/* ---------------------------------------------------------------------
   Access Governance Portal — base styles.
   Deliberately framework-free: a small, legible design system instead
   of a general-purpose CSS toolkit, so the whole UI stays inspectable
   in one file per the "lightweight, easy to troubleshoot" requirement.
   ------------------------------------------------------------------ */

:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-border: #dde3e9;
  --ink: #1b2430;
  --ink-soft: #55606c;
  --ink-faint: #8894a0;
  --accent: #2a6f77;
  --accent-soft: #e4f0f1;
  --line: #e2e7ec;

  --ok: #2f7d4f;
  --ok-bg: #e6f4ea;
  --warn: #9a6a10;
  --warn-bg: #fbf1de;
  --danger: #b23b3b;
  --danger-bg: #fbe9e9;
  --neutral: #55606c;
  --neutral-bg: #eceff2;

  --radius: 8px;
  --font-ui: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

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

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

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* --- Sidebar ---------------------------------------------------- */

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 18px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
}

.brand-name {
  font-weight: 600;
  font-size: 14.5px;
  color: var(--ink);
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.nav-sub { padding-left: 18px; font-weight: 400; }

.nav-group { margin-top: 14px; }

.nav-heading {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  padding: 4px 10px;
  letter-spacing: 0.03em;
}

.sidebar-footer {
  padding: 12px 6px 0;
  border-top: 1px solid var(--line);
  margin-top: 14px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-toggle-input { display: none; }
.nav-toggle-btn { display: none; }

/* --- Topbar ------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.global-search { flex: 1; max-width: 480px; }

.global-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
}

.global-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
}

.topbar-spacer { flex: 1; }

/* --- Content / layout primitives ---------------------------------- */

.content { padding: 28px; max-width: 1180px; }

.page-header { margin-bottom: 22px; }
.page-header h1 { font-size: 21px; margin: 0 0 4px; font-weight: 650; }
.page-header p { margin: 0; color: var(--ink-soft); font-size: 14px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-faint);
  text-transform: none;
  margin: 0 0 10px;
}

.stat-value { font-size: 26px; font-weight: 650; line-height: 1.1; }
.stat-label { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }

.kv { display: flex; flex-direction: column; gap: 9px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.kv-row .k { color: var(--ink-soft); }
.kv-row .v { font-weight: 550; text-align: right; }
.kv-row .v.mono { font-family: var(--font-mono); font-weight: 400; font-size: 13px; }

/* --- Status badges -------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
}

.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }
.badge-dev { background: var(--warn-bg); color: var(--warn); }
.badge-dryrun { background: var(--accent-soft); color: var(--accent); }

/* --- Buttons -------------------------------------------------------- */

button, .btn-primary, .btn-secondary {
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #235a61; }

.btn-secondary {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--panel-border);
}
.btn-secondary:hover { background: var(--bg); }
.btn-secondary:disabled, .btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--neutral-bg);
  padding: 1px 5px;
  border-radius: 4px;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  color: var(--ink-faint);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: none;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table tbody tr:hover { background: var(--bg); }

/* --- Tabs (pure CSS, radio/label pattern — no JS) --------------------- */

.tabs { margin-top: 4px; }

.tab-input { display: none; }

.tab-labels {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tab-label {
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

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

.tab-panel { display: none; }

#tab-1:checked ~ .tab-labels label[for="tab-1"],
#tab-2:checked ~ .tab-labels label[for="tab-2"],
#tab-3:checked ~ .tab-labels label[for="tab-3"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

#tab-1:checked ~ .tab-panels #panel-1,
#tab-2:checked ~ .tab-panels #panel-2,
#tab-3:checked ~ .tab-panels #panel-3 {
  display: block;
}

/* --- Detail page header (User View / Group View) ---------------------- */

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}

.detail-header h1 { margin: 0 0 4px; font-size: 22px; }
.detail-header .subtitle { color: var(--ink-soft); font-size: 13.5px; }
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pill-list a.pill, .pill-list span.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--neutral-bg);
  color: var(--ink);
  font-size: 12.5px;
  text-decoration: none;
}
.pill-list a.pill:hover { background: var(--accent-soft); color: var(--accent); }
.pill-list .pill.inherited { border: 1px dashed var(--panel-border); background: transparent; }

.search-form { display: flex; gap: 8px; margin-bottom: 18px; max-width: 480px; }
.search-form input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  font-size: 14px;
}

/* --- Empty / loading states ------------------------------------------ */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
}
.empty-state .empty-title { font-weight: 600; color: var(--ink); margin-bottom: 6px; }

.htmx-indicator { opacity: 0; transition: opacity 120ms ease; }
.htmx-request .htmx-indicator { opacity: 1; }

/* --- Responsive nav (mobile) ----------------------------------------- */

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

  .nav-toggle-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    position: fixed;
    top: 12px;
    left: 14px;
    z-index: 20;
    width: 36px;
    height: 36px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 7px;
    cursor: pointer;
  }
  .nav-toggle-btn span {
    display: block;
    width: 16px;
    height: 2px;
    background: var(--ink);
    margin: 0 auto;
  }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    width: 240px;
    z-index: 15;
    transition: left 160ms ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
  }

  .nav-toggle-input:checked ~ .sidebar {
    left: 0;
    box-shadow: 2px 0 18px rgba(0,0,0,0.15);
  }

  .topbar { padding-left: 58px; }
  .content { padding: 20px 16px; }
}
