:root {
  --bg: #F4F6FA; --surface: #FFFFFF; --surface-2: #F8FAFC;
  --border: #DCE1EA; --border-strong: #B8C2D2;
  --text: #0F172A; --muted: #475569; --faint: #64748B;
  --primary: #1D4ED8; --primary-hover: #1E40AF; --primary-soft: #E8EEFF; --on-primary: #FFFFFF;
  --danger: #B91C1C; --danger-hover: #991B1B; --danger-soft: #FEE2E2;
  --warning-bg: #FEF3C7; --warning-border: #F2D27A; --warning-text: #713F12;
  --ring: #1D4ED8;
  --r-sm: 6px; --r: 8px; --r-lg: 12px; --r-xl: 16px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs: 15px; --fs-lg: 17px; --fs-h2: 18px; --fs-h1: 26px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { min-height: 100vh; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs); line-height: 1.5; }
[x-cloak] { display: none !important; }
*:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--r-sm); }
.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; }
.skip { position: absolute; left: -9999px; top: var(--s-3); background: var(--primary); color: #fff; padding: var(--s-2) var(--s-3); border-radius: var(--r); z-index: 100; text-decoration: none; }
.skip:focus { left: var(--s-3); }
.icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-primary { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.mono { font-family: var(--mono); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.mb-4 { margin-bottom: var(--s-4); }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-h1); font-weight: 650; }
h2 { font-size: var(--fs-h2); font-weight: 650; }
h3 { font-size: var(--fs); font-weight: 600; }
p { margin: 0; }
a { color: var(--primary); }
form { margin: 0; }

/* Buttons */
.btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); font: inherit; font-weight: 600; font-size: var(--fs); line-height: 1.2; padding: 10px 16px; border-radius: var(--r); border: 1px solid transparent; cursor: pointer; text-decoration: none; min-height: 40px; transition: background .15s, border-color .15s; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); min-height: 32px; }
.btn-block { width: 100%; }
.btn-google { background: #fff; color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-google:hover { background: var(--surface-2); }
.btn-google .glogo { width: 20px; height: 20px; }
.btn[aria-busy="true"] { opacity: .7; cursor: progress; }
.icon-btn { appearance: none; background: transparent; border: 0; color: var(--muted); width: 36px; height: 36px; border-radius: var(--r); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-4); }
.field label { font-weight: 600; font-size: var(--fs-sm); }
.field .hint { font-size: var(--fs-sm); color: var(--muted); }
.input, .textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r); padding: 10px 12px; min-height: 40px; width: 100%; }
.input:focus, .textarea:focus { border-color: var(--primary); outline: 2px solid var(--ring); outline-offset: 0; }
.textarea { font-family: var(--mono); font-size: var(--fs-sm); min-height: 140px; resize: vertical; line-height: 1.5; }
.field.is-invalid .input, .field.is-invalid .textarea { border-color: var(--danger); outline-color: var(--danger); }
.field-error { display: flex; color: var(--danger); font-size: var(--fs-sm); font-weight: 600; align-items: flex-start; gap: 6px; }
.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 12px; color: var(--faint); pointer-events: none; }
.search .input { padding-left: 38px; }
.code-input { font-family: var(--mono); font-size: 32px; letter-spacing: .35em; text-align: center; text-transform: uppercase; padding: 14px 8px 14px calc(8px + .35em); min-height: 64px; }

/* Alerts & badges */
.alert { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r); border: 1px solid; font-size: var(--fs-sm); line-height: 1.5; }
.alert .icon { margin-top: 2px; width: 18px; height: 18px; }
.alert-error { background: var(--danger-soft); border-color: #F3B4B4; color: #7F1D1D; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-info { background: var(--primary-soft); border-color: #C3D0FF; color: #1E3A8A; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.badge-blue { background: var(--primary-soft); border-color: #C3D0FF; color: #1E3A8A; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.card-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-4); }
.danger-card { border-color: #F3B4B4; }
.danger-card .card-head h2 { color: var(--danger); }

/* App bar */
.appbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.appbar-inner { max-width: 1120px; margin: 0 auto; padding: 0 var(--s-5); height: 60px; display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.brand .icon { width: 28px; height: 28px; color: var(--primary); }
.appbar-actions { display: flex; align-items: center; gap: var(--s-2); }
.usermenu { position: relative; }
.avatar-btn { appearance: none; background: transparent; border: 1px solid transparent; border-radius: 999px; padding: 4px 10px 4px 4px; display: inline-flex; align-items: center; gap: 10px; font: inherit; color: var(--text); cursor: pointer; }
.avatar-btn:hover { background: var(--surface-2); border-color: var(--border); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-sm); text-transform: uppercase; }
.usermenu-name { font-weight: 600; font-size: var(--fs-sm); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: var(--s-2); z-index: 20; }
.menu-head { padding: var(--s-2) var(--s-3) var(--s-3); border-bottom: 1px solid var(--border); margin-bottom: var(--s-2); display: flex; flex-direction: column; gap: 2px; }
.menu-head span { color: var(--muted); font-size: var(--fs-sm); }
.menu-item { appearance: none; background: transparent; border: 0; width: 100%; text-align: left; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--r); font: inherit; color: var(--text); text-decoration: none; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }

/* Page layout */
.page { max-width: 1120px; margin: 0 auto; padding: var(--s-6) var(--s-5) var(--s-7); }
.page-head { margin-bottom: var(--s-5); display: flex; flex-direction: column; gap: 4px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s-5); align-items: start; }
.col-side { display: flex; flex-direction: column; gap: var(--s-4); position: sticky; top: 84px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-3); flex-wrap: wrap; }
.section-head .search { flex: 0 1 320px; }
.count { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s-3); }
.narrow { max-width: 640px; margin: 0 auto; padding: var(--s-6) var(--s-5) var(--s-7); }
.center-page { max-width: 560px; margin: 0 auto; padding: var(--s-6) var(--s-4) var(--s-7); }
.breadcrumb { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s-4); display: flex; align-items: center; gap: 6px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); text-decoration: underline; }
.form-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-5); }
.app-footer { text-align: center; color: var(--faint); font-size: var(--fs-xs); padding: var(--s-5); }

/* Resources */
.resource-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.resource { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-4); display: flex; gap: var(--s-3); align-items: flex-start; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.resource:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.resource-icon { width: 36px; height: 36px; border-radius: var(--r); background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; flex: none; font-weight: 700; font-size: var(--fs-sm); text-transform: uppercase; }
.resource-icon.is-nohost { background: var(--surface-2); color: var(--faint); }
.resource-main { min-width: 0; flex: 1; }
.resource h3 a { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.resource h3 a:hover { color: var(--primary); text-decoration: underline; }
.resource h3 a .icon { color: var(--faint); width: 14px; height: 14px; }
.resource .host { font-family: var(--mono); font-size: var(--fs-xs); color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.resource .desc { font-size: var(--fs-sm); color: var(--muted); margin-top: 6px; }
.empty { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); padding: var(--s-6); text-align: center; color: var(--muted); }

/* SSH key */
.ssh-empty { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-3); }
.ssh-illus { width: 48px; height: 48px; border-radius: var(--r-lg); background: var(--surface-2); color: var(--faint); display: inline-flex; align-items: center; justify-content: center; }
.ssh-illus .icon { width: 24px; height: 24px; }
.key-meta { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-bottom: var(--s-3); }
.key-meta .mono { font-size: var(--fs-sm); color: var(--muted); }
.key-block { font-family: var(--mono); font-size: var(--fs-xs); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s-3); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.key-block.is-expanded { white-space: pre-wrap; word-break: break-all; }
.code-snippet { font-family: var(--mono); font-size: var(--fs-xs); background: #0F172A; color: #E2E8F0; border-radius: var(--r); padding: var(--s-3); display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }
.code-snippet .icon-btn { color: #CBD5E1; }
.code-snippet .icon-btn:hover { background: #1E293B; color: #fff; }

/* Auth & status pages */
.auth-layout { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--s-7) var(--s-4); gap: var(--s-5); background: radial-gradient(1200px 500px at 50% -10%, #E8EEFF 0%, var(--bg) 60%); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--s-6); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: var(--s-5); }
.brand-lockup { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2); }
.brand-lockup .logo { width: 48px; height: 48px; border-radius: var(--r-lg); background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; margin-bottom: var(--s-2); }
.brand-lockup .logo .icon { width: 26px; height: 26px; }
.brand-lockup p { color: var(--muted); }
.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--faint); font-size: var(--fs-sm); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-foot { color: var(--muted); font-size: var(--fs-sm); text-align: center; }
.status-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s-7) var(--s-4); }
.status-card { max-width: 520px; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--s-6); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: var(--s-4); align-items: flex-start; }
.status-icon { width: 56px; height: 56px; border-radius: var(--r-lg); background: var(--warning-bg); color: #92400E; display: inline-flex; align-items: center; justify-content: center; }
.status-icon .icon { width: 28px; height: 28px; }
.status-card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s-4); margin: 0; font-size: var(--fs-sm); }
.status-card dt { color: var(--muted); }
.status-card dd { margin: 0; font-weight: 600; }

/* Login code */
.dialog { border: 0; padding: 0; background: transparent; max-width: min(520px, calc(100% - 32px)); width: 100%; }
.dialog::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.code-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: var(--s-6); display: flex; flex-direction: column; gap: var(--s-4); }
.code-panel header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.code-display { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); text-align: center; }
.code { font-family: var(--mono); font-size: 44px; font-weight: 700; letter-spacing: .12em; display: flex; justify-content: center; gap: .5em; color: var(--text); line-height: 1.1; }
.code-display { cursor: pointer; }
.code-display .code { filter: blur(10px); user-select: none; transition: filter .15s ease; }
.code-reveal-hint { display: block; margin-top: var(--s-2); color: var(--muted); font-size: var(--fs-xs); }
.is-revealed .code-display .code { filter: none; user-select: text; }
.is-revealed .code-reveal-hint { visibility: hidden; }
@media (hover: hover) {
  .code-panel:not(.is-expired) .code-display:hover .code { filter: none; user-select: text; }
  .code-panel:not(.is-expired) .code-display:hover .code-reveal-hint { visibility: hidden; }
}
.code-expired-tag { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: rgba(248, 250, 252, .85); border-radius: inherit; color: var(--danger); font-weight: 700; font-size: var(--fs-lg); gap: 8px; }
.countdown { display: flex; flex-direction: column; gap: var(--s-2); }
.bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); transition: width 1s linear; }
.countdown .time { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.countdown .time strong { color: var(--text); }
.code-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.code-actions > * { flex: 1; }
.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: var(--fs-sm); display: flex; flex-direction: column; gap: 4px; }
.is-expired .code { filter: blur(6px); user-select: none; }
.is-expired .code-expired-tag { display: flex; }
.is-expired .bar-fill { background: var(--danger); }
.is-expired .countdown .time { color: var(--danger); }

@media (max-width: 720px) {
  .appbar-inner { height: 56px; padding: 0 var(--s-4); }
  .usermenu-name, .btn-admin span { display: none; }
  .brand span { font-size: var(--fs); }
  .page { padding: var(--s-5) var(--s-4) var(--s-7); }
  .grid { grid-template-columns: 1fr; }
  .col-side { position: static; order: -1; }
  .resource-list { grid-template-columns: 1fr; }
  .section-head .search { flex: 1 1 100%; }
  .card { padding: var(--s-4); }
  .code { font-size: 36px; letter-spacing: .1em; }
  .code-panel { padding: var(--s-5) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom)); }
  .code-actions { flex-direction: column; }
  .auth-card { padding: var(--s-5); }
  .form-actions .btn { flex: 1; }
  .menu { position: fixed; left: var(--s-3); right: var(--s-3); top: auto; bottom: var(--s-3); min-width: 0; }
  .dialog[open] { margin: auto 0 0; max-width: none; width: 100%; }
  .dialog .code-panel { border-radius: var(--r-xl) var(--r-xl) 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
