/* ============================================================
   Sectorial Terminal // THEME SYSTEM (SA-WEB-001)
   Flat Imperial design: Inter, no radius, light/dark variables.
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; border-radius: 0 !important; }

:root {
  --body-bg: #f4f2ed;
  --content-bg: #ffffff;
  --border-light: #d0ccc4;
  --border: #ccc;
  --border-table: #e8e4dc;
  --border-heavy: #2a2a2a;
  --text: #1e1e1e;
  --text-muted: #666;
  --text-dim: #999;
  --red: #6d2121;
  --red-bright: #8a2a2a;
  --green: #10b981;
  --amber: #f59e0b;
  --hover-bg: #f0ece4;
  --nav-hover: #edeae4;
  --label: #444;
  --input-bg: #ffffff;
  --shadow: rgba(0,0,0,0.04);
  --sidebar-width: 260px;
}

body.dark {
  --body-bg: #0b0d10;
  --content-bg: #1a1a1a;
  --border-light: #333;
  --border: #444;
  --border-table: #333;
  --border-heavy: #666;
  --text: #e0e0e0;
  --text-muted: #888;
  --text-dim: #666;
  --red: #8a2a2a;
  --red-bright: #aa3a3a;
  --hover-bg: #222;
  --nav-hover: #2a2a2a;
  --label: #ccc;
  --input-bg: #0b0d10;
  --shadow: rgba(0,0,0,0.3);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  background: var(--body-bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .3s, color .3s;
}

a { color: inherit; }

/* ---------- Typography helpers ---------- */
.eyebrow { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); font-weight: 700; }
h1, h2, h3 { text-transform: uppercase; letter-spacing: 0.06em; }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }

/* ---------- Public layout ---------- */
.pub-wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.pub-header {
  border-bottom: 2px solid var(--border-heavy);
  background: var(--content-bg);
}
.pub-header-inner {
  max-width: 1100px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 64px; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 1.15rem; text-decoration: none; }
.brand .sub { font-weight: 300; color: var(--text-muted); font-size: 0.6rem; letter-spacing: 0.08em; margin-left: 8px; }
.pub-nav { display: flex; gap: 2px; flex-wrap: wrap; }
.pub-nav a {
  text-decoration: none; color: var(--text-muted); font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 12px;
  border-bottom: 2px solid transparent; min-height: 44px; display: inline-flex; align-items: center;
}
.pub-nav a:hover, .pub-nav a.active { color: var(--text); border-bottom-color: var(--red); background: var(--hover-bg); }

.pub-footer {
  border-top: 1px solid var(--border-light); margin-top: 48px; padding: 20px 0;
  font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
}
.pub-footer .pub-wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Hero ---------- */
.hero { padding: 56px 0 40px; border-bottom: 1px solid var(--border-light); background: var(--content-bg); }
.hero h1 { font-size: 2rem; letter-spacing: 0.14em; }
.hero .hero-sub { color: var(--text-muted); max-width: 720px; margin-top: 10px; font-size: 0.95rem; }
.hero .hero-rule { width: 64px; border-top: 3px solid var(--red); margin-bottom: 16px; }

/* ---------- Cards / grids ---------- */
.section { padding: 32px 0; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--content-bg); border: 1px solid var(--border); padding: 18px;
}
.card h3 { font-size: 0.85rem; margin-bottom: 6px; }
.card p { font-size: 0.85rem; color: var(--text-muted); }
.card.link-card { display: block; text-decoration: none; border-left: 2px solid transparent; transition: 0.15s; }
.card.link-card:hover { border-left-color: var(--red); background: var(--hover-bg); }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi-card { background: var(--content-bg); border: 1px solid var(--border); padding: 14px 16px; min-height: 84px; }
.kpi-card .kpi-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: 700; margin-top: 2px; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.kpi-card .kpi-sub { font-size: 0.62rem; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--label); margin-bottom: 4px; font-weight: 600; }
input, textarea, select {
  width: 100%; padding: 9px; margin-bottom: 14px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
  font-family: inherit; font-size: 0.85rem; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--red); }
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"] { width: auto; margin: 0 8px 0 0; vertical-align: middle; }
.check-row { display: flex; align-items: center; gap: 4px; margin-bottom: 14px; font-size: 0.8rem; }
.check-row label { margin: 0; }

button, .btn {
  background: none; border: 1px solid var(--border-heavy);
  padding: 10px 24px; font-family: inherit; font-size: 0.7rem;
  font-weight: 600; cursor: pointer; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text); transition: 0.1s;
  text-decoration: none; display: inline-block; min-height: 40px;
}
button:hover, .btn:hover { background: var(--hover-bg); }
button.primary, .btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--red-bright); }
button.small, .btn.small { padding: 4px 12px; min-height: 32px; font-size: 0.62rem; }
button.approve { border-color: var(--green); color: var(--green); }
button.approve:hover { background: var(--green); color: #fff; }
button.deny { border-color: var(--red); color: var(--red); }
button.deny:hover { background: var(--red); color: #fff; }
button.block { width: 100%; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.msg { padding: 12px; margin-top: 12px; font-size: 0.85rem; border: 1px solid var(--border); }
.msg.success { border-color: var(--green); color: var(--green); }
.msg.error { border-color: var(--red); color: var(--red); }
.key-reveal {
  font-family: ui-monospace, monospace; background: var(--body-bg); border: 1px dashed var(--red);
  padding: 12px; margin: 10px 0; word-break: break-all; font-size: 0.9rem;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--content-bg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--border-table); text-align: left; }
th { color: var(--text); font-weight: 700; font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 2px solid var(--border-heavy); white-space: nowrap; }
tbody tr:hover { background: var(--hover-bg); }
td .status-active { color: var(--green); font-weight: 600; }
td .status-loa, .status-pending { color: var(--amber); font-weight: 600; }
td .status-bad { color: var(--red); font-weight: 600; }

.tag {
  font-size: 0.55rem; text-transform: uppercase; color: var(--text-muted); background: var(--body-bg);
  padding: 0.1rem 0.5rem; border: 1px solid var(--border); letter-spacing: 1px; font-weight: 700; white-space: nowrap;
}
.badge { background: var(--red); color: #fff; font-size: 0.55rem; padding: 0.05rem 0.5rem; font-weight: 700; letter-spacing: 1px; }

/* ---------- Admin layout ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; max-width: 1400px; margin: 0 auto; width: 100%; background: var(--content-bg); border-left: 1px solid var(--border-light); border-right: 1px solid var(--border-light); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: var(--content-bg); border-bottom: 2px solid var(--border-heavy); flex-shrink: 0; min-height: 64px; gap: 12px; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; flex-wrap: wrap; }
.hamburger { display: none; background: none; border: none; color: var(--text); font-size: 1.5rem; cursor: pointer; padding: 4px 8px; min-height: 44px; font-family: inherit; }
.user-badge { display: flex; align-items: center; gap: 8px; }
.user-badge .avatar { width: 32px; height: 32px; background: var(--border); display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); font-weight: 700; font-size: 0.75rem; text-transform: uppercase; }
.user-badge .uname { font-size: 0.8rem; font-weight: 600; }
.user-badge .rank { font-size: 0.55rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.theme-btn { background: none; border: 1px solid var(--border); padding: 2px 10px; font-size: 0.6rem; font-weight: 600; cursor: pointer; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text); min-height: 32px; }
.theme-btn:hover { background: var(--hover-bg); }

.main-layout { display: flex; flex: 1; }
.sidebar { width: var(--sidebar-width); background: var(--content-bg); border-right: 1px solid var(--border-light); flex-shrink: 0; padding: 8px 0; }
.sidebar-section { padding: 4px 0; border-bottom: 1px solid var(--border-light); }
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section-title { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 0.4rem 16px; font-weight: 700; }
.sidebar-item {
  display: flex; align-items: center; gap: 10px; padding: 0.4rem 16px; cursor: pointer;
  color: var(--text-muted); font-size: 0.72rem; transition: 0.15s; border-left: 2px solid transparent;
  min-height: 42px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; text-decoration: none;
}
.sidebar-item:hover, .sidebar-item.active { background: var(--hover-bg); color: var(--text); border-left-color: var(--red); }
.sidebar-item .badge { margin-left: auto; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,0.4); }

.content { flex: 1; padding: 24px 28px; background: var(--body-bg); min-width: 0; }
.content-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.content-header h2 { font-weight: 700; font-size: 1.15rem; }
.breadcrumb { font-size: 0.62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.breadcrumb span { color: var(--text); }

.panel { background: var(--content-bg); border: 1px solid var(--border); padding: 16px; margin-bottom: 16px; }
.panel .panel-title { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 700; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filter-row > div { min-width: 140px; }
.filter-row input, .filter-row select { margin-bottom: 0; }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--content-bg); border: 1px solid var(--border); padding: 12px 24px; color: var(--text); font-size: 0.85rem; border-left: 3px solid var(--red); box-shadow: 0 2px 12px var(--shadow); min-width: 220px; max-width: 380px; animation: slideUp 0.3s ease-out; font-weight: 500; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Modal ---------- */
.modal-backdrop { display: none; position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,0.5); align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--content-bg); border: 1px solid var(--border-heavy); padding: 24px; max-width: 560px; width: 100%; }
.modal h3 { font-size: 0.9rem; margin-bottom: 14px; }

/* ---------- Identity card ---------- */
.id-card {
  background: var(--content-bg); border: 2px solid var(--border-heavy);
  max-width: 460px; font-size: 0.8rem;
}
.id-card .idc-head {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 2px solid var(--red); padding: 12px 16px;
}
.id-card .idc-head .idc-title { font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.85rem; }
.id-card .idc-head .idc-sub { font-size: 0.55rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.id-card .idc-type { font-size: 0.55rem; background: var(--red); color: #fff; padding: 2px 8px; letter-spacing: 1px; font-weight: 700; text-transform: uppercase; }
.id-card .idc-body { display: flex; gap: 16px; padding: 16px; }
.id-card .idc-photo {
  width: 96px; height: 96px; border: 1px solid var(--border); background: var(--body-bg);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-weight: 700; font-size: 1.6rem; color: var(--text-muted); overflow: hidden;
}
.id-card .idc-photo img { width: 100%; height: 100%; object-fit: cover; }
.id-card .idc-fields { flex: 1; min-width: 0; }
.id-card .idc-fields .f { display: flex; gap: 8px; margin-bottom: 2px; font-size: 0.72rem; }
.id-card .idc-fields .f .k { width: 64px; flex-shrink: 0; color: var(--text-muted); text-transform: uppercase; font-size: 0.55rem; letter-spacing: 0.06em; font-weight: 700; padding-top: 2px; }
.id-card .idc-fields .f .v { font-weight: 600; word-break: break-word; }
.id-card .idc-iid { font-family: ui-monospace, monospace; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em; color: var(--red); }
.id-card .idc-verify { border-top: 1px solid var(--border-table); padding: 10px 16px; display: grid; gap: 6px; }
.id-card .idc-verify .vf-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.id-card .idc-verify .vf-label { font-size: 0.55rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; width: 96px; flex-shrink: 0; }
.id-card .idc-verify .vf-link { font-family: ui-monospace, monospace; font-size: 0.68rem; color: var(--red); font-weight: 600; word-break: break-all; }
.id-card .idc-verify .vf-code { font-family: ui-monospace, monospace; font-size: 0.95rem; font-weight: 700; letter-spacing: 0.12em; }
.id-card .idc-verify .vf-hint { font-size: 0.58rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.id-card .idc-verify .vf-copy { padding: 2px 8px; min-height: 26px; font-size: 0.55rem; }
.id-card .idc-foot { border-top: 2px solid var(--border-heavy); padding: 8px 16px; font-size: 0.58rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.id-card.revoked { position: relative; }
.id-card.revoked::after {
  content: attr(data-stamp); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 800; color: var(--red); text-transform: uppercase; letter-spacing: 0.2em;
  transform: rotate(-12deg); pointer-events: none; opacity: 0.55;
}

/* ---------- Chain of command ---------- */
.coc-node { border: 1px solid var(--border); background: var(--content-bg); padding: 10px 16px; }
.coc-node .coc-role { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.coc-node .coc-desc { font-size: 0.75rem; color: var(--text-muted); }
.coc-level { margin-left: 24px; border-left: 2px solid var(--red); padding-left: 16px; display: grid; gap: 8px; margin-top: 8px; }

/* ---------- Print (identity cards / dossiers) ---------- */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .no-print, .pub-header, .pub-footer, .topbar, .sidebar, .toast-container { display: none !important; }
  .content { padding: 0; background: #fff; }
  .id-card { border-color: #000; box-shadow: none; page-break-inside: avoid; }
  .panel { border-color: #999; page-break-inside: avoid; }
}

/* ---------- Responsive ---------- */
/* ---------- Skeleton loader (#16) ---------- */
@keyframes skeleton-pulse {
  0% { opacity: 1; }
  50% { opacity: 0.35; }
  100% { opacity: 1; }
}
.skeleton-box {
  display: inline-block; height: 14px; background: var(--border-light);
  animation: skeleton-pulse 1.8s ease-in-out infinite;
}

/* ---------- Notification center (#8) ---------- */
.notif-bell {
  position: relative; cursor: pointer; padding: 6px 8px; display: inline-flex; align-items: center;
  color: var(--text-muted);
}
.notif-bell:hover { color: var(--text); }
.notif-count {
  position: absolute; top: 0; right: 0; display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; background: var(--red); color: #fff; font-size: 0.5rem; font-weight: 700;
  padding: 0 4px; border-radius: 0 !important;
}
.notif-dropdown {
  position: absolute; top: 100%; right: 0; width: 320px; max-height: 400px; overflow-y: auto;
  background: var(--content-bg); border: 1px solid var(--border); z-index: 200;
  box-shadow: 0 4px 12px var(--shadow);
}
.notif-dropdown .notif-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 0.72rem; }
.notif-item {
  padding: 10px 12px; border-bottom: 1px solid var(--border-table); cursor: pointer; position: relative;
  transition: background 0.15s;
}
.notif-item:hover { background: var(--hover-bg); }
.notif-item.unread { border-left: 3px solid var(--red); }
.notif-item .notif-title { font-size: 0.75rem; font-weight: 600; }
.notif-item .notif-msg { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }
.notif-item .notif-time { font-size: 0.55rem; color: var(--text-dim); margin-top: 4px; }
.notif-item .notif-dot {
  position: absolute; top: 10px; right: 10px; width: 6px; height: 6px;
  background: var(--red); border-radius: 0 !important;
}

/* ---------- Typeahead / Autocomplete (#5) ---------- */
.typeahead-dropdown { border: 1px solid var(--border); }
.typeahead-item {
  padding: 6px 10px; cursor: pointer; font-size: 0.72rem; border-bottom: 1px solid var(--border-table);
}
.typeahead-item:hover { background: var(--hover-bg); }
.typeahead-item:last-child { border-bottom: none; }

/* ---------- Error boundary (#17) ---------- */
.error-boundary {
  text-align: center; padding: 60px 20px; max-width: 500px; margin: 0 auto;
}
.error-boundary .error-boundary-icon { font-size: 2.5rem; margin-bottom: 12px; color: var(--red); }

/* ---------- Collapsible sidebar sections (#11) ---------- */
.sidebar-section.collapsed .sidebar-section-content { display: none !important; }
.sidebar-section-header { cursor: pointer; user-select: none; }
.sidebar-section-header::after {
  content: '\25BC'; float: right; font-size: 0.5rem; transition: transform 0.2s; opacity: 0.4;
}
.sidebar-section.collapsed .sidebar-section-header::after { transform: rotate(-90deg); }

/* ---------- Cols dropdown (#12) ---------- */
.cols-toggle { font-size: 0.62rem !important; }
.cols-item:hover { background: var(--hover-bg); }
.cols-item input[type='checkbox'] { width: auto; margin: 0; }

@media (max-width: 1100px) {
  .kpi-grid, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; transform: translateX(-100%); transition: transform 0.3s ease; border-right: 1px solid var(--border); overflow-y: auto; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .hamburger { display: inline-block; }
  .content { padding: 16px; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card .kpi-value { font-size: 1.4rem; }
  .hero h1 { font-size: 1.4rem; }
  .id-card .idc-body { flex-direction: column; }
}
