/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* CRITICAL: override user-agent [hidden] which display:flex/block can beat */
[hidden] { display: none !important; }

:root {
  --navy:       #0e2840;
  --teal:       #0f7a8a;
  --teal-soft:  #e0f4f7;
  --green:      #0a7c55;
  --green-soft: #dff5ec;
  --amber:      #b45309;
  --amber-soft: #fef3c7;
  --red:        #c0392b;
  --red-soft:   #fce8e6;
  --purple-soft:#f0eaff;
  --purple:     #6b3fa0;
  --ink:        #1a2a3a;
  --sub:        #4a5f6d;
  --muted:      #7a8e9b;
  --line:       #dde5ea;
  --surface:    #f5f8fa;
  --white:      #ffffff;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 54px;
  padding: 0 24px;
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}

.hdr-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.hdr-leaf {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #f0b429;
  display: grid;
  place-items: center;
  font-size: 15px;
  flex-shrink: 0;
}

.hdr-text { display: flex; flex-direction: column; gap: 1px; }

.hdr-eyebrow {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
}

.hdr-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.hdr-end {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ro-tag {
  padding: 3px 10px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,.75);
}

.hdr-btn {
  padding: 5px 11px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 7px;
  color: #fff;
  font: 600 11px "Inter", sans-serif;
  cursor: pointer;
  transition: background .15s;
}

.hdr-btn:hover { background: rgba(255,255,255,.2); }

/* ── Tab Bar ──────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  position: sticky;
  top: 54px;
  z-index: 40;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
  text-align: left;
}

.tab.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

.tab:hover:not(.active) { color: var(--ink); }

.tab-ico { font-size: 15px; }

.tab-words { display: flex; flex-direction: column; gap: 1px; }

.tab-name {
  font-size: 12px;
  font-weight: 700;
  display: block;
}

.tab-sub {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  display: block;
  opacity: .5;
}

.tab.active .tab-sub { opacity: .75; }

/* ── Loading ──────────────────────────────────────────────────────────────── */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.loader-fill { flex: 1; }

.spin {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tab panels ───────────────────────────────────────────────────────────── */
.reg-panel { display: flex; align-items: flex-start; min-height: calc(100vh - 109px); }

/* ── Summary ──────────────────────────────────────────────────────────────── */
.sum-body {
  padding: 16px 20px 40px;
  max-width: 1160px;
  margin: 0 auto;
  width: 100%;
}

/* KPI Cards */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 960px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-link { cursor: pointer; }
.kpi-link:hover,
.kpi-link:focus-visible { border-color: var(--teal); background: var(--teal-soft); }
.kpi-link:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; }

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.kpi-num {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}

.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--teal-soft);
  display: grid;
  place-items: center;
  font-size: 13px;
  flex-shrink: 0;
}

.kpi-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.kpi.c-green  .kpi-num  { color: var(--green); }
.kpi.c-green  .kpi-icon { background: var(--green-soft); }
.kpi.c-amber  .kpi-num  { color: var(--amber); }
.kpi.c-amber  .kpi-icon { background: var(--amber-soft); }
.kpi.c-red    .kpi-num  { color: var(--red); }
.kpi.c-red    .kpi-icon { background: var(--red-soft); }
.kpi.c-teal   .kpi-num  { color: var(--teal); }
.kpi.c-teal   .kpi-icon { background: var(--teal-soft); }

/* Breakdown grid */
.bd-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

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

.bd-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
}

.bd-card-head {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--sub);
  border-bottom: 1px solid var(--line);
  background: #fafcfd;
}

.bd-list { padding: 2px 0; }

.bd-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid #f1f5f7;
  font-size: 12px;
}

.bd-row:last-child { border-bottom: 0; }

.bd-row-link { cursor: pointer; border-radius: 6px; }
.bd-row-link:hover,
.bd-row-link:focus-visible { background: var(--teal-soft); }
.bd-row-link:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; }

.bd-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.bd-cnt {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  min-width: 22px;
  text-align: right;
}

.bd-bar-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 80px;
  flex-shrink: 0;
}

.bd-bar {
  flex: 1;
  height: 4px;
  background: var(--teal-soft);
  border-radius: 99px;
  overflow: hidden;
}

.bd-fill {
  display: block;
  height: 100%;
  background: var(--teal);
  border-radius: 99px;
}

.bd-pct {
  font-size: 10px;
  font-weight: 700;
  color: var(--teal);
  min-width: 26px;
  text-align: right;
}

/* ── Register ─────────────────────────────────────────────────────────────── */
.reg-body {
  flex: 1;
  min-width: 0;
  transition: margin-right .25s ease;
}

.reg-body.panel-open { margin-right: 420px; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 7px;
  padding: 10px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 109px;
  z-index: 30;
  flex-wrap: wrap;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  cursor: text;
}

.search-ico {
  font-size: 15px;
  color: var(--muted);
  flex-shrink: 0;
  user-select: none;
}

.search-wrap input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: 0;
  padding: 7px 0;
  font: inherit;
  color: var(--ink);
  font-size: 13px;
}

.filter-bar select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface);
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}

/* Table */
.tbl-wrap {
  padding: 14px 20px 48px;
  overflow-x: auto;
}

.reg-tbl {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
}

.reg-tbl thead { background: #f8fbfc; }

.reg-tbl th {
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding: 9px 13px;
  border-bottom: 1px solid var(--line);
}

.col-no { width: 44px; text-align: center; }

.reg-tbl td {
  padding: 10px 13px;
  border-bottom: 1px solid #f1f5f7;
  font-size: 13px;
  vertical-align: middle;
}

.reg-tbl tr:last-child td { border-bottom: 0; }

.reg-tbl tbody tr {
  cursor: pointer;
  transition: background .1s;
}

.reg-tbl tbody tr:hover    { background: #eef6f8; }
.reg-tbl tbody tr.selected { background: #dff3f7; }

td.col-no { text-align: center; }

.row-num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.permit-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

/* Status pills */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.pill-active   { background: var(--green-soft);  color: var(--green); }
.pill-renewal  { background: var(--amber-soft);  color: var(--amber); }
.pill-approval { background: var(--teal-soft);   color: var(--teal); }
.pill-expired,
.pill-inactive { background: var(--red-soft);    color: var(--red); }
.pill-pending  { background: var(--purple-soft); color: var(--purple); }

/* Expiry badge */
.xb            { display: flex; flex-direction: column; gap: 1px; font-size: 12px; font-weight: 600; }
.xb em         { font-style: normal; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.xb-ok  em     { color: var(--green); }
.xb-warn em    { color: var(--amber); }
.xb-over em    { color: var(--red); }
.xb-none       { color: var(--muted); font-size: 12px; }

/* File chips */
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid rgba(15,122,138,.15);
  border-radius: 999px;
  font: 600 10px "Inter", sans-serif;
  cursor: pointer;
  margin: 2px 2px 2px 0;
  white-space: nowrap;
  transition: .12s;
}

.file-chip:hover { background: var(--teal); color: #fff; }

.reg-empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── Detail Pane ──────────────────────────────────────────────────────────── */
.d-pane {
  position: fixed;
  top: 109px;
  right: 0;
  bottom: 0;
  width: 420px;
  background: var(--white);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 28px rgba(14,40,64,.1);
  display: flex;
  flex-direction: column;
  z-index: 35;
  animation: pane-in .22s cubic-bezier(.22,.8,.4,1);
}

@keyframes pane-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

.d-close {
  position: absolute;
  top: 13px;
  right: 13px;
  width: 26px;
  height: 26px;
  border: 0;
  background: rgba(255,255,255,.15);
  color: #fff;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  z-index: 2;
  transition: background .15s;
}

.d-close:hover { background: rgba(255,255,255,.3); }

/* Pane header (colored by urgency) */
.dp-head-inner {
  padding: 18px 16px 14px;
  position: relative;
}

.dp-head-ok   { background: var(--navy); }
.dp-head-warn { background: #7a5200; }
.dp-head-over { background: #8b1f15; }
.dp-head-none { background: #3d5a6e; }

.dp-meta {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.5);
  margin-bottom: 5px;
}

.dp-title {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  line-height: 1.25;
  margin-bottom: 6px;
  padding-right: 34px;
}

.dp-loc {
  font-size: 12px;
  color: rgba(255,255,255,.65);
  margin-bottom: 10px;
}

.dp-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dp-status-row .xb    { color: rgba(255,255,255,.85); }
.dp-status-row .xb em { color: rgba(255,255,255,.6); }

/* Pane body */
.d-body { flex: 1; overflow-y: auto; }

.dp-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.dp-section:last-child { border-bottom: 0; }

.dp-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.dp-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f7;
  font-size: 13px;
}

.dp-row:last-child { border-bottom: 0; }

.dp-row-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  width: 90px;
}

.dp-row-val { text-align: right; flex: 1; }

/* File list in pane */
.dp-file-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fbfc;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: .12s;
}

.dp-file-btn:hover { background: var(--teal-soft); border-color: var(--teal); }

.dp-file-icon { font-size: 18px; flex-shrink: 0; }
.dp-file-info { flex: 1; min-width: 0; }
.dp-file-name { display: block; font-size: 12px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dp-file-meta { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }
.dp-file-arrow { color: var(--teal); font-size: 13px; flex-shrink: 0; }
.dp-file-btn:hover .dp-file-name { color: var(--teal); }
.dp-no-files { padding: 14px; text-align: center; color: var(--muted); font-size: 12px; border: 2px dashed var(--line); border-radius: 9px; }

/* ── Usage Log ────────────────────────────────────────────────────────────── */
.log-tbl { table-layout: auto; }
.log-tbl td { vertical-align: middle; padding: 10px 12px; }
.log-time { white-space: nowrap; font-size: 11px; color: var(--muted); }
.log-user { font-size: 12px; font-weight: 600; color: var(--ink); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-detail { font-size: 12px; color: var(--ink); max-width: 280px; }

.log-action-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  background: #e8f0f5;
  color: #3a5f6f;
}
.log-action-add    { background: #e6f7ef; color: #1b7c49; }
.log-action-update { background: #fff8e2; color: #7a5a00; }
.log-action-delete { background: #fde8e8; color: #c0392b; }
.log-action-signin { background: #edf2ff; color: #2c4da8; }
.log-action-signout{ background: #f0eeff; color: #5c3db8; }
.log-action-file   { background: #e8f5ff; color: #1a6fa8; }

.log-module-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--line, #e5edf0);
  color: var(--muted, #7a8e9b);
  white-space: nowrap;
}

/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
  .hdr-end, .tab-bar, .filter-bar, .file-chip, .d-close, .d-pane { display: none !important; }
  #tab-summary, #tab-register { display: block !important; }
  .reg-panel { display: block; }
}

/* Superseded permit documents.
   An auditor sees them — a replaced certificate is part of the record — but
   they must never be mistaken for the document that is current. */
.file-chip-history { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; color: #8d6419; background: var(--amber-soft, #fff4d9); border-radius: 999px; padding: 2px 7px; margin: 2px 2px 2px 0; white-space: nowrap; }
.dp-section-label-history { margin-top: 12px; color: #8d6419; }
.dp-file-btn-history { border-style: dashed; opacity: .8; }
.dp-file-btn-history .dp-file-name { color: var(--muted); text-decoration: line-through; }
