/* MiCA Monitor — "institutional data terminal" visual system.
   Tokens taken verbatim from the design handoff. */
:root {
  --ink: #0f1720; --ink2: #33404f; --ink3: #4a5563; --ink4: #5b6675;
  --muted: #8a93a1;
  --line-row: #eef1f5; --line-sec: #e6eaf0; --line-input: #d5dae2; --line-btn: #e0e4ea;
  --fill1: #fbfcfd; --fill2: #f6f8fa; --fill3: #eef1f6; --fill4: #f2f4f7;
  --accent: #1f5fd6; --accent-tint: #eaf0fb;
  --dark: #12151c;
  --pos: #12805c;
  --danger: #b23227; --danger2: #9a2b21; --danger3: #b6635a; --danger-tint: #f6e5e2;
  --banner: #fdf3f1; --banner-line: #f3d9d4;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #fff; }
body { font-family: var(--sans); color: var(--ink); -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #c9cfd8; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
.mono { font-family: var(--mono); }
.min0 { min-width: 0; }
.hidden { display: none !important; }
a { color: inherit; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Header ---------- */
.hdr { display: flex; align-items: center; justify-content: space-between; padding: 15px 26px; border-bottom: 1px solid var(--line-sec); flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 31px; height: 31px; border-radius: 7px; background: var(--dark); display: flex; align-items: center; justify-content: center; color: #fff; font-family: var(--mono); font-weight: 600; font-size: 15px; flex: 0 0 auto; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--muted); }
.hdr-right { display: flex; align-items: center; gap: 14px; font-family: var(--mono); font-size: 11px; color: var(--ink4); }
.pill { display: flex; align-items: center; gap: 6px; padding: 5px 9px; background: var(--accent-tint); color: var(--accent); border-radius: 20px; font-weight: 600; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ---------- Stats strip ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--line-sec); flex: 0 0 auto; }
.stat { padding: 14px 22px; border-right: 1px solid var(--line-row); }
.stat:first-child { padding-left: 26px; }
.stat:last-child { border-right: 0; padding-right: 26px; }
.stat-label { font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat-value { font-family: var(--mono); font-size: 26px; font-weight: 600; margin-top: 4px; line-height: 1.1; }
.stat-value.danger { color: var(--danger); }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-sub.pos { color: var(--pos); }
.stat-sub.danger3 { color: var(--danger3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; padding: 0 26px; border-bottom: 1px solid var(--line-sec); background: var(--fill1); flex: 0 0 auto; }
.tab { position: relative; appearance: none; border: 0; background: transparent; padding: 13px 14px; font-family: inherit; font-size: 13px; font-weight: 600; color: var(--ink2); cursor: pointer; }
.tab .cnt { color: var(--muted); font-weight: 500; }
.tab.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 4px; }

/* ---------- Filter toolbar ---------- */
.toolbar { display: flex; align-items: flex-end; gap: 11px; padding: 14px 26px; border-bottom: 1px solid var(--line-sec); flex-wrap: wrap; flex: 0 0 auto; }
.field { display: flex; flex-direction: column; }
.field.search { flex: 1 1 220px; min-width: 200px; }
.field-label { font-size: 10px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.search-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-input); border-radius: 7px; padding: 8px 10px; background: #fff; }
.search-box svg { flex: 0 0 auto; }
.search-box input { border: 0; outline: 0; flex: 1; min-width: 0; font-family: inherit; font-size: 13px; color: var(--ink); background: transparent; }
.toolbar select { border: 1px solid var(--line-input); border-radius: 7px; padding: 8px 10px; font-family: inherit; font-size: 13px; color: var(--ink); background: #fff; cursor: pointer; min-width: 118px; }
#f-service { min-width: 130px; }
#f-reg, #f-since { min-width: 122px; }
.toolbar select:focus-visible, .search-box:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-box:focus-within { outline-offset: 0; border-color: var(--accent); }
.clear-btn { appearance: none; border: 1px solid var(--line-btn); background: #fff; border-radius: 7px; padding: 9px 12px; font-family: inherit; font-size: 12px; font-weight: 600; color: var(--ink4); cursor: pointer; }
.clear-btn:hover { background: var(--fill2); }

/* ---------- Content region (single scroll area) ---------- */
.content { flex: 1; min-height: 0; overflow: auto; }
.empty { padding: 44px 26px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Directory ---------- */
.directory { min-width: 100%; }
.dir-head, .row { display: grid; grid-template-columns: 2.2fr 1fr 0.9fr 1.6fr 0.9fr 1fr; gap: 14px; }
.dir-head { position: sticky; top: 0; z-index: 1; padding: 10px 26px; background: var(--fill2); border-bottom: 1px solid var(--line-sec); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.row { padding: 12px 26px; border-bottom: 1px solid var(--line-row); cursor: pointer; align-items: center; }
.row:hover { background: #f5f9ff; }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell-entity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.monogram { width: 30px; height: 30px; border-radius: 6px; background: var(--fill3); color: var(--ink2); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; font-weight: 600; flex: 0 0 auto; }
.entity-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entity-legal { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-home { display: flex; align-items: center; gap: 7px; min-width: 0; }
.cc-chip { font-family: var(--mono); font-size: 11px; font-weight: 600; background: var(--dark); color: #fff; padding: 2px 5px; border-radius: 4px; flex: 0 0 auto; }
.cc-chip.sm { font-size: 10px; padding: 1px 5px; }
.country-name { font-size: 12px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-reg { font-family: var(--mono); font-size: 12px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-services { display: flex; flex-wrap: wrap; gap: 4px; }
.svc-chip { font-size: 10px; font-weight: 600; color: #3d4a5c; background: var(--line-row); border-radius: 4px; padding: 2px 6px; font-family: var(--mono); }
.cell-services .more { font-size: 10px; font-weight: 600; color: var(--muted); padding: 2px 4px; }
.cell-passport { font-size: 12px; color: var(--ink2); }
.cell-auth { font-family: var(--mono); font-size: 12px; color: var(--ink2); }
.dir-head-sort { cursor: pointer; user-select: none; }
.dir-head-sort:hover { color: var(--ink2); }
.dir-head-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.sort-arrow { color: var(--accent); margin-left: 3px; font-size: 10px; }

/* ---------- Non-compliant ---------- */
.nc-banner { display: flex; align-items: center; gap: 10px; padding: 12px 26px; background: var(--banner); border-bottom: 1px solid var(--banner-line); color: var(--danger2); font-size: 12px; flex-wrap: wrap; }
.nc-strong { font-weight: 700; }
.nc-muted { color: var(--danger3); }
.nc-row { padding: 14px 26px; border-bottom: 1px solid var(--line-row); }
.nc-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.nc-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.nc-name { font-weight: 600; font-size: 14px; }
.nc-tag { font-size: 10px; font-weight: 700; letter-spacing: .06em; color: var(--danger); background: var(--danger-tint); padding: 2px 6px; border-radius: 4px; }
.nc-date { font-family: var(--mono); font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.nc-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--ink4); flex-wrap: wrap; }
.nc-meta .dot-sep { color: #c3cad3; }
.nc-site { font-family: var(--mono); color: var(--accent); word-break: break-all; }
.nc-more { color: var(--muted); }
.nc-reason { margin-top: 6px; font-size: 12px; color: var(--ink3); line-height: 1.5; }

/* ---------- Changes ---------- */
.changes { padding: 6px 0 14px; }
.change-group { padding: 12px 26px 4px; }
.change-date { font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line-row); padding-bottom: 7px; }
.event { display: flex; gap: 12px; padding: 9px 26px; }
.event-tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 3px 7px; border-radius: 4px; margin-top: 1px; white-space: nowrap; }
.tag-added { color: #0d6b4f; background: #e4f2ec; }
.tag-changed { color: #9a6410; background: #f8efd9; }
.tag-removed { color: #51596b; background: #eaecf0; }
.tag-warning { color: #b23227; background: #f6e5e2; }
.event-body { min-width: 0; }
.event-title { font-size: 13px; }
.event-entity { font-weight: 600; }
.event-meta { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.event-detail { font-size: 12px; color: var(--ink4); line-height: 1.5; margin-top: 2px; }

/* ---------- Detail drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 20, 30, .28); z-index: 40; animation: fade .16s ease; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(462px, 100vw); background: #fff; border-left: 1px solid var(--line-sec); box-shadow: -16px 0 44px rgba(20, 30, 48, .16); display: flex; flex-direction: column; z-index: 41; animation: slide .18s cubic-bezier(.22, .61, .36, 1); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .scrim, .drawer { animation: none; } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px; border-bottom: 1px solid var(--line-row); flex: 0 0 auto; }
.drawer-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.drawer-monogram { width: 44px; height: 44px; border-radius: 9px; background: var(--dark); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 600; font-size: 16px; flex: 0 0 auto; }
.drawer-name { font-weight: 700; font-size: 17px; }
.drawer-legal { font-size: 12px; color: var(--muted); }
.drawer-close { appearance: none; border: 1px solid var(--line-btn); background: #fff; width: 30px; height: 30px; border-radius: 7px; cursor: pointer; color: var(--ink4); font-size: 14px; flex: 0 0 auto; }
.drawer-close:hover { background: var(--fill2); }
.drawer-body { padding: 18px 24px; overflow: auto; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 18px; }
.fact.full { grid-column: 1 / 3; }
.fact-label { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.fact-value { font-size: 13px; color: var(--ink2); line-height: 1.45; }
.fact-value.mono { font-family: var(--mono); font-size: 12px; }
.fact-value.break { word-break: break-all; }
.section { margin-top: 18px; }
.section-label { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.services-list { display: flex; flex-direction: column; gap: 7px; }
.service-item { display: flex; gap: 9px; align-items: flex-start; }
.service-code { font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--accent); background: var(--accent-tint); border-radius: 4px; padding: 2px 5px; flex: 0 0 auto; margin-top: 1px; }
.service-label { font-size: 12.5px; color: var(--ink2); line-height: 1.45; }
.passport-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.pass-chip { font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--ink2); background: var(--fill4); border: 1px solid var(--line-sec); border-radius: 4px; padding: 2px 5px; }
.website-link { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-all; }
.website-link:hover { text-decoration: underline; }
.comments-box { margin-top: 16px; padding: 12px 14px; background: var(--fill2); border: 1px solid var(--line-sec); border-radius: 8px; font-size: 12px; color: var(--ink3); line-height: 1.5; }
.muted-note { font-size: 12.5px; color: var(--muted); }

/* Non-compliant drawer */
.drawer-monogram.nc { background: var(--danger); }
.nc-status-banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 16px; background: var(--banner); border: 1px solid var(--banner-line); border-radius: 8px; font-size: 12px; color: var(--danger3); }
.site-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.site-item { font-family: var(--mono); font-size: 12.5px; color: var(--ink2); word-break: break-all; }
.nc-reason-box { font-size: 12.5px; color: var(--ink3); line-height: 1.55; }

/* ---------- Loading ---------- */
body.loading .stat-value, body.loading .cnt { color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat:nth-child(4) { padding-left: 26px; }
  .stat:nth-child(3) { border-right: 0; }
}
@media (max-width: 820px) {
  .hdr, .toolbar, .dir-head, .row, .nc-banner, .nc-row, .event, .change-group, .stat { padding-left: 16px; padding-right: 16px; }
  .stat:first-child, .stat:last-child { padding-left: 16px; padding-right: 16px; }
  .directory { min-width: 720px; }              /* horizontal scroll keeps columns aligned */
  .dir-head { padding-left: 16px; }
}
@media (max-width: 620px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat { border-right: 0; border-bottom: 1px solid var(--line-row); }
  .field.search { flex-basis: 100%; }
  .hdr-right .updated { display: none; }
}
