:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-strong: #eef3f7;
  --text: #18212b;
  --muted: #5f6f82;
  --line: #d5dde7;
  --line-strong: #c3ceda;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --action: #255c99;
  --action-strong: #1f4e82;
  --focus: #2563eb;
  --shadow: 0 10px 30px rgba(22, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 14px;
}

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.app-header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.auth-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  max-width: 420px;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-strong);
  color: #2c4057;
  font-size: 12px;
  font-weight: 700;
}

.auth-status[data-state="valid"] {
  border-color: #9cc8bd;
  background: #e7f5f1;
  color: #0f5d50;
}

.auth-status[data-state="warning"] {
  border-color: #e3c779;
  background: #fff7db;
  color: #775b12;
}

.auth-status[data-state="invalid"] {
  border-color: #e6aaaa;
  background: #fff0f0;
  color: #8a2f2f;
}

main {
  min-height: calc(100vh - 76px);
}

.directory-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

.directory-shell.contact-panel-open {
  grid-template-columns: minmax(0, 1fr) 390px;
}

.search-pane {
  min-width: 0;
  padding: 20px 24px 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 360px) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-box,
.filter-control {
  display: grid;
  gap: 5px;
  color: #43566c;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 0 10px;
}

input:focus,
select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.secondary-button,
.contact-close {
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-strong);
  color: #2c4057;
  font: inherit;
  font-weight: 700;
  padding: 0 14px;
  cursor: pointer;
}

.secondary-button:hover,
.contact-close:hover {
  background: #e4ebf2;
}

.secondary-button:disabled {
  color: #93a1b1;
  cursor: default;
  background: #eef2f5;
}

.field-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.field-settings[hidden] {
  display: none;
}

.field-settings h2 {
  margin: 0 0 10px;
  color: #344a61;
  font-size: 13px;
  text-transform: uppercase;
}

.field-option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px 12px;
}

.field-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: #2c4057;
}

.field-option input {
  width: 16px;
  height: 16px;
}

.results-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.results-table th,
.results-table td {
  height: 46px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-table th {
  position: sticky;
  top: 0;
  background: var(--surface-strong);
  color: #40546a;
  font-size: 12px;
  text-transform: uppercase;
  user-select: none;
}

.results-table th[data-sortable="true"] {
  cursor: pointer;
}

.results-table tr {
  cursor: pointer;
}

.results-table tbody tr:hover {
  background: #eef7f6;
}

.results-table tbody tr.selected {
  background: #e1f2f0;
  box-shadow: inset 3px 0 0 var(--accent);
}

.unauthorized-state {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: calc(100vh - 160px);
  padding: 32px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.unauthorized-state[hidden] {
  display: none;
}

.unauthorized-state h2 {
  margin: 0 0 8px;
  color: #8a2f2f;
  font-size: 24px;
}

.unauthorized-state p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.contact-panel {
  display: none;
  border-left: 1px solid var(--line);
  background: var(--surface);
  padding: 22px;
  overflow: auto;
  box-shadow: -10px 0 26px rgba(22, 34, 51, 0.06);
}

.contact-panel-open .contact-panel {
  display: block;
}

.empty-panel {
  color: var(--muted);
}

.contact-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.contact-card h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.contact-card header p {
  margin: 6px 0 0;
  color: var(--muted);
}

dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px 12px;
  margin: 16px 0 0;
}

dt {
  color: #4a5f76;
  font-weight: 700;
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.contact-field-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.contact-inline-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--action);
  text-decoration: none;
  vertical-align: middle;
}

.contact-inline-action:hover {
  background: #e3edf7;
  border-color: var(--line-strong);
  color: var(--action-strong);
}

.contact-inline-action svg {
  display: block;
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.temporary-protocol-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.temporary-protocol-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  height: 34px;
  border-radius: 4px;
  background: var(--action);
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
}

.temporary-protocol-actions a:hover {
  background: var(--action-strong);
}

@media (max-width: 860px) {
  .directory-shell {
    grid-template-columns: 1fr;
  }

  .directory-shell.contact-panel-open {
    grid-template-columns: 1fr;
  }

  .contact-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    width: 100%;
  }

  .secondary-button {
    width: 100%;
  }

  .field-settings {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 18px;
  }

  .auth-status {
    max-width: 100%;
  }
}
