@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* Surfaces — warm off-white palette */
  --bg:               #fff8f1;
  --surface-white:    #ffffff;
  --surface-low:      #fbf3e4;
  --surface:          #f5eddf;
  --surface-high:     #f0e7d9;
  --surface-highest:  #eae1d4;

  /* Shell */
  --shell:            #25273A;   /* Savills Navy */
  --shell-text:       #ffffff;

  /* Brand accent */
  --yellow:           #FFDF00;   /* Savills Yellow */
  --yellow-dark:      #d4b800;   /* hover */
  --on-yellow:        #1f1b13;   /* text on yellow — always black per brand */

  /* Text */
  --text:             #1f1b13;
  --text-muted:       #4d4635;
  --text-subtle:      #7f7663;

  /* Borders */
  --border:           #d0c5af;
  --border-subtle:    #e8dfd0;

  /* Status */
  --danger:           #ba1a1a;
  --danger-bg:        #ffdad6;
  --success:          #3aa95c;

  /* Radius */
  --r:     4px;
  --r-lg:  8px;

  /* Typography */
  --font:      'Hanken Grotesk', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', Menlo, monospace;

  /* Layout */
  --header-h:    64px;
  --panel-w:     440px;
  --container:   1280px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Header ──────────────────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 300;
  height: var(--header-h);
  background: var(--shell);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
}

.savills-logo-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 16px;
}

.header-brand-sep {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,.2);
  margin-right: 16px;
}

.header-product {
  font-size: 15px;
  font-weight: 600;
  color: var(--shell-text);
  letter-spacing: -.01em;
  white-space: nowrap;
}

.header-nav-sep {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,.15);
  margin: 0 20px;
}

/* Header nav */
.header-nav {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-decoration: none;
  color: rgba(255,255,255,.55);
  border-bottom: 3px solid transparent;
  transition: color .15s;
}
.nav-item:hover { color: rgba(255,255,255,.85); }
.nav-item--active {
  color: var(--yellow);
  border-bottom-color: var(--yellow);
}

/* User block */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-highest);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.80);
  white-space: nowrap;
}

.btn-signout {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.75);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  padding: 6px 14px;
  cursor: pointer;
  border-radius: var(--r);
  transition: border-color .15s, color .15s, background .15s;
}
.btn-signout:hover { border-color: rgba(255,255,255,.45); color: var(--shell-text); background: rgba(255,255,255,.06); }

/* ── Full-screen states ───────────────────────────────────────────────────── */

.state-fullscreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: calc(100vh - var(--header-h));
  color: var(--text-subtle);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--shell);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.unauth-card {
  background: var(--surface-white);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 40px 48px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 12px rgba(31,27,19,.08);
}
.unauth-card h2 { font-size: 18px; font-weight: 600; margin-bottom: 10px; }
.unauth-card p  { font-size: 14px; color: var(--text-muted); line-height: 1.65; margin-bottom: 28px; }

/* ── Admin shell ─────────────────────────────────────────────────────────── */

.admin-shell {
  display: flex;
  height: calc(100vh - var(--header-h));
  position: relative;
}

.main-scroll {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: padding-right .25s ease;
}

.main-scroll.panel-open {
  padding-right: var(--panel-w);
}

.content-wrapper {
  flex: 1;
  max-width: var(--container);
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 24px;
}

/* ── Page header ─────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 6px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--yellow);
  color: var(--on-yellow);
  border: none;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
  letter-spacing: .02em;
  cursor: pointer;
  border-radius: var(--r);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-primary:hover { background: var(--yellow-dark); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  border-radius: var(--r);
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--surface-low); border-color: var(--border); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(186,26,26,.25);
  padding: 8px 16px;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  border-radius: var(--r);
  transition: background .15s, border-color .15s;
}
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

/* ── Stats ───────────────────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface-low);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 20px 24px;
  min-width: 160px;
}

.stat-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-subtle);
  margin-bottom: 10px;
}

.stat-value {
  display: block;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ── Table section ───────────────────────────────────────────────────────── */

.table-section {
  background: var(--surface-white);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* Search bar */
.search-bar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-low);
}

.search-input-wrap {
  position: relative;
  max-width: 360px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.search-input-wrap input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 36px;
  background: var(--surface-white);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.search-input-wrap input:focus {
  border-color: var(--shell);
  box-shadow: 0 0 0 3px rgba(37,39,58,.06);
}
.search-input-wrap input::placeholder { color: var(--text-subtle); }

/* Table */
.table-wrap { overflow-x: auto; }

.table-loading { padding: 24px; color: var(--text-subtle); font-size: 14px; }
.empty-state   { padding: 48px 24px; text-align: center; color: var(--text-subtle); font-size: 15px; }

.orgs-table {
  width: 100%;
  border-collapse: collapse;
}

.orgs-table th {
  padding: 0 16px;
  height: 40px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.th-actions { text-align: right; }

.orgs-table td {
  padding: 0 16px;
  height: 56px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.orgs-table tr:last-child td { border-bottom: none; }
.orgs-table tbody tr { transition: background .1s; }
.orgs-table tbody tr:hover td { background: var(--surface-low); }
.orgs-table tbody tr.selected td { background: #fffbe6; }
.orgs-table tbody tr.selected td:first-child {
  border-left: 3px solid var(--yellow);
  padding-left: 13px;
}

/* Code pill for IDs */
.id-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r);
  padding: 2px 7px;
  color: var(--text-muted);
}

.report-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 9999px;
  padding: 2px 10px;
  color: var(--text-muted);
}

/* Action buttons */
.td-actions { text-align: right; white-space: nowrap; }

.btn-row-edit {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--r);
  margin-right: 6px;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-row-edit:hover { background: var(--surface-low); border-color: var(--border); color: var(--text); }

.btn-row-delete {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(186,26,26,.25);
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--r);
  transition: background .15s, border-color .15s;
}
.btn-row-delete:hover { background: var(--danger-bg); border-color: var(--danger); }

/* ── Edit panel (fixed right) ────────────────────────────────────────────── */

.edit-panel {
  position: fixed;
  right: 0;
  top: var(--header-h);
  bottom: 0;
  width: var(--panel-w);
  background: var(--surface-white);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(100%);
  transition: transform .25s ease;
  box-shadow: -4px 0 24px rgba(31,27,19,.08);
}

.edit-panel.visible { transform: translateX(0); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--surface-low);
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}

.panel-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-subtle);
  cursor: pointer;
  border-radius: var(--r);
  transition: background .15s, color .15s;
}
.panel-close:hover { background: var(--surface-high); color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--surface-low);
}

.panel-footer-right { display: flex; gap: 8px; }

/* ── Form fields ─────────────────────────────────────────────────────────── */

.field { margin-bottom: 20px; }

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: border-color .15s, background .15s;
}
.field input[type="text"]:focus,
.field textarea:focus {
  border-color: var(--shell);
  background: var(--surface-white);
  box-shadow: 0 0 0 3px rgba(37,39,58,.06);
}
.field textarea { resize: vertical; }

.field-hint {
  font-size: 11px;
  color: var(--text-subtle);
  margin-top: 5px;
  line-height: 1.5;
}

.required { color: var(--danger); }

.form-error {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-bg);
  border-left: 3px solid var(--danger);
  padding: 8px 12px;
  border-radius: 0 var(--r) var(--r) 0;
  margin-top: 4px;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: auto;
}

.footer-status {
  display: flex;
  align-items: center;
  gap: 7px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}
