:root {
  --ink: #142029;
  --muted: #62727e;
  --line: #d8e0e3;
  --soft-line: #e9eef0;
  --canvas: #f4f7f7;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --sidebar: #10282c;
  --sidebar-muted: #a9c0bf;
  --brand: #0c6b68;
  --brand-dark: #07514f;
  --brand-soft: #e3f3f1;
  --accent: #e0a02a;
  --danger: #b83835;
  --danger-soft: #fcebea;
  --success: #1c7a50;
  --success-soft: #e8f5ed;
  --warning: #9a6413;
  --warning-soft: #fff4df;
  --shadow: 0 12px 28px rgba(27, 49, 54, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

html, body, #app { min-height: 100%; margin: 0; }

body { min-width: 320px; background: var(--canvas); }

button, input, select, textarea { font: inherit; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: 0.55; }

a { color: inherit; text-decoration: none; }

svg { width: 18px; height: 18px; stroke-width: 1.9; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--canvas);
}

.auth-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  width: min(100%, 430px);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-form { width: 100%; }

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 40px; height: 40px; flex: none; object-fit: contain; }
.brand-lockup-login { justify-content: center; }
.brand-logo-wordmark { width: min(100%, 205px); height: auto; max-height: 96px; object-fit: contain; }

.brand-copy { min-width: 0; }
.brand-copy strong { display: block; line-height: 1.15; font-size: 15px; }
.brand-copy span { color: var(--muted); font-size: 12px; }

.auth-heading { margin: 28px 0 8px; font-size: 25px; line-height: 1.2; font-weight: 750; text-align: center; }
.auth-lede { margin: 0 0 28px; color: var(--muted); line-height: 1.55; font-size: 13px; text-align: center; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 23px 15px 16px;
  background: var(--sidebar);
  color: white;
}

.sidebar .brand-lockup { padding: 0 8px 25px; }
.sidebar .brand-copy span { color: var(--sidebar-muted); }

.nav-label { padding: 16px 10px 8px; color: #89a5a5; font-size: 10px; font-weight: 750; letter-spacing: 0.09em; text-transform: uppercase; }
.nav-list { display: grid; gap: 3px; }

.nav-link {
  min-height: 39px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #c1d1d0;
  text-align: left;
  font-size: 13px;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.07); color: white; }
.nav-link.active { background: #1c4648; color: white; font-weight: 650; }
.nav-link i { display: grid; place-items: center; color: #8cb5b2; }
.nav-link.active i { color: #f3bf56; }

.sidebar-footer { margin-top: auto; padding-top: 18px; }
.account-mini { padding: 12px 10px; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.account-mini strong, .account-mini span { overflow: hidden; display: block; text-overflow: ellipsis; white-space: nowrap; }
.account-mini strong { font-size: 12px; }
.account-mini span { margin-top: 3px; color: var(--sidebar-muted); font-size: 11px; }
.signout { width: 100%; margin-top: 8px; color: #d8e8e6; }

.main-shell { min-width: 0; }

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.93);
}

.topbar-title { min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 18px; line-height: 1.35; font-weight: 720; }
.topbar-title p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.mobile-menu { display: none; }

.page { padding: 27px 30px 42px; }
.page > * + * { margin-top: 20px; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading h2 { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 730; }
.page-heading p { max-width: 690px; margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.page-heading-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { min-height: 112px; padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 3px rgba(27,49,54,0.02); }
.stat-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
.stat-card-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 6px; background: var(--brand-soft); color: var(--brand-dark); }
.stat-card.accent .stat-card-icon { background: #fff0d4; color: #a96c09; }
.stat-card.danger .stat-card-icon { background: var(--danger-soft); color: var(--danger); }
.stat-card .value { margin-top: 17px; font-size: 26px; line-height: 1; font-weight: 760; font-variant-numeric: tabular-nums; }
.stat-card .detail { margin-top: 7px; color: var(--muted); font-size: 11px; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.75fr); gap: 20px; align-items: start; }

.section { min-width: 0; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 11px; }
.section-heading h3 { margin: 0; font-size: 15px; line-height: 1.4; font-weight: 720; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 3px rgba(27,49,54,0.02); }
.panel > .panel-header { min-height: 57px; padding: 13px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--soft-line); }
.panel-header-title { min-width: 0; }
.panel-header-title h3 { margin: 0; font-size: 14px; font-weight: 720; }
.panel-header-title p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.panel-body { padding: 17px; }
.panel-body.flush { padding: 0; }

.info-list { margin: 0; display: grid; }
.info-row { display: flex; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--soft-line); }
.info-row:last-child { border-bottom: 0; }
.info-row dt { color: var(--muted); font-size: 12px; }
.info-row dd { max-width: 60%; margin: 0; overflow: hidden; font-size: 12px; font-weight: 650; text-align: right; text-overflow: ellipsis; white-space: nowrap; }

.notice { display: flex; align-items: flex-start; gap: 10px; padding: 13px 14px; border: 1px solid #efd9a7; border-radius: 7px; background: #fffaee; color: #765413; font-size: 12px; line-height: 1.5; }
.notice i { flex: none; margin-top: 1px; }
.notice.danger { border-color: #edc4c2; background: var(--danger-soft); color: #84312e; }
.notice.info { border-color: #bcdedc; background: #eff9f8; color: #165d5a; }

.quick-actions { display: grid; gap: 7px; }
.quick-action { width: 100%; min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); text-align: left; }
.quick-action:hover { border-color: #aabfc0; background: var(--surface-muted); }
.quick-action-main { display: flex; align-items: center; gap: 11px; min-width: 0; }
.quick-action-main i { color: var(--brand); }
.quick-action strong, .quick-action span { display: block; }
.quick-action strong { font-size: 12px; }
.quick-action span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.quick-action > i { color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 11px; padding: 14px 16px; border-bottom: 1px solid var(--soft-line); background: var(--surface-muted); }
.filter-field { display: grid; gap: 5px; min-width: 138px; }
.filter-field.grow { flex: 1 1 220px; }
.filter-field label, .field label { color: #4b5c66; font-size: 11px; font-weight: 700; }

.field { display: grid; gap: 6px; min-width: 0; }
.field + .field { margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .span-2 { grid-column: span 2; }

input, select, textarea {
  width: 100%;
  min-height: 37px;
  padding: 8px 10px;
  border: 1px solid #b9c8cd;
  border-radius: 5px;
  outline: none;
  background: white;
  color: var(--ink);
  font-size: 13px;
}

textarea { min-height: 98px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(12,107,104,0.12); }
input::placeholder, textarea::placeholder { color: #91a0a8; }

.input-wrap { position: relative; }
.input-wrap i { position: absolute; top: 50%; left: 10px; width: 16px; height: 16px; transform: translateY(-50%); color: #7b8a93; pointer-events: none; }
.input-wrap input { padding-left: 34px; }

.checkbox-field { min-height: 37px; display: flex; align-items: center; gap: 8px; padding: 6px 1px; color: #3d505b; font-size: 12px; }
.checkbox-field input { width: 15px; min-height: 15px; margin: 0; accent-color: var(--brand); }

.btn { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 11px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--ink); font-size: 12px; font-weight: 680; line-height: 1; white-space: nowrap; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { border-color: var(--brand); background: var(--brand); color: white; }
.btn-primary:hover:not(:disabled) { border-color: var(--brand-dark); background: var(--brand-dark); }
.btn-secondary { border-color: #b8c6ca; background: white; }
.btn-secondary:hover:not(:disabled) { border-color: #8da5ab; background: var(--surface-muted); }
.btn-quiet { color: var(--brand-dark); }
.btn-quiet:hover:not(:disabled) { background: var(--brand-soft); }
.btn-danger { border-color: var(--danger); background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #962d2a; border-color: #962d2a; }
.btn-danger-outline { border-color: #ddb0ad; color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { min-height: 30px; padding: 6px 8px; font-size: 11px; }
.icon-btn { width: 34px; min-width: 34px; padding: 7px; }
.icon-btn.btn-sm { width: 30px; min-width: 30px; padding: 5px; }

.table-shell { width: 100%; overflow-x: auto; }
.data-table { width: 100%; min-width: 760px; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 15px; border-bottom: 1px solid var(--soft-line); text-align: left; vertical-align: middle; }
.data-table th { background: #fbfcfc; color: #64757f; font-size: 10px; font-weight: 750; letter-spacing: 0.055em; text-transform: uppercase; white-space: nowrap; }
.data-table td { color: #273942; font-size: 12px; }
.data-table tbody tr:hover { background: #fbfdfd; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .cell-primary { max-width: 300px; overflow: hidden; color: var(--ink); font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.data-table .cell-subtle { color: var(--muted); font-size: 11px; }
.data-table .cell-actions { width: 1%; text-align: right; white-space: nowrap; }
.table-actions { display: inline-flex; align-items: center; gap: 3px; }

.empty-state { min-height: 220px; display: grid; place-items: center; padding: 30px; text-align: center; }
.empty-state > div { max-width: 380px; }
.empty-state .empty-icon { width: 42px; height: 42px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 7px; background: var(--brand-soft); color: var(--brand); }
.empty-state h3 { margin: 0; font-size: 14px; }
.empty-state p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.loading-state { min-height: 180px; display: grid; place-items: center; padding: 28px; color: var(--muted); font-size: 13px; }
.loading-inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.spinner { width: 16px; height: 16px; flex: none; border: 2px solid #c7d6d7; border-top-color: var(--brand); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pagination { min-height: 58px; padding: 12px 15px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--soft-line); }
.pagination-summary { color: var(--muted); font-size: 11px; }
.pagination-controls { display: flex; align-items: center; gap: 6px; }
.pagination-page { min-width: 33px; height: 30px; padding: 0 7px; border: 1px solid #bfccd0; border-radius: 5px; background: white; color: #40525b; font-size: 11px; font-weight: 650; }
.pagination-page.active { border-color: var(--brand); background: var(--brand); color: white; }

.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 20px; padding: 3px 7px; border-radius: 999px; background: #edf1f2; color: #48606b; font-size: 10px; font-weight: 750; line-height: 1; white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.brand { background: var(--brand-soft); color: var(--brand-dark); }
.badge.neutral { background: #eef1f2; color: #4e5e66; }

.owner-cell { display: grid; gap: 3px; max-width: 250px; }
.owner-cell .owner-id { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.split-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 0.65fr); gap: 20px; align-items: start; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px; border-bottom: 1px solid var(--soft-line); }
.detail-header h3 { margin: 0; font-size: 17px; line-height: 1.35; }
.detail-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.detail-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.roster-section + .roster-section { border-top: 1px solid var(--soft-line); }
.roster-section h4 { margin: 0; padding: 13px 16px; font-size: 12px; }
.roster-list { margin: 0; padding: 0; list-style: none; }
.roster-list li { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 16px; border-top: 1px solid var(--soft-line); }
.roster-person { min-width: 0; }
.roster-person strong, .roster-person span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-person strong { font-size: 12px; }
.roster-person span { margin-top: 2px; color: var(--muted); font-size: 10px; }

.json-output { max-height: 470px; overflow: auto; margin: 0; padding: 15px; background: #15272b; color: #d7e8e6; font: 11px/1.6 "SFMono-Regular", Consolas, "Liberation Mono", monospace; white-space: pre-wrap; }
.diagnostic-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.diagnostic-stat { padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-muted); }
.diagnostic-stat strong, .diagnostic-stat span { display: block; }
.diagnostic-stat strong { font-size: 20px; }
.diagnostic-stat span { margin-top: 4px; color: var(--muted); font-size: 11px; }

.modal-layer { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; background: rgba(15, 29, 33, 0.55); }
.modal { width: min(100%, 570px); max-height: min(720px, calc(100vh - 40px)); display: flex; flex-direction: column; border: 1px solid #cad5d8; border-radius: 8px; background: var(--surface); box-shadow: 0 24px 60px rgba(7, 25, 29, 0.28); }
.modal.wide { width: min(100%, 760px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 17px 18px; border-bottom: 1px solid var(--soft-line); }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.modal-content { overflow-y: auto; padding: 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--soft-line); background: #fbfcfc; }

.toast-stack { position: fixed; z-index: 80; top: 18px; right: 18px; width: min(360px, calc(100vw - 36px)); display: grid; gap: 9px; }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid #bbd7cd; border-radius: 7px; background: white; box-shadow: var(--shadow); color: #245d43; font-size: 12px; line-height: 1.45; }
.toast.error { border-color: #e1b6b3; color: #87312e; }
.toast.info { border-color: #b8d9d7; color: #125d5b; }
.toast i { flex: none; margin-top: 1px; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

@media (max-width: 1120px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-grid, .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 252px; transform: translateX(-102%); transition: transform .18s ease; box-shadow: 14px 0 35px rgba(9,26,29,0.24); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-flex; }
  .topbar { min-height: 63px; padding: 0 16px; }
  .page { padding: 22px 16px 35px; }
  .page-heading { display: block; }
  .page-heading-actions { justify-content: flex-start; margin-top: 15px; }
  .topbar-title p { display: none; }
  .diagnostic-summary { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .auth-panel { padding: 30px 22px; }
  .auth-heading { margin-top: 42px; }
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .filters { align-items: stretch; }
  .filter-field { flex: 1 1 100%; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .pagination-controls { width: 100%; justify-content: flex-end; }
  .detail-header { display: block; }
  .detail-actions { justify-content: flex-start; margin-top: 14px; }
}
