:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-muted: #eef3f4;
  --surface-strong: #e4ecee;
  --text: #14282b;
  --text-soft: #607275;
  --text-faint: #8b9a9c;
  --line: #d9e3e5;
  --accent: #0b8f85;
  --accent-strong: #08756d;
  --accent-soft: #d9f1ed;
  --navy: #173f4a;
  --success: #16845b;
  --success-soft: #dff3e9;
  --warning: #a66c13;
  --warning-soft: #fff0d1;
  --danger: #bd4a4a;
  --danger-soft: #fbe3e3;
  --shadow: 0 18px 50px rgba(35, 61, 67, .08);
  --radius: 10px;
  --sidebar: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101b1e;
  --surface: #172528;
  --surface-muted: #1d3033;
  --surface-strong: #244044;
  --text: #e8f1f0;
  --text-soft: #a8bcbd;
  --text-faint: #789093;
  --line: #2b4549;
  --accent: #4bc4b6;
  --accent-strong: #70d5c8;
  --accent-soft: #1f4b49;
  --navy: #c7e8e6;
  --success: #63d39f;
  --success-soft: #1f4839;
  --warning: #e2ad5b;
  --warning-soft: #4e3d21;
  --danger: #ef8585;
  --danger-soft: #512e32;
  --shadow: 0 22px 60px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: var(--accent-strong); }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.eyebrow { color: var(--text-faint); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

/* Auth */
.login-page { display: grid; min-height: 100vh; grid-template-columns: minmax(0, 1.08fr) minmax(380px, .92fr); background: var(--surface); }
.login-visual { position: relative; display: flex; align-items: flex-end; min-height: 100vh; overflow: hidden; padding: clamp(36px, 8vw, 120px); color: #e8f6f4; background: #164c55; }
.login-visual::before { position: absolute; inset: 12% -12% -20% 18%; border: 1px solid rgba(230, 255, 250, .18); border-radius: 50%; content: ""; transform: rotate(-18deg); }
.login-visual::after { position: absolute; right: -16%; top: -18%; width: 64%; height: 80%; border: 1px solid rgba(230, 255, 250, .13); border-radius: 48%; content: ""; transform: rotate(28deg); }
.visual-grid { position: absolute; inset: 0; opacity: .2; background-image: linear-gradient(rgba(215, 251, 246, .18) 1px, transparent 1px), linear-gradient(90deg, rgba(215, 251, 246, .18) 1px, transparent 1px); background-size: 38px 38px; mask-image: linear-gradient(to bottom, transparent, #000 30%, #000 80%, transparent); }
.visual-copy { position: relative; max-width: 520px; }
.visual-copy .eyebrow { color: #8cdbd1; }
.visual-copy h1 { margin: 18px 0; font-size: clamp(36px, 5vw, 70px); line-height: 1.04; letter-spacing: -.02em; font-weight: 700; }
.visual-copy p { max-width: 360px; margin: 0; color: #b5d9d5; font-size: 16px; }
.auth-panel { width: min(100%, 520px); align-self: center; justify-self: center; padding: 52px clamp(30px, 7vw, 86px); }
.brand-lockup { display: flex; align-items: center; gap: 12px; color: var(--navy); }
.brand-lockup strong { display: block; font-size: 18px; line-height: 1.1; }
.brand-lockup span:not(.brand-mark) { display: block; color: var(--text-faint); font-size: 11px; letter-spacing: .04em; }
.brand-mark { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 9px; color: #fff; background: var(--accent); font-size: 18px; font-weight: 800; }
.auth-heading { margin: 68px 0 28px; }
.auth-heading h2 { margin: 8px 0 6px; color: var(--text); font-size: 32px; letter-spacing: -.02em; }
.auth-heading p { margin: 0; color: var(--text-soft); }
.auth-tabs { display: flex; gap: 24px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.auth-tab { position: relative; padding: 0 0 12px; border: 0; color: var(--text-faint); background: none; font-weight: 700; }
.auth-tab.is-active { color: var(--accent-strong); }
.auth-tab.is-active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; border-radius: 2px; background: var(--accent); content: ""; }
.auth-form { display: grid; gap: 15px; }
.auth-form label, .form-grid label { display: grid; gap: 7px; color: var(--text-soft); font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; outline: none; color: var(--text); background: var(--surface); transition: border-color .16s, box-shadow .16s; }
input, select { min-height: 42px; padding: 0 12px; }
textarea { min-height: 100px; padding: 10px 12px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.primary-button, .secondary-button, .danger-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; padding: 0 15px; border: 1px solid transparent; border-radius: 7px; font-weight: 700; transition: transform .15s, background .15s, border-color .15s; }
.primary-button { color: #fff; background: var(--accent); }
.primary-button:hover { background: var(--accent-strong); transform: translateY(-1px); }
.secondary-button { border-color: var(--line); color: var(--text); background: var(--surface); }
.secondary-button:hover { border-color: var(--accent); color: var(--accent-strong); }
.danger-button { border-color: transparent; color: var(--danger); background: var(--danger-soft); }
.wide { width: 100%; min-height: 46px; margin-top: 7px; }
.form-message { margin-top: 14px; padding: 10px 12px; border-radius: 7px; color: var(--danger); background: var(--danger-soft); font-size: 13px; }
.auth-footer { display: flex; align-items: center; gap: 7px; margin-top: 72px; color: var(--text-faint); font-size: 12px; }
.auth-footer span:last-child { margin-left: auto; color: var(--text-soft); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.status-dot.is-online { background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 14%, transparent); }
.status-dot.is-warning { background: var(--warning); }

/* App shell */
.app-page { display: flex; min-height: 100vh; }
.sidebar { position: fixed; z-index: 20; display: flex; width: var(--sidebar); height: 100vh; flex-direction: column; padding: 24px 16px 18px; border-right: 1px solid var(--line); background: var(--surface); }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 28px; }
.brand-lockup.compact { gap: 9px; }
.brand-lockup.compact .brand-mark { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }
.brand-lockup.compact strong { font-size: 15px; }
.brand-lockup.compact span:not(.brand-mark) { font-size: 9px; }
.workspace-chip { display: flex; align-items: center; gap: 9px; min-height: 52px; margin: 0 2px 25px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-muted); }
.workspace-avatar, .user-avatar { display: grid; flex: 0 0 auto; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: #fff; background: var(--navy); font-size: 12px; font-weight: 800; }
.workspace-meta { min-width: 0; flex: 1; }
.workspace-meta strong, .workspace-meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-meta strong { color: var(--text); font-size: 12px; }
.workspace-meta small { color: var(--text-faint); font-size: 10px; }
.workspace-caret { color: var(--text-faint); font-size: 17px; }
.primary-nav, .sidebar-bottom { display: grid; gap: 4px; }
.sidebar-bottom { margin-top: auto; gap: 14px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 40px; padding: 0 11px; border: 0; border-radius: 7px; color: var(--text-soft); background: transparent; text-align: left; font-weight: 600; }
.nav-item:hover { color: var(--text); background: var(--surface-muted); }
.nav-item.is-active { color: var(--accent-strong); background: var(--accent-soft); }
.nav-icon { display: grid; width: 18px; place-items: center; color: currentColor; font-size: 16px; }
.nav-badge { min-width: 20px; margin-left: auto; padding: 1px 6px; border-radius: 10px; color: #fff; background: var(--danger); font-size: 10px; text-align: center; }
.sidebar-caption { padding: 0 11px; color: var(--text-faint); font-size: 10px; }
.main-content { width: calc(100% - var(--sidebar)); min-width: 0; margin-left: var(--sidebar); }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 88px; padding: 18px clamp(22px, 4vw, 56px); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 90%, transparent); }
.topbar-leading { display: flex; align-items: center; gap: 15px; }
.topbar h1 { margin: 3px 0 0; color: var(--text); font-size: 25px; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.icon-button { display: inline-grid; width: 38px; height: 38px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 7px; color: var(--text-soft); background: var(--surface); font-size: 17px; }
.icon-button:hover { color: var(--accent-strong); border-color: var(--accent); }
.mobile-menu, .mobile-close { display: none; }
.health-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 16px; color: var(--text-soft); background: var(--surface); font-size: 11px; white-space: nowrap; }
.health-pill.is-online .status-dot { background: var(--success); }
.health-pill.is-warning .status-dot { background: var(--warning); }
.tenant-picker { width: 168px; }
.tenant-picker select { min-height: 36px; padding-right: 8px; border-radius: 7px; font-size: 12px; }
.user-menu { position: relative; }
.user-trigger { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 3px 0 7px; border: 0; color: var(--text); background: transparent; font-weight: 700; }
.user-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-dropdown { position: absolute; z-index: 30; right: 0; top: calc(100% + 8px); width: 150px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); background: var(--surface); }
.user-dropdown button { display: block; width: 100%; padding: 9px 10px; border: 0; border-radius: 5px; color: var(--text-soft); background: transparent; text-align: left; }
.user-dropdown button:hover { color: var(--text); background: var(--surface-muted); }
.view-root { max-width: 1440px; margin: 0 auto; padding: 30px clamp(22px, 4vw, 56px) 60px; }

/* Shared view components */
.view-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.view-heading h2 { margin: 4px 0 0; color: var(--text); font-size: 24px; letter-spacing: -.02em; }
.view-heading p { margin: 5px 0 0; color: var(--text-soft); }
.heading-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.metric-card, .panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric-card { min-height: 132px; padding: 18px; }
.metric-label { display: flex; align-items: center; justify-content: space-between; color: var(--text-soft); font-size: 12px; font-weight: 700; }
.metric-kicker { color: var(--text-faint); font-size: 10px; font-weight: 600; }
.metric-value { margin-top: 18px; color: var(--text); font-size: 27px; font-weight: 750; letter-spacing: -.03em; }
.metric-foot { margin-top: 6px; color: var(--text-faint); font-size: 11px; }
.metric-value.is-green { color: var(--success); }
.metric-value.is-amber { color: var(--warning); }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 16px; }
.panel { min-width: 0; padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-header h3 { margin: 0; color: var(--text); font-size: 15px; }
.panel-header p { margin: 4px 0 0; color: var(--text-faint); font-size: 11px; }
.panel-header .secondary-button { min-height: 32px; padding: 0 10px; font-size: 11px; }
.list { display: grid; gap: 9px; }
.list-row { display: flex; align-items: flex-start; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-mark { display: grid; flex: 0 0 auto; width: 30px; height: 30px; place-items: center; border-radius: 7px; color: var(--accent-strong); background: var(--accent-soft); font-size: 14px; font-weight: 800; }
.list-main { min-width: 0; flex: 1; }
.list-main strong, .list-main span { display: block; overflow: hidden; text-overflow: ellipsis; }
.list-main strong { color: var(--text); font-size: 12px; white-space: nowrap; }
.list-main span { margin-top: 2px; color: var(--text-soft); font-size: 11px; }
.list-time { flex: 0 0 auto; color: var(--text-faint); font-size: 10px; }
.empty-state { display: grid; min-height: 130px; place-items: center; padding: 20px; color: var(--text-faint); text-align: center; }
.empty-state strong { display: block; margin-bottom: 4px; color: var(--text-soft); }
.health-banner { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-muted); }
.health-banner .status-dot { width: 10px; height: 10px; }
.health-banner strong { display: block; color: var(--text); font-size: 13px; }
.health-banner span { display: block; color: var(--text-soft); font-size: 11px; }
.health-banner .secondary-button { margin-left: auto; min-height: 32px; padding: 0 10px; font-size: 11px; }
.progress-track { height: 8px; overflow: hidden; border-radius: 10px; background: var(--surface-strong); }
.progress-bar { height: 100%; border-radius: inherit; background: var(--accent); }
.progress-bar.is-warning { background: var(--warning); }
.progress-bar.is-danger { background: var(--danger); }
.usage-block { display: grid; gap: 9px; }
.usage-line { display: flex; justify-content: space-between; color: var(--text-soft); font-size: 12px; }
.usage-line strong { color: var(--text); }
.pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 12px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.pill.success { color: var(--success); background: var(--success-soft); }
.pill.warning { color: var(--warning); background: var(--warning-soft); }
.pill.danger { color: var(--danger); background: var(--danger-soft); }
.pill.neutral { color: var(--text-soft); background: var(--surface-muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--text-faint); background: var(--surface-muted); font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
td { color: var(--text-soft); font-size: 12px; }
td strong { color: var(--text); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
.form-panel { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.section-tabs { display: flex; gap: 5px; margin-bottom: 16px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-muted); }
.section-tab { flex: 1; min-height: 34px; border: 0; border-radius: 5px; color: var(--text-soft); background: transparent; font-size: 12px; font-weight: 700; }
.section-tab.is-active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(22, 50, 55, .08); }
details { border: 1px solid var(--line); border-radius: 8px; }
details summary { padding: 12px 14px; color: var(--text); cursor: pointer; font-weight: 700; }
details .details-body { padding: 0 14px 14px; }
.permission-note { padding: 11px 13px; border-radius: 7px; color: var(--text-soft); background: var(--surface-muted); font-size: 12px; }
.code-value { display: inline-block; max-width: 240px; overflow: hidden; color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; vertical-align: bottom; white-space: nowrap; }

/* Toast and loading */
.toast-region { position: fixed; z-index: 100; right: 24px; bottom: 24px; display: grid; gap: 8px; width: min(360px, calc(100vw - 48px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); color: var(--text); background: var(--surface); font-size: 12px; animation: toast-in .2s ease-out; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.loading-line { height: 11px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-muted), var(--surface-strong), var(--surface-muted)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
  .topbar-actions .user-name { display: none; }
}
@media (max-width: 780px) {
  .login-page { display: block; }
  .login-visual { display: none; }
  .auth-panel { min-height: 100vh; padding: 34px 24px; }
  .auth-heading { margin-top: 72px; }
  .auth-footer { margin-top: 60px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; z-index: 15; inset: 0; background: rgba(11, 28, 31, .42); }
  .mobile-menu, .mobile-close { display: inline-grid; }
  .main-content { width: 100%; margin-left: 0; }
  .topbar { min-height: 76px; padding: 14px 18px; }
  .topbar h1 { font-size: 20px; }
  .topbar-actions { gap: 6px; }
  .health-pill { display: none; }
  .tenant-picker { width: 128px; }
  .view-root { padding: 22px 18px 42px; }
  .view-heading { display: block; }
  .heading-actions { margin-top: 14px; }
  .metric-grid { gap: 8px; }
  .metric-card { min-height: 112px; padding: 14px; }
  .metric-value { margin-top: 12px; font-size: 22px; }
  .panel { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
}
@media (max-width: 480px) {
  .topbar-leading { gap: 9px; }
  .tenant-picker { width: 106px; }
  .tenant-picker select { font-size: 10px; }
  .topbar-actions .icon-button { width: 34px; height: 34px; }
  .user-trigger { padding: 0; }
  .user-trigger > span:last-child { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-label { font-size: 10px; }
  .metric-value { font-size: 19px; }
  .metric-foot { font-size: 9px; }
}
