/* ==========================================================================
   Document Verification System - stylesheet
   Custom, dependency free CSS. No frameworks, no external fonts, no CDNs.
   Sections: tokens, base, layout, components, public pages, admin, print
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
  --brand: #1d4ed8;
  --brand-dark: #1e3a8a;
  --brand-soft: #eff4ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #0369a1;
  --info-soft: #e0f2fe;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .16);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: .82rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------------ layout */
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 1rem; }
.wrap-narrow { max-width: 720px; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row-between { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* --------------------------------------------------------------- topbars */
.topbar {
  background: linear-gradient(120deg, var(--brand-dark), var(--brand));
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .1) inset;
}
.topbar .wrap { display: flex; align-items: center; gap: 1rem; min-height: 62px; padding-top: .5rem; padding-bottom: .5rem; }
.brand { display: flex; align-items: center; gap: .65rem; color: #fff; font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 10px; background: rgba(255, 255, 255, .16);
  display: grid; place-items: center; font-size: 1.1rem; border: 1px solid rgba(255, 255, 255, .22);
}
.brand .sub { display: block; font-size: .74rem; font-weight: 450; opacity: .82; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.topnav a {
  color: #e5edff; padding: .45rem .7rem; border-radius: 8px; font-size: .9rem; font-weight: 500;
}
.topnav a:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }
.topnav a.active { background: rgba(255, 255, 255, .2); color: #fff; }

.adminbar { background: #0f172a; color: #cbd5e1; }
.adminbar .wrap { display: flex; align-items: center; gap: .75rem; min-height: 52px; font-size: .9rem; }
.adminbar a { color: #cbd5e1; }
.adminbar a:hover { color: #fff; }
.adminbar .who { margin-left: auto; display: flex; align-items: center; gap: .75rem; }

.foot { border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: .86rem; margin-top: 2.5rem; }
.foot .wrap { padding-top: 1.25rem; padding-bottom: 1.25rem; }
.foot-links { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; gap: .75rem; margin: -.25rem 0 1rem; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .right { margin-left: auto; }
.card-body-flush { margin: 0 -1.25rem -1.25rem; }
.card-note { border-top: 1px solid var(--line); margin: 1rem -1.25rem -1.25rem; padding: .85rem 1.25rem; background: #f8fafc; border-radius: 0 0 var(--radius) var(--radius); color: var(--muted); font-size: .88rem; }

.stat { display: flex; gap: .8rem; align-items: flex-start; }
.stat .ico {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-size: 1.1rem; background: var(--brand-soft); color: var(--brand-dark); flex: none;
}
.stat .val { font-size: 1.5rem; font-weight: 680; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .84rem; }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .55rem;
  border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-valid { color: var(--ok); background: var(--ok-soft); border-color: #bbf7d0; }
.badge-expired { color: var(--warn); background: var(--warn-soft); border-color: #fde68a; }
.badge-revoked { color: var(--bad); background: var(--bad-soft); border-color: #fecaca; }
.badge-deleted { color: #6b7280; background: #f1f5f9; border-color: #e2e8f0; }
.badge-pending { color: var(--info); background: var(--info-soft); border-color: #bae6fd; }
.badge-plain::before { display: none; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .12s ease, border-color .12s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-sm { padding: .32rem .6rem; font-size: .82rem; }
.btn-lg { padding: .75rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------------- forms */
.field { margin-bottom: .9rem; }
.field > label, .label { display: block; font-weight: 600; font-size: .87rem; margin-bottom: .3rem; color: var(--ink-2); }
.hint { color: var(--muted); font-size: .8rem; margin-top: .25rem; display: block; }
.req { color: var(--bad); }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=date],
input[type=number], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font: inherit; font-size: .92rem; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12); outline: none; }
input[readonly], input[disabled], select[disabled] { background: #f8fafc; color: var(--muted); }
textarea { min-height: 90px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8 0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-size: .9rem; }
.check input { margin-top: .2rem; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 1rem; margin: 0 0 1rem; }
legend { font-weight: 650; font-size: .9rem; padding: 0 .35rem; }
.input-code { font-family: var(--mono); letter-spacing: .18em; text-transform: uppercase; font-size: 1.05rem; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.data th, table.data td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data thead th {
  background: #f8fafc; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.data tbody tr:hover { background: #f8fafc; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data caption { caption-side: top; text-align: left; padding: .75rem; color: var(--muted); }

/* ------------------------------------------------------------------ alerts */
.alert { display: flex; gap: .65rem; padding: .8rem 1rem; border-radius: var(--radius-sm); border: 1px solid; font-size: .9rem; margin-bottom: 1rem; }
.alert .a-ico { flex: none; font-weight: 700; }
.alert-success { background: var(--ok-soft); border-color: #bbf7d0; color: #14532d; }
.alert-error { background: var(--bad-soft); border-color: #fecaca; color: #7f1d1d; }
.alert-warn { background: var(--warn-soft); border-color: #fde68a; color: #78350f; }
.alert-info { background: var(--info-soft); border-color: #bae6fd; color: #075985; }
.alert ul { margin: .25rem 0 0; padding-left: 1.1rem; }

/* --------------------------------------------------------------- utilities */
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .5rem; border-radius: 6px;
  background: #f1f5f9; border: 1px solid var(--line); font-size: .8rem; color: var(--ink-2);
}
.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: .45rem .9rem; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.divider-label { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .82rem; margin: 1.25rem 0 .9rem; }
.divider-label::before, .divider-label::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; }
.toolbar .grow { flex: 1 1 190px; }

.pagination { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; justify-content: center; margin-top: 1rem; }
.pagination a, .pagination span {
  min-width: 34px; height: 34px; padding: 0 .5rem; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-2); border-radius: 8px; background: #fff; font-size: .86rem; color: var(--ink-2);
}
.pagination .current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pagination .disabled { opacity: .45; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 72px; }
.spark div { flex: 1; background: var(--brand-soft); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.spark div span { position: absolute; inset: auto 0 -1.15rem 0; text-align: center; font-size: .6rem; color: var(--muted); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .85rem; color: var(--muted); font-weight: 600; font-size: .89rem; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .big { font-size: 2rem; margin-bottom: .5rem; opacity: .5; }

.copy-field { display: flex; gap: .4rem; }
.copy-field input { font-family: var(--mono); font-size: .8rem; }

/* =========================================================== public portal */
.public-hero {
  background: linear-gradient(135deg, var(--brand-dark) 0%, #1e40af 55%, #2563eb 100%);
  color: #fff; padding: 2.5rem 0; text-align: center;
}
.public-hero h1 { color: #fff; font-size: 1.85rem; margin-bottom: .4rem; }
.public-hero p { color: #dbeafe; max-width: 620px; margin: 0 auto; }
.public-body { padding: 1.75rem 0 2.5rem; }
.public-foot-links { display: flex; gap: 1.25rem; justify-content: center; flex-wrap: wrap; }

.verify-card { max-width: 620px; margin: 0 auto; }
.verify-result { text-align: center; padding: 1.5rem 1.25rem 1.25rem; }
.verify-result .stamp {
  width: 92px; height: 92px; margin: 0 auto .9rem; border-radius: 50%; display: grid; place-items: center;
  font-size: 2.4rem; font-weight: 700; border: 3px solid;
}
.stamp-valid { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.stamp-expired { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.stamp-revoked { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); }
.stamp-missing { color: var(--muted); border-color: var(--muted); background: #f1f5f9; }
.verify-result h2 { font-size: 1.45rem; }
.verify-result .status-line { font-size: 1.05rem; font-weight: 600; margin-bottom: .3rem; }
.verify-detail { text-align: left; margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1.25rem; }
.manual-hint { font-size: .84rem; color: var(--muted); text-align: center; margin-top: 1rem; }

.faq { max-width: 720px; margin: 0 auto; }
.faq details { border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm); padding: .75rem 1rem; margin-bottom: .6rem; }
.faq summary { cursor: pointer; font-weight: 600; font-size: .92rem; }
.faq p { margin: .6rem 0 0; color: var(--muted); font-size: .88rem; }

/* =================================================================== admin */
.admin-layout { display: flex; align-items: flex-start; gap: 1.25rem; padding: 1.25rem 0 2.5rem; }
.side { width: 214px; flex: none; position: sticky; top: 1rem; }
.side .card { padding: .6rem; }
.side a {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .65rem; border-radius: 8px;
  color: var(--ink-2); font-size: .9rem; font-weight: 500;
}
.side a:hover { background: var(--brand-soft); color: var(--brand-dark); text-decoration: none; }
.side a.active { background: var(--brand); color: #fff; }
.side .sep { height: 1px; background: var(--line); margin: .5rem .25rem; }
.side .grp { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: .6rem .65rem .25rem; }
.main { flex: 1 1 auto; min-width: 0; }
.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: linear-gradient(140deg, #0f172a, #1e3a8a 60%, #1d4ed8); }
.login-box { width: 100%; max-width: 400px; }
.login-box .card { padding: 1.75rem; }
.login-head { text-align: center; margin-bottom: 1.25rem; }
.login-head .logo { width: 54px; height: 54px; border-radius: 14px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 1.5rem; margin: 0 auto .7rem; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; padding: 1.25rem; }
.modal h3 { margin-bottom: .5rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

.qr-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .75rem; display: inline-block; }
.qr-box img { display: block; width: 190px; height: 190px; image-rendering: pixelated; }

.toast-wrap { position: fixed; top: 12px; right: 12px; z-index: 60; width: min(360px, calc(100vw - 24px)); }
.toast { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: .7rem .9rem; margin-bottom: .5rem; font-size: .88rem; }
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--bad); }

/* =================================================================== print */
.print-only { display: none; }

@media print {
  body { background: #fff; }
  .topbar, .foot, .side, .no-print, .toolbar, .pagination, .form-actions, .adminbar { display: none !important; }
  .print-only { display: block; }
  .admin-layout { display: block; padding: 0; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; }
  .label-card { width: 100%; border: 1.5pt solid #0f172a; border-radius: 6pt; padding: 10pt; margin: 0 0 8pt; break-inside: avoid; }
  .label-card .qr { width: 42mm; height: 42mm; }
  a { color: #000; text-decoration: none; }
  @page { margin: 10mm; }
}

@media (max-width: 860px) {
  .admin-layout { flex-direction: column; }
  .side { width: 100%; position: static; }
  .side nav { display: flex; flex-wrap: wrap; gap: .2rem; }
  .side .sep, .side .grp { display: none; }
  .kv { grid-template-columns: 1fr; gap: .1rem; }
  .kv dt { margin-top: .5rem; }
  .topbar .wrap { flex-wrap: wrap; }
  .topnav { width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
