/* --------------------------------------------------------------------------
   Mobile Credential Manager — console styling.

   Laid out like the Elatec Mobile Credential Manager it is modelled on: a fixed
   left rail, a light working surface, and white cards that carry one subject
   each. Light only, on purpose — this is an administrative console that gets
   compared side by side with the tool it mirrors.
   -------------------------------------------------------------------------- */

:root {
  --bg: #f1f3f4;
  --surface: #ffffff;
  --surface-alt: #f8f9fa;
  --border: #e3e5e8;
  --border-strong: #d2d5da;

  --text: #202124;
  --text-muted: #5f6368;
  --text-faint: #80868b;

  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --primary-soft: #e8f0fe;
  --danger: #d93025;
  --danger-soft: #fce8e6;
  --success: #188038;
  --success-soft: #e6f4ea;
  --warning: #e37400;
  --warning-soft: #fef7e0;

  --radius: 8px;
  --radius-sm: 6px;
  /* Reading measure for the working area; the content is centred within it. */
  --measure: 1240px;
  --shadow: 0 1px 2px rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.06);
  --shadow-lg: 0 8px 24px rgba(60, 64, 67, 0.18);
  --sidebar-width: 264px;

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

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }

/* ------------------------------------------------------------------ shell */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: block; padding: 26px 24px 22px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-sub { font-size: 15px; font-weight: 600; color: var(--text); }
.brand-issuer { margin-top: 3px; font-size: 12px; color: var(--text-faint); }

.nav { padding: 4px 0; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 24px; color: var(--text-muted);
  font-size: 14px; border-left: 3px solid transparent; cursor: pointer;
}
.nav-item:hover { background: var(--surface-alt); text-decoration: none; color: var(--text); }
.nav-item.active { background: #f1f3f4; color: var(--text); font-weight: 500; border-left-color: var(--primary); }
.nav-item svg { width: 20px; height: 20px; flex: 0 0 20px; stroke: currentColor; fill: none; stroke-width: 1.6; }

.nav-group-toggle { width: 100%; background: none; border: 0; font: inherit; text-align: left; }
.nav-group-toggle .chevron { margin-left: auto; transition: transform 0.15s ease; }
.nav-group.open .chevron { transform: rotate(180deg); }
.nav-sub { display: none; padding-bottom: 4px; }
.nav-group.open .nav-sub { display: block; }
.nav-sub .nav-item { padding-left: 58px; font-size: 13px; }

.sidebar-foot { padding: 14px 24px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); }
.sidebar-foot .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); margin-right: 7px; }
.sidebar-foot .dot.ok { background: var(--success); }
.sidebar-foot .dot.warn { background: var(--warning); }
.sidebar-foot .dot.bad { background: var(--danger); }

/* -------------------------------------------------------------- main area */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/*
 * The topbar and the content share one measure and one centring rule, so the
 * account menu stays aligned with the page heading below it at every width.
 */
.topbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 14px 40px; min-height: 60px;
  width: 100%; max-width: var(--measure); margin: 0 auto;
}

.account { position: relative; }
.account-button {
  background: none; border: 0; font: inherit; color: var(--text-muted);
  cursor: pointer; padding: 6px 10px; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 8px;
}
.account-button:hover { background: var(--surface); }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 6px; z-index: 40;
}
.account-menu[hidden] { display: none; }
.account-menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  font: inherit; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text);
}
.account-menu button:hover { background: var(--surface-alt); }
.account-menu button.danger { color: var(--danger); }

.content { padding: 0 40px 56px; max-width: var(--measure); width: 100%; margin: 0 auto; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 22px;
}
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.page-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px 28px; margin-bottom: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.card-head h2 { font-size: 19px; }
.card-sub { color: var(--text-muted); font-size: 13px; margin: -10px 0 18px; }

/* Cards carry their own bottom margin; a grid of them needs the same, or the
   next card sits flush against the bottom row. */
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-dash { grid-template-columns: minmax(240px, 1fr) minmax(420px, 2.2fr); align-items: start; }

@media (max-width: 900px) {
  .grid-dash { grid-template-columns: 1fr; }
}

.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.stat-label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 34px; font-weight: 600; margin: 6px 0 12px; line-height: 1.1; }
.stat-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; display: flex; }
.stat-bar span { display: block; height: 100%; }
.stat-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.stat-legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 500; padding: 9px 20px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; background: none; color: var(--text);
  white-space: nowrap; line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { border-color: var(--primary); color: var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-soft); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-plain { border-color: var(--border-strong); color: var(--text-muted); }
.btn-plain:hover:not(:disabled) { background: var(--surface-alt); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.link-action {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; border-bottom: 1px solid var(--border);
  font: inherit; color: var(--primary); padding: 13px 4px; cursor: pointer; text-align: left;
}
.link-action:last-child { border-bottom: 0; }
.link-action:hover:not(:disabled) { color: var(--primary-hover); }
.link-action:disabled { color: var(--text-faint); cursor: not-allowed; }
.link-action.danger { color: var(--danger); }
.link-action .glyph { width: 18px; text-align: center; font-size: 15px; }

.field { margin-bottom: 18px; }
.field label, .field-label {
  display: block; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 6px; font-weight: 500;
}
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="url"], input[type="search"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
input[type="color"] { width: 56px; height: 40px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
textarea { min-height: 130px; resize: vertical; font-family: var(--mono); font-size: 13px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

.checkbox { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

.field-error { color: var(--danger); font-size: 12px; margin-top: 5px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 18px; }
.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 8px; }

.searchbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.searchbar input[type="search"] { max-width: 340px; }
.searchbar .spacer { margin-left: auto; }
.pager { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; }

/* ----------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; margin: 0 -28px; padding: 0 28px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 400; color: var(--text-muted); font-size: 13px;
  padding: 12px 16px 12px 0; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 15px 16px 15px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-alt); }
td.mono, .mono { font-family: var(--mono); font-size: 13px; }
td.shrink { width: 1%; white-space: nowrap; }

.empty { padding: 44px 8px; text-align: center; color: var(--text-muted); }
.empty p { margin: 0 0 16px; }

/* ------------------------------------------------------------ definitions */

.definitions { display: grid; grid-template-columns: max-content 1fr; gap: 12px 32px; align-items: baseline; }
.definitions dt { color: var(--text-muted); font-size: 13px; }
.definitions dd { margin: 0; }

/* ------------------------------------------------------------------ chips */

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px;
  border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-alt); color: var(--text-muted);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-active { background: var(--success-soft); color: var(--success); }
.chip-scheduled { background: var(--primary-soft); color: var(--primary); }
.chip-suspended { background: var(--warning-soft); color: var(--warning); }
.chip-expired, .chip-revoked { background: var(--danger-soft); color: var(--danger); }
.chip-plain::before { display: none; }

/* ------------------------------------------------------------------ alerts */

.alert { border-radius: var(--radius-sm); padding: 13px 16px; margin-bottom: 18px; font-size: 13px; line-height: 1.55; }
.alert strong { display: block; margin-bottom: 3px; }
.alert-info { background: var(--primary-soft); color: #174ea6; }
.alert-warn { background: var(--warning-soft); color: #a55600; }
.alert-error { background: var(--danger-soft); color: #a50e0e; }
.alert-success { background: var(--success-soft); color: #0d652d; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* ------------------------------------------------------------- pass card */

.pass-art {
  width: 190px; height: 120px; border-radius: 10px; flex: 0 0 190px;
  background: #1f2933; color: #fff; padding: 14px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
}
.pass-art::after {
  content: ""; position: absolute; inset: -40% -20% auto auto; width: 150%; height: 200%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.16), transparent 70%);
}
.pass-art .art-name { font-size: 13px; font-weight: 600; position: relative; }
.pass-art .art-layout { font-size: 12px; font-weight: 500; opacity: 0.85; position: relative; }

.pass-block { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; }
.pass-block .definitions { flex: 1 1 320px; }
.pass-block .pass-actions { flex: 0 0 230px; }

/* --------------------------------------------------------------- layouts */

.sourced-fields {
  background: var(--surface-alt); border-radius: var(--radius-sm);
  padding: 14px 16px; margin-bottom: 20px;
}
.sourced-fields .field-label { margin-bottom: 10px; }

.standard-field {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) minmax(120px, 1fr) minmax(120px, 1fr) 130px;
  gap: 12px; align-items: center;
  padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid transparent;
}
.standard-field:nth-child(odd) { background: var(--surface-alt); }
.standard-field.on { border-color: var(--primary-soft); background: var(--primary-soft); }
.standard-field .checkbox strong { font-weight: 500; color: var(--text); }
.standard-field-source { font-size: 12px; }
.standard-field-label, .standard-field-display { padding: 6px 10px; font-size: 13px; }

@media (max-width: 720px) {
  .standard-field { grid-template-columns: 1fr; gap: 8px; }
}

.divider { border: 0; border-top: 1px solid var(--border); margin: 26px 0 22px; }

.field-editor { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px; background: var(--surface-alt); }
.field-editor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.field-editor-head .drag { color: var(--text-faint); font-size: 16px; }
.field-editor-head .title { font-weight: 600; flex: 1; }
.field-editor .form-row { gap: 0 14px; }
.field-editor .field { margin-bottom: 12px; }

/* ----------------------------------------------------------------- chart */

.chart { width: 100%; height: 200px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .series { fill: none; stroke: var(--primary); stroke-width: 2; }
.chart .point { fill: var(--primary); }
.chart text { font-size: 11px; fill: var(--text-faint); }

/* ----------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(32, 33, 36, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 60;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: min(620px, 100%); max-height: 88vh; overflow-y: auto; padding: 26px 28px;
}
.modal h2 { margin-bottom: 6px; }
.modal .modal-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

/* ----------------------------------------------------------------- toast */

.toasts { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast {
  background: #202124; color: #fff; padding: 13px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13px; max-width: 460px; line-height: 1.5;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ------------------------------------------------------------- auth pages */

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.auth-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px; width: min(430px, 100%); }
.auth-card .brand { padding: 0 0 28px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card .auth-sub { color: var(--text-muted); margin: 0 0 26px; font-size: 13px; line-height: 1.6; }
.auth-card .btn { width: 100%; }
.password-rules { font-size: 12px; color: var(--text-muted); margin: -8px 0 18px; line-height: 1.6; }

/* ------------------------------------------------------------- claim page */

.claim-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.claim-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 34px 30px; width: min(430px, 100%); text-align: center; }
.claim-card h1 { font-size: 22px; margin-bottom: 8px; }
.claim-card .claim-sub { color: var(--text-muted); font-size: 14px; margin: 0 0 26px; }
.claim-art { width: 100%; max-width: 300px; aspect-ratio: 1.6; margin: 0 auto 24px; border-radius: 12px; background: #1f2933; color: #fff; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; text-align: left; position: relative; overflow: hidden; }
.claim-art::after { content: ""; position: absolute; inset: -40% -20% auto auto; width: 150%; height: 200%; background: radial-gradient(closest-side, rgba(255,255,255,0.16), transparent 70%); }
.claim-art .art-name { font-size: 17px; font-weight: 600; position: relative; }
.save-button img { display: block; height: 52px; margin: 0 auto; }
.claim-qr { margin-top: 26px; }
.claim-qr img { width: 190px; height: 190px; border-radius: 8px; }
.claim-meta { margin-top: 22px; font-size: 12px; color: var(--text-faint); line-height: 1.7; }

/* ----------------------------------------------------------------- misc */

.loading { padding: 60px; text-align: center; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 16px; }
.inline-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.secret-box {
  font-family: var(--mono); font-size: 13px; word-break: break-all; background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px 15px; margin: 12px 0;
}

.scan-list { list-style: none; margin: 0; padding: 0; }
.scan-list li { display: flex; gap: 14px; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--border); }
.scan-list li:last-child { border-bottom: 0; }
.scan-list .when { font-family: var(--mono); font-size: 12px; color: var(--text-faint); flex: 0 0 66px; }
.scan-list .what { flex: 1; min-width: 0; }
.scan-list .reason { font-size: 12px; color: var(--text-muted); }

@media (max-width: 1180px) {
  .content, .topbar { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s ease; z-index: 50; }
  .shell.nav-open .sidebar { transform: none; }
  .content, .topbar { padding-left: 20px; padding-right: 20px; }
  .table-wrap { margin: 0 -20px; padding: 0 20px; }
  .nav-toggle { display: inline-flex !important; }
}
.nav-toggle { display: none; margin-right: auto; }
