:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: #17202a;
  background: #f4f6f8;
  font-synthesis: none;
  --border: #dfe4e8;
  --muted: #6c7781;
  --surface: #ffffff;
  --accent: #087f5b;
  --accent-hover: #06684b;
  --danger: #c92a2a;
  --warning: #b26a00;
  --info: #1769aa;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f4f6f8; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef2f3; }
.auth-panel { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 38px; box-shadow: 0 16px 38px rgba(20, 32, 38, .08); }
.brand-mark { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 7px; background: #17202a; color: white; font-weight: 800; }
.brand-mark.small { width: 36px; height: 36px; font-size: 12px; }
.eyebrow { margin: 24px 0 6px; color: var(--accent); font-size: 11px; font-weight: 700; }
.auth-panel h1 { margin: 0 0 28px; font-size: 24px; }
.auth-link { justify-self: center; margin-top: -4px; }

.form-stack, .form-grid { display: grid; gap: 16px; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
label { display: grid; gap: 7px; color: #34404a; font-size: 13px; font-weight: 600; }
input, textarea, select { width: 100%; min-height: 40px; border: 1px solid #cfd6dc; border-radius: 5px; padding: 9px 11px; color: #17202a; background: white; outline: none; }
textarea { min-height: 82px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8, 127, 91, .12); }
.form-error { margin: 12px 0 0; color: var(--danger); font-size: 13px; }

.button { min-height: 38px; border: 1px solid transparent; border-radius: 5px; padding: 8px 14px; font-weight: 650; }
.button.primary { color: white; background: var(--accent); }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { border-color: var(--border); color: #34404a; background: white; }
.button.danger { color: var(--danger); border-color: #ffc9c9; background: #fff5f5; }
.button.danger-submit { color: white; background: var(--danger); border-color: var(--danger); }
.button.small { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.button.wide { width: 100%; }
.text-button { padding: 3px; border: 0; color: var(--accent); background: transparent; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 5px; color: #34404a; background: white; font-size: 19px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid #2d3740; background: #1e272e; color: white; }
.brand-row { display: flex; gap: 11px; align-items: center; height: 72px; padding: 0 18px; border-bottom: 1px solid #343f47; }
.brand-row div:last-child { display: grid; gap: 2px; }
.brand-row span { color: #9fabb4; font-size: 11px; }
#main-nav { display: grid; gap: 3px; padding: 16px 10px; }
#main-nav button { min-height: 40px; border: 0; border-radius: 5px; padding: 0 13px; text-align: left; color: #bdc6cc; background: transparent; }
#main-nav button:hover, #main-nav button.active { color: white; background: #334047; }
#main-nav button.active { box-shadow: inset 3px 0 var(--accent); }
.sidebar-footer { margin-top: auto; display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 16px 18px; border-top: 1px solid #343f47; color: #c5cdd2; font-size: 12px; }
.workspace { min-width: 0; }
.topbar { height: 72px; display: flex; align-items: center; gap: 16px; padding: 0 28px; border-bottom: 1px solid var(--border); background: white; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar #refresh-button { margin-left: auto; }
#mobile-nav-button { display: none; }
.page-content { padding: 24px 28px 42px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { min-height: 104px; padding: 18px; border: 1px solid var(--border); border-radius: 7px; background: white; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 12px; font-size: 27px; }
.section { margin-top: 20px; }
.section-header, .toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-header h2, .toolbar h2 { margin: 0; font-size: 16px; }
.toolbar p, .section-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 7px; background: white; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 13px; text-align: left; white-space: nowrap; color: #5d6972; background: #f7f9fa; border-bottom: 1px solid var(--border); font-size: 11px; }
td { padding: 12px 13px; border-bottom: 1px solid #edf0f2; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.cell-title { font-weight: 650; }
.cell-subtitle { margin-top: 3px; color: var(--muted); font-size: 11px; }
.actions { display: flex; gap: 6px; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #edf1f3; color: #52606a; }
.badge.active, .badge.completed, .badge.online { color: #087f5b; background: #e6fcf5; }
.badge.suspended, .badge.queued { color: var(--warning); background: #fff4e6; }
.badge.revoked, .badge.failed, .badge.cancelled, .badge.offline { color: var(--danger); background: #fff0f0; }
.badge.running { color: var(--info); background: #e7f5ff; }
.empty-state { padding: 42px 20px; text-align: center; color: var(--muted); background: white; border: 1px solid var(--border); border-radius: 7px; }
.progress { width: 120px; height: 7px; overflow: hidden; background: #e9edef; border-radius: 999px; }
.progress span { display: block; height: 100%; background: var(--accent); }

dialog { width: min(660px, calc(100vw - 28px)); max-height: calc(100vh - 40px); padding: 0; overflow: auto; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 28px 70px rgba(15, 23, 30, .25); }
dialog::backdrop { background: rgba(14, 24, 31, .48); }
.dialog-header { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); background: white; }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.dialog-body { padding: 20px 22px; }
.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: white; }
#dialog-error { padding: 0 22px; }
.permission-list { display: grid; gap: 10px; grid-column: span 2; }
.permission-row { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 12px; align-items: center; padding: 11px; border: 1px solid var(--border); border-radius: 5px; }
.permission-picker { overflow: hidden; border: 1px solid var(--border); border-radius: 6px; background: white; }
.permission-picker summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; color: #34404a; cursor: pointer; list-style: none; }
.permission-picker summary::-webkit-details-marker { display: none; }
.permission-picker summary > span:first-child { display: grid; gap: 2px; }
.permission-picker summary small { color: var(--muted); font-size: 11px; }
.permission-picker summary > span:last-child { color: var(--accent); font-size: 12px; font-weight: 650; }
.permission-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); background: #f8faf9; }
.permission-choice { display: flex; align-items: flex-start; gap: 9px; min-height: 54px; padding: 10px; border: 1px solid var(--border); border-radius: 5px; background: white; cursor: pointer; }
.permission-choice input, .check-row input { width: 17px; min-height: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent); }
.permission-choice span { display: grid; gap: 3px; }
.permission-choice small { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.4; }
.permission-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 5px; }
.permission-group legend { padding: 0 6px; color: var(--text); font-size: 13px; font-weight: 700; }
.time-settings { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 6px; background: #f8faf9; }
.check-row { display: flex; grid-template-columns: none; align-items: center; gap: 9px; }
.time-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
input[readonly] { color: #52606a; background: #f2f4f5; }
.settings-grid { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.2fr); gap: 18px; align-items: start; }
.settings-panel { padding: 20px; border: 1px solid var(--border); border-radius: 7px; background: white; }
.settings-panel .section-header { align-items: flex-start; }
.security-note, .danger-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.danger-note { color: var(--danger); }
.protected-field { padding-top: 14px; border-top: 1px solid var(--border); }
.protected-field span { color: var(--muted); font-size: 11px; font-weight: 400; }
.challenge-section { display: grid; gap: 12px; }
.challenge-editor { display: grid; gap: 10px; }
.recovery-challenge { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 6px; }
.recovery-challenge .remove-challenge { margin-bottom: 1px; }

.friend-shell { min-height: 100vh; background: #f3f6f5; }
.friend-header { height: 62px; display: flex; align-items: center; padding: 0 max(20px, calc((100vw - 980px) / 2)); border-bottom: 1px solid var(--border); background: white; }
.friend-content { width: min(980px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0; }
.access-failure { width: min(560px, 100%); margin: 8vh auto 0; padding: 30px; border: 1px solid var(--border); border-top: 4px solid var(--danger); border-radius: 7px; background: white; box-shadow: 0 16px 38px rgba(20, 32, 38, .07); }
.access-failure .eyebrow { margin: 0 0 8px; color: var(--danger); }
.access-failure h1 { margin: 0; font-size: 23px; }
.failure-message { margin: 10px 0 0; color: #46525b; line-height: 1.7; }
.failure-details { display: grid; gap: 1px; margin: 22px 0 0; overflow: hidden; border: 1px solid var(--border); border-radius: 6px; background: var(--border); }
.failure-details div { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 16px; padding: 12px 14px; background: #f8faf9; }
.failure-details dt { color: var(--muted); font-size: 12px; }
.failure-details dd { margin: 0; color: #26323a; font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
.failure-advice { display: grid; gap: 5px; margin: 20px 0; color: #46525b; font-size: 13px; line-height: 1.6; }
.failure-advice strong { color: #26323a; }
.friend-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 32px; align-items: end; padding: 6px 0 28px; border-bottom: 1px solid var(--border); }
.friend-summary h1 { margin: 0 0 7px; font-size: 24px; }
.friend-summary p { margin: 0; color: var(--muted); }
.friend-identity .eyebrow { margin: 0 0 7px; }
.friend-metrics { display: grid; grid-template-columns: repeat(2, minmax(110px, auto)); gap: 28px; }
.quota-number { text-align: right; }
.quota-number strong { display: block; font-size: 28px; }
.quota-number span { color: var(--muted); font-size: 12px; }
.online-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(8, 127, 91, .12); }
.system-list { display: grid; gap: 12px; margin-top: 24px; }
.system-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center; padding: 17px 18px; border: 1px solid var(--border); border-radius: 7px; background: white; }
.system-item h2 { margin: 0; font-size: 16px; }
.system-item p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.launch-button { min-width: 132px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 360px; padding: 12px 15px; color: white; background: #26323a; border-radius: 5px; box-shadow: 0 10px 28px rgba(0,0,0,.18); font-size: 13px; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; width: 224px; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  #mobile-nav-button { display: inline-grid; place-items: center; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .page-content { padding: 18px 14px 34px; }
  .topbar { padding: 0 14px; }
  .metric-grid, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .permission-list { grid-column: span 1; }
  .recovery-challenge { grid-template-columns: 1fr; }
  .permission-row { grid-template-columns: 1fr; }
  .permission-choices, .permission-group, .time-grid { grid-template-columns: 1fr; }
  .toolbar { align-items: flex-start; }
  .friend-summary, .system-item { grid-template-columns: 1fr; }
  .access-failure { margin-top: 3vh; padding: 24px 20px; }
  .failure-details div { grid-template-columns: 1fr; gap: 4px; }
  .friend-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .quota-number { text-align: left; }
  .quota-number strong { font-size: 24px; }
  .launch-button { width: 100%; }
  .auth-panel { padding: 28px 22px; }
}
