:root {
  color-scheme: light dark;
  --canvas: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --border: #d9dde5;
  --border-strong: #b9c0cc;
  --text: #1b2230;
  --text-secondary: #5f6877;
  --text-tertiary: #7d8695;
  --accent: #2356d8;
  --accent-hover: #1d46af;
  --accent-soft: #edf2ff;
  --success: #14745a;
  --danger: #b42318;
  --danger-soft: #fff1ef;
  --focus: rgba(35, 86, 216, 0.18);
  --shadow-dialog: 0 18px 48px rgba(16, 24, 40, 0.2);
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--canvas); color: var(--text); }
body { font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px max(20px, calc((100vw - 1180px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-lockup { display: flex; flex-direction: column; }
.brand-lockup strong { font-size: 15px; font-weight: 680; letter-spacing: -0.015em; }
.brand-lockup span, .version-label { color: var(--text-tertiary); font-size: 11px; }
main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 30px 0 48px; }

.auth-view { display: grid; min-height: calc(100vh - 136px); place-items: center; }
.auth-panel { width: min(420px, 100%); padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.auth-heading { margin-bottom: 22px; }
.auth-heading h1, .page-heading h1, .panel h2, .dialog-heading h2 { margin: 3px 0 0; font-size: 20px; font-weight: 680; letter-spacing: -0.025em; }
.auth-heading p, .page-heading p, .dialog-heading p { margin: 7px 0 0; color: var(--text-secondary); line-height: 1.5; }
.section-kicker { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }

.form-field { display: block; margin-bottom: 14px; }
.form-field > span { display: flex; justify-content: space-between; margin-bottom: 6px; color: var(--text-secondary); font-size: 12px; font-weight: 600; }
.form-field small { color: var(--text-tertiary); font-weight: 400; }
input, select { width: 100%; min-height: 38px; padding: 8px 10px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 5px; outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

.button { min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: 5px; font-weight: 650; }
.button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.secondary { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.button.secondary:hover:not(:disabled) { background: var(--surface-muted); }
.button.danger { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 32%, transparent); }
.button-link { padding: 5px; color: var(--accent); background: transparent; border: 0; font-size: 12px; font-weight: 650; }
.button-link:hover { text-decoration: underline; }
.full-width { width: 100%; }
.inline-message { min-height: 19px; margin: 12px 0 0; color: var(--text-secondary); font-size: 12px; line-height: 1.45; }
.inline-message.error { color: var(--danger); }
.inline-message.success { color: var(--success); }

.dashboard { display: grid; gap: 18px; }
.owner-bar, .page-heading, .panel-heading, .users-heading, .owner-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.owner-bar { padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.owner-bar > div:first-child { display: flex; align-items: baseline; gap: 9px; }
.page-heading { padding: 12px 2px 2px; }
.context-label { color: var(--text-tertiary); font-size: 12px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { min-height: 120px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.metric span { display: block; color: var(--text-secondary); font-size: 12px; }
.metric strong { display: block; margin: 12px 0 5px; font-size: 28px; font-weight: 680; letter-spacing: -0.04em; }
.metric small { color: var(--text-tertiary); }
.workspace-grid { display: grid; grid-template-columns: minmax(280px, 0.78fr) minmax(380px, 1.22fr); gap: 18px; }
.panel { padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.panel-heading { margin-bottom: 18px; }
.panel h2 { font-size: 17px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-tertiary); font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
td { color: var(--text-secondary); font-size: 13px; }
td strong { display: block; color: var(--text); font-weight: 650; }
td small { color: var(--text-tertiary); }
td:last-child, th:last-child { text-align: right; }
.compact-table th, .compact-table td { padding: 9px 8px; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; font-weight: 650; }
.status::before { width: 7px; height: 7px; content: ""; background: var(--success); border-radius: 50%; }
.status.disabled::before { background: var(--text-tertiary); }
.empty-state { margin: 10px 0 0; padding: 22px; color: var(--text-tertiary); text-align: center; background: var(--surface-muted); border-radius: 5px; }

.security-panel summary { cursor: pointer; color: var(--text); font-weight: 650; }
.password-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; margin-top: 18px; }
.password-form .form-field { margin: 0; }

dialog { width: min(520px, calc(100% - 28px)); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-dialog); }
dialog::backdrop { background: rgba(16, 24, 40, 0.48); }
.dialog-card { padding: 22px; }
.dialog-heading { margin-bottom: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.split-actions { justify-content: space-between; }
.split-actions > div { display: flex; gap: 9px; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 360px; padding: 11px 14px; color: #fff; background: #1b2230; border-radius: 6px; box-shadow: var(--shadow-dialog); font-size: 12px; }

@media (max-width: 820px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-grid { grid-template-columns: 1fr; }
  .password-form { grid-template-columns: 1fr; }
  .owner-bar, .page-heading { align-items: flex-start; }
}

@media (max-width: 520px) {
  main { width: min(100% - 20px, 1180px); padding-top: 18px; }
  .app-header { padding-inline: 12px; }
  .auth-panel { padding: 20px; }
  .metrics-grid { grid-template-columns: 1fr; }
  .owner-bar, .page-heading, .users-heading { flex-direction: column; }
  .owner-actions { width: 100%; }
  .split-actions { flex-direction: column-reverse; }
  .split-actions > div { justify-content: stretch; }
  .split-actions .button { flex: 1; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #11151d;
    --surface: #191f2a;
    --surface-muted: #202733;
    --border: #303949;
    --border-strong: #465164;
    --text: #edf1f7;
    --text-secondary: #aeb8c8;
    --text-tertiary: #8490a3;
    --accent: #7ea2ff;
    --accent-hover: #9ab6ff;
    --accent-soft: #202e52;
    --success: #55c6a3;
    --danger: #ff8d84;
    --danger-soft: #3a2225;
    --focus: rgba(126, 162, 255, 0.22);
  }
  .button.primary { color: #0d1526; }
}
