:root {
  color-scheme: light dark;
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #f7f8f5;
  --text: #202520;
  --muted: #687168;
  --line: #dde2db;
  --accent: #2f7654;
  --accent-soft: #e0efe5;
  --danger: #a64040;
  --shadow: 0 18px 45px rgb(47 69 54 / 9%);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b19;
    --surface: #202622;
    --surface-2: #272e2a;
    --text: #edf1ed;
    --muted: #aab4ac;
    --line: #38413b;
    --accent: #73bc8f;
    --accent-soft: #273f31;
    --danger: #f08b8b;
    --shadow: 0 18px 45px rgb(0 0 0 / 22%);
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, select, input { min-height: 42px; border-radius: 10px; }
button { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); padding: 0 15px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent), transparent 68%); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.danger { color: var(--danger); }
button.link-button { border: 0; background: transparent; color: var(--accent); padding-inline: 0; }
button:disabled { opacity: .55; cursor: wait; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 64px; }
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 26px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 750; font-size: 20px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: 21px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
h2 { margin-bottom: 9px; font-size: 26px; }
h3 { margin-bottom: 0; font-size: 17px; }
.eyebrow { margin-bottom: 6px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.65; }

.auth-card { width: min(480px, 100%); margin: 7vh auto 0; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
#recovery-codes-view > button { margin: 8px 8px 0 0; }
#recovery-codes-view > button:last-child { margin-right: 0; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.field-hint { margin: -4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
input, select { width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); padding: 0 12px; }
.password-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.password-field input { border-radius: 10px 0 0 10px; }
.password-field .password-toggle { min-width: 58px; border-left: 0; border-radius: 0 10px 10px 0; padding-inline: 10px; }
input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--accent); }
.toggle-label { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: 14px; }
.backup-form { gap: 12px; }
.backup-policy-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.backup-actions { display: flex; justify-content: flex-end; gap: 8px; }
.backup-hint { margin-top: 12px; }
.backup-state { margin: 8px 0 0; font-size: 13px; }
pre { overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.message { position: sticky; top: 12px; z-index: 10; margin: 0 auto 16px; width: min(720px, 100%); padding: 12px 15px; border-radius: 12px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent), transparent 55%); box-shadow: var(--shadow); }
.message.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger), transparent 50%); }
.storage-warning { margin-bottom: 14px; padding: 12px 15px; border-radius: 12px; color: #7a5310; background: #fff4d9; border: 1px solid #e7c675; }
.storage-warning.critical { color: var(--danger); background: color-mix(in srgb, var(--danger), transparent 90%); border-color: color-mix(in srgb, var(--danger), transparent 55%); }

.dashboard-head, .panel-head, .admin-chip { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dashboard-head { margin-bottom: 20px; }
.admin-chip { padding: 5px 5px 5px 13px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.admin-chip button { min-height: 34px; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.metrics article, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 24px rgb(47 69 54 / 4%); }
.metrics article { padding: 15px; }
.metrics span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.metrics strong { font-size: 20px; }
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { padding: 20px; }
.panel.wide { margin-bottom: 14px; }
.panel-head { margin-bottom: 18px; }
.compact-form { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
.compact-form button { align-self: end; }
.separator { height: 1px; background: var(--line); margin: 18px 0; }
.invitation-list-head { margin-bottom: 10px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.actions { display: flex; flex-wrap: wrap; gap: 6px; }
td.actions button { min-height: 32px; padding: 0 9px; font-size: 12px; }
.status { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 99px; background: var(--surface-2); }
.status.active { color: var(--accent); background: var(--accent-soft); }
.list { display: grid; gap: 8px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 11px; background: var(--surface-2); }
.list-item small { display: block; margin-top: 3px; color: var(--muted); }
.invitation-item > div:first-child { min-width: 0; }
.invitation-code { display: block; overflow-wrap: anywhere; color: var(--text); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; user-select: all; }
.inline-actions { display: flex; flex: 0 0 auto; gap: 6px; }
.inline-actions button { min-height: 34px; padding: 0 10px; }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 20px, 1180px); padding-top: 20px; }
  .auth-card, .panel { padding: 18px; border-radius: 14px; }
  .dashboard-head { align-items: flex-start; }
  .admin-chip { flex-direction: column; align-items: stretch; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .compact-form, .backup-policy-grid { grid-template-columns: 1fr; }
  .backup-actions { justify-content: stretch; }
  .backup-actions button { flex: 1; }
}

@media print {
  body { background: #fff; }
  .shell { width: 100%; margin: 0; padding: 0; }
  .brand, #message, #recovery-codes-view button { display: none !important; }
  #recovery-codes-view { width: 100%; margin: 0; padding: 0; border: 0; box-shadow: none; }
  #recovery-codes-view pre { border: 1px solid #bbb; color: #000; background: #fff; }
}
