/* ============================================================
   Homelab Runner Control Panel — component stylesheet
   Zero external dependencies, light theme.
   ============================================================ */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f0;
  --border-strong: #d5dce8;
  --text: #1f2937;
  --muted: #64748b;
  --faint: #94a3b8;
  --primary: #4f46e5;
  --primary-weak: #eef2ff;
  --primary-hover: #4338ca;
  --success: #059669;
  --success-weak: #ecfdf5;
  --warning: #d97706;
  --warning-weak: #fffbeb;
  --danger: #dc2626;
  --danger-weak: #fef2f2;
  --info: #2563eb;
  --info-weak: #eff6ff;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 4px 16px rgba(15, 23, 42, .07);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
pre { font-family: var(--mono); font-size: 12px; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- Auth ---------- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 15% -10%, #e0e7ff 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 100%, #dbeafe 0%, transparent 50%), var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg); padding: 32px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.auth-brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.auth-card h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.02em; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.auth-tabs button { flex: 1; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex: 0 0 244px; position: fixed; top: 0; bottom: 0; left: 0;
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; z-index: 30;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 20px 18px; color: #fff;
  font-weight: 700; font-size: 15px; letter-spacing: -.01em; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.sidebar-scroll { overflow-y: auto; flex: 1; padding: 12px 10px; }
.nav-group { margin-bottom: 18px; }
.nav-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: #6b7280; padding: 6px 12px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--sidebar-text); font-size: 13px; font-weight: 500; margin-bottom: 2px; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { width: 17px; height: 17px; flex: 0 0 auto; opacity: .9; }
.nav-badge { margin-left: auto; background: rgba(255,255,255,.14); padding: 0 7px; border-radius: 20px; font-size: 10px; font-weight: 700; }
.nav-item.active .nav-badge { background: rgba(255,255,255,.25); }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 11px; color: #6b7280; }

.main { margin-left: 244px; flex: 1; min-width: 0; }
.topbar {
  height: 62px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 28px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.crumb { color: var(--faint); font-size: 12px; margin-bottom: 2px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-weak); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.content { padding: 26px 28px 60px; max-width: 1440px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.page-head h2 { margin: 0 0 3px; font-size: 22px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- Cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1080px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr); } .grid.cols-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 720px) { .grid.cols-2,.grid.cols-3,.grid.cols-4 { grid-template-columns: 1fr; } }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat .label svg { width: 15px; height: 15px; opacity: .7; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.03em; margin-top: 8px; line-height: 1.1; }
.stat .foot { font-size: 11px; color: var(--faint); margin-top: 6px; }
.stat .accent { position: absolute; right: 14px; top: 14px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.accent.indigo { background: var(--primary-weak); color: var(--primary); }
.accent.green { background: var(--success-weak); color: var(--success); }
.accent.amber { background: var(--warning-weak); color: var(--warning); }
.accent.red { background: var(--danger-weak); color: var(--danger); }
.accent.blue { background: var(--info-weak); color: var(--info); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: 1px solid var(--primary);
  padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: filter .15s, background .15s; white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.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(--muted); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { filter: brightness(.92); }
.btn.danger-outline { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn.danger-outline:hover { background: var(--danger-weak); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Forms ---------- */
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.field-hint { font-size: 11px; color: var(--muted); margin-top: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface); color: var(--text); outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
textarea { resize: vertical; min-height: 72px; }
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.checkbox { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; }
.auth-page input { padding: 11px 12px; }

/* ---------- Table ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td .sub { display: block; font-size: 11px; color: var(--faint); margin-top: 2px; }
td.mono, .mono { font-family: var(--mono); }
.tab-actions { display: flex; gap: 10px; white-space: nowrap; }
.tab-actions a, .tab-actions button { font-size: 12px; }
.empty { padding: 40px 20px; text-align: center; color: var(--faint); font-size: 13px; }
.empty svg { width: 34px; height: 34px; opacity: .5; display: block; margin: 0 auto 10px; }

/* ---------- Badges & progress ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 650; line-height: 1.6; white-space: nowrap; }
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.on, .badge.success { background: var(--success-weak); color: var(--success); }
.badge.off, .badge.muted { background: var(--surface-2); color: var(--muted); }
.badge.warn, .badge.warning { background: var(--warning-weak); color: var(--warning); }
.badge.err, .badge.danger { background: var(--danger-weak); color: var(--danger); }
.badge.info { background: var(--info-weak); color: var(--info); }
.badge.primary { background: var(--primary-weak); color: var(--primary); }
.progress { height: 6px; background: var(--border); border-radius: 20px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 20px; }
.progress.green > i { background: var(--success); }
.progress.amber > i { background: var(--warning); }
.progress.red > i { background: var(--danger); }
.progress-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .fld { display: flex; flex-direction: column; gap: 4px; }
.toolbar .fld label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.toolbar input, .toolbar select { min-width: 130px; padding: 7px 10px; font-size: 12px; }
.toolbar .grow { flex: 1; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.pagination .pages { display: flex; gap: 5px; align-items: center; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(2px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s ease-out; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 88vh; display: flex; flex-direction: column; animation: pop .18s ease-out; }
.modal.wide { max-width: 760px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .x { cursor: pointer; color: var(--faint); font-size: 22px; line-height: 1; background: none; border: none; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98) } to { opacity: 1; transform: none } }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; top: 76px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 10px; box-shadow: var(--shadow); padding: 12px 16px; font-size: 13px; min-width: 240px; max-width: 380px; animation: slide .2s ease-out; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slide { from { opacity: 0; transform: translateX(20px) } to { opacity: 1; transform: none } }

/* ---------- Misc ---------- */
.hint { font-size: 12px; color: var(--muted); }
.note { padding: 12px 14px; border-radius: 9px; font-size: 12px; background: var(--info-weak); color: #1e40af; border: 1px solid #dbeafe; margin: 12px 0; }
.note.warn { background: var(--warning-weak); color: #92400e; border-color: #fde68a; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13px; }
.kv .k { color: var(--muted); }
.secret-box { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 9px; padding: 12px 14px; word-break: break-all; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; background: var(--surface); position: relative; display: flex; flex-direction: column; }
.plan-card.featured { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.plan-card .tier { font-size: 11px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .08em; }
.plan-card h4 { margin: 6px 0 3px; font-size: 17px; }
.plan-card .price { font-size: 26px; font-weight: 700; letter-spacing: -.03em; margin: 10px 0 2px; }
.plan-card .price span { font-size: 12px; color: var(--muted); font-weight: 400; }
.plan-card ul { list-style: none; padding: 0; margin: 14px 0 18px; font-size: 12px; color: var(--muted); flex: 1; }
.plan-card li { padding: 4px 0; }
.plan-card li::before { content: '✓'; color: var(--success); font-weight: 700; margin-right: 7px; }
.audit-detail { background: #0f172a; color: #a5f3fc; border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 11px; margin-top: 8px; }
.audit-row { cursor: pointer; }
.loading { padding: 60px; text-align: center; color: var(--faint); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------- Payment UI ---------- */
.badge.green { background: var(--success-weak); color: var(--success); }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.switch-row input { width: 16px; height: 16px; }
.pay-methods { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.pay-method { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; cursor: pointer; background: var(--surface); }
.pay-method:hover { border-color: var(--primary); }
.pay-method input { accent-color: var(--primary); }
.pay-dlg { text-align: left; }
.pay-amount { font-size: 30px; font-weight: 700; text-align: center; margin: 4px 0 2px; }
.pay-stage { margin-top: 16px; min-height: 90px; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border-radius: 10px; padding: 16px; font-size: 13px; }
.pay-ready { text-align: center; }
.pay-ready-icon { color: var(--primary); }
.pay-ready-icon svg { width: 34px; height: 34px; }
.pay-ready p { margin: 6px 0 12px; color: var(--muted); }
.pay-ready .btn { margin: 0 4px; }
.pay-error { color: var(--danger); display: flex; align-items: center; gap: 8px; }
.pay-error svg { width: 18px; height: 18px; }
.pay-tip { font-size: 11px; color: var(--muted); margin-top: 12px; text-align: center; line-height: 1.6; }
.help-list { font-size: 13px; color: var(--muted); line-height: 2; padding-left: 20px; margin: 0; }
.help-list code { font-size: 12px; }
@media (max-width: 720px) { .form-row.two { grid-template-columns: 1fr; } }

/* ---------- Site footer / legal links ---------- */
.site-foot {
  margin: 26px 24px 18px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
  font-size: 12px; color: var(--muted); line-height: 1.8;
}
.site-foot a { color: var(--primary); text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }
.site-foot > div:last-child { margin-left: auto; }
.auth-page .site-foot { margin: 22px 0 0; justify-content: center; text-align: center; }
.auth-page .site-foot > div { width: 100%; }
.auth-page .site-foot > div:last-child { margin-left: 0; }
@media (max-width: 720px) {
  .site-foot { margin: 20px 14px 14px; }
  .site-foot > div:last-child { margin-left: 0; }
}
