/* ==========================================================================
   HB Certificate System — panel stylesheet
   Hand-written, no build step, no framework. Small design system:
   tokens → base → layout → components.
   ========================================================================== */

/* --- Tokens --------------------------------------------------------------- */
:root {
  --c-bg: #f4f6fa;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-border: #dde3ec;
  --c-border-strong: #c3ccda;

  --c-text: #1b2430;
  --c-text-muted: #6b7688;
  --c-text-invert: #ffffff;

  --c-primary: #1f4d8f;
  --c-primary-dark: #173c71;
  --c-primary-soft: #eaf0f9;

  --c-ok: #1c7c4a;
  --c-ok-soft: #e6f5ec;
  --c-warn: #9a6300;
  --c-warn-soft: #fdf3e0;
  --c-bad: #b42318;
  --c-bad-soft: #fdeceb;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --shadow-sm: 0 1px 2px rgba(20, 28, 45, .06);
  --shadow-md: 0 2px 8px rgba(20, 28, 45, .08);
  --shadow-lg: 0 8px 28px rgba(20, 28, 45, .12);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --topbar-h: 56px;
}

/* --- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 var(--sp-3); line-height: 1.25; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

p { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

.muted { color: var(--c-text-muted); }
.mono { font-family: var(--font-mono); font-size: .92em; }
.lead { color: var(--c-text-muted); margin-bottom: var(--sp-5); }
.nowrap { white-space: nowrap; }

/* --- Top bar ------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  height: var(--topbar-h);
  padding: 0 var(--sp-5);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--c-primary);
  color: var(--c-text-invert);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
}

.mainnav {
  display: flex;
  gap: var(--sp-1);
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.mainnav a {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--c-text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.mainnav a:hover { background: var(--c-surface-2); color: var(--c-text); text-decoration: none; }
.mainnav a.is-active { background: var(--c-primary-soft); color: var(--c-primary-dark); }

.userbox {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  white-space: nowrap;
}
.username { font-weight: 500; }

.role-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  color: var(--c-text-muted);
  font-size: 12px;
}

/* --- Layout -------------------------------------------------------------- */
.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-5) var(--sp-7);
}

.page-title { margin-bottom: var(--sp-4); }

.footer {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  max-width: 1160px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-6);
  color: var(--c-text-muted);
  font-size: 13px;
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.toolbar .spacer { flex: 1; }

/* --- Stats --------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.stat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.stat-ok   { border-left-color: var(--c-ok); }
.stat-warn { border-left-color: var(--c-warn); }
.stat-bad  { border-left-color: var(--c-bad); }

.stat-value {
  display: block;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  display: block;
  margin-top: var(--sp-1);
  color: var(--c-text-muted);
  font-size: 13px;
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px 16px;
  border: 1px solid var(--c-primary);
  border-radius: var(--r-sm);
  background: var(--c-primary);
  color: var(--c-text-invert);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--c-primary-dark); border-color: var(--c-primary-dark); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn-secondary {
  background: var(--c-surface);
  border-color: var(--c-border-strong);
  color: var(--c-text);
}
.btn-secondary:hover { background: var(--c-surface-2); border-color: var(--c-border-strong); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--c-text-muted);
}
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-text); }

.btn-danger { background: var(--c-bad); border-color: var(--c-bad); }
.btn-danger:hover { background: #96190f; border-color: #96190f; }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* --- Forms --------------------------------------------------------------- */
.field { margin-bottom: var(--sp-4); }

.field label,
.label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text);
}

.input, .select, .textarea,
input[type="text"], input[type="password"], input[type="date"],
input[type="number"], input[type="email"], input[type="file"],
select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
}

input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 1px;
  border-color: var(--c-primary);
}

textarea { min-height: 96px; resize: vertical; }

.hint {
  margin-top: var(--sp-1);
  color: var(--c-text-muted);
  font-size: 12.5px;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}
.field-row > .field { flex: 1; min-width: 180px; }

.code-input {
  font-family: var(--font-mono);
  font-size: 20px;
  letter-spacing: 6px;
  text-align: center;
}

/* --- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th, .table td {
  padding: 10px var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

.table th {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .3px;
  background: var(--c-surface-2);
  white-space: nowrap;
}

.table tbody tr:hover { background: var(--c-surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Badges and alerts --------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok     { background: var(--c-ok-soft);   color: var(--c-ok); }
.badge-warn   { background: var(--c-warn-soft); color: var(--c-warn); }
.badge-bad    { background: var(--c-bad-soft);  color: var(--c-bad); }
.badge-muted  { background: var(--c-surface-2); color: var(--c-text-muted); border: 1px solid var(--c-border); }

.alert {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
  font-size: 14px;
}
.alert-success { background: var(--c-ok-soft);   border-color: #bfe3cd; color: #15603a; }
.alert-error   { background: var(--c-bad-soft);  border-color: #f2c6c2; color: #8f1d14; }
.alert-info    { background: var(--c-primary-soft); border-color: #c9d8ef; color: var(--c-primary-dark); }

.error-code {
  font-size: 40px;
  font-weight: 700;
  color: var(--c-text-muted);
  margin: 0 0 var(--sp-2);
  line-height: 1;
}

/* --- Auth screens -------------------------------------------------------- */
body.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-5);
  background: linear-gradient(160deg, #eef2f8 0%, #e3e9f3 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-6);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
  font-weight: 600;
}

.auth-title { font-size: 18px; margin-bottom: var(--sp-4); }
.auth-card .btn { margin-top: var(--sp-2); }

.qr-box {
  display: flex;
  justify-content: center;
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}
.qr-box img, .qr-box svg { width: 200px; height: 200px; }

.secret-box {
  padding: var(--sp-3);
  background: var(--c-surface-2);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
  text-align: center;
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 860px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    position: static;
  }
  .mainnav { order: 3; width: 100%; flex: none; }
  .container { padding: var(--sp-4); }
}

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .card { padding: var(--sp-4); }
  .userbox .role-badge { display: none; }
}
