/* Agent Trust Gateway — Admin Console v3
   Professional SaaS design system. Markup contract: public/admin.html +
   markup generated by public/app.js (.pill, .stat, tables, notices). */

:root {
  color-scheme: light;

  /* Palette */
  --atg-bg: #f3f5f9;
  --atg-surface: #ffffff;
  --atg-border: #e3e8f0;
  --atg-border-strong: #c6d2e0;
  --atg-text: #101c2c;
  --atg-text-2: #42556e;
  --atg-muted: #7186a0;

  /* Brand accent */
  --atg-accent: #2563eb;
  --atg-accent-hover: #1d4ed8;
  --atg-accent-soft: #eff4ff;
  --atg-ring: rgba(37, 99, 235, 0.18);

  /* Sidebar */
  --atg-sidebar-bg: #0b1a2e;
  --atg-sidebar-bg-2: #0e2439;
  --atg-sidebar-text: #b9cadd;
  --atg-sidebar-dim: #5f7a99;

  /* Status tints */
  --atg-red-bg: #fdecec;
  --atg-red-text: #a11f1f;
  --atg-red-border: #f3c8c8;
  --atg-amber-bg: #fdf0d3;
  --atg-amber-text: #8f5b07;
  --atg-amber-border: #eedcae;
  --atg-green-bg: #e4f3ea;
  --atg-green-text: #146c39;
  --atg-green-border: #c2e2cd;

  --atg-code-bg: #0c1728;
  --atg-radius: 14px;
  --atg-shadow: 0 1px 2px rgba(16, 28, 44, 0.05), 0 1px 3px rgba(16, 28, 44, 0.04);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--atg-text);
  background: var(--atg-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

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

main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 28px 56px;
}

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

.sidebar {
  flex: 0 0 248px;
  width: 248px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--atg-sidebar-bg) 0%, var(--atg-sidebar-bg-2) 100%);
  color: var(--atg-sidebar-text);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 20px 14px;
}

.brand-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2f6bff, #1d4ed8);
  color: #fff;
  box-shadow: 0 4px 12px rgba(47, 107, 255, 0.35);
}

.brand-text { min-width: 0; }

.brand-name {
  display: block;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.25;
  color: #fff;
  white-space: nowrap;
}

.brand-sub {
  display: block;
  margin-top: 1px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #7e97b1;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 12px 12px;
}

.nav a {
  padding: 8px 11px;
  border-radius: 8px;
  color: var(--atg-sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.13s ease, color 0.13s ease;
}

.nav a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }

.nav a:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px rgba(125, 175, 255, 0.8);
  color: #fff;
}

.nav-group {
  margin: 16px 11px 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--atg-sidebar-dim);
}

.sidebar-foot {
  margin: auto 0 0;
  padding: 16px 20px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 12px;
  line-height: 1.55;
  color: #6d87a1;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 12px 28px;
  background: rgba(255, 255, 255, 0.88);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--atg-border);
}

.topbar-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar .bar input[type="password"] { width: 210px; }
.topbar .bar select { min-width: 190px; }

/* ---------- Generic bars / rows ---------- */

.bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
section .bar { margin-bottom: 14px; }

/* ---------- Sections ---------- */

section {
  background: var(--atg-surface);
  border: 1px solid var(--atg-border);
  border-radius: var(--atg-radius);
  box-shadow: var(--atg-shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
  scroll-margin-top: 92px;
}

.section-head { margin-bottom: 14px; }

.section-head h2 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-sub {
  margin: 4px 0 0;
  max-width: 72ch;
  font-size: 13px;
  color: var(--atg-muted);
}

.section-note {
  font-size: 12px;
  font-weight: 500;
  color: var(--atg-muted);
}

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

button {
  appearance: none;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  color: #fff;
  background: var(--atg-accent);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 15px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

button:hover { background: var(--atg-accent-hover); }

button.secondary {
  background: var(--atg-surface);
  color: var(--atg-text-2);
  border-color: var(--atg-border-strong);
}

button.secondary:hover { background: #f0f4f9; color: var(--atg-text); }

button.danger { background: #d92d20; }
button.danger:hover { background: #b42318; }

button:disabled { opacity: 0.55; cursor: not-allowed; }

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--atg-ring);
}

td button { padding: 5px 11px; font-size: 12.5px; }

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

input,
select,
textarea {
  font: inherit;
  font-size: 14px;
  color: var(--atg-text);
  background: var(--atg-surface);
  border: 1px solid var(--atg-border-strong);
  border-radius: 8px;
  padding: 8px 11px;
}

input::placeholder { color: #9db0c4; }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--atg-accent);
  box-shadow: 0 0 0 3px var(--atg-ring);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: 4px;
  accent-color: var(--atg-accent);
  flex: 0 0 auto;
}

input[type="checkbox"]:focus { box-shadow: 0 0 0 3px var(--atg-ring); }

/* ---------- Labeled fields & form layouts ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--atg-text-2);
}

.field input,
.field select { width: 100%; }

.inline-field { flex: 0 1 230px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--atg-text-2);
  cursor: pointer;
}

form.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 14px;
  align-items: end;
  margin: 12px 0 4px;
}

form.grid .check { padding-bottom: 9px; }

form.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  margin: 14px 0 2px;
}

form.inline .field { flex: 1 1 180px; }

/* ---------- Details / summary ---------- */

details { margin-top: 16px; }

section > details {
  border-top: 1px dashed var(--atg-border);
  padding-top: 14px;
}

summary { cursor: pointer; }

summary::-webkit-details-marker { display: none; }

section > details > summary {
  display: inline-flex;
  align-items: center;
  list-style: none;
  padding: 7px 13px;
  border: 1px solid var(--atg-border-strong);
  border-radius: 8px;
  background: var(--atg-surface);
  color: var(--atg-accent);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}

section > details > summary::before { content: "+"; margin-right: 7px; font-weight: 700; }

section > details[open ] > summary::before { content: "–"; }

section > details > summary:hover {
  background: var(--atg-accent-soft);
  border-color: var(--atg-accent);
}

section > details > summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--atg-ring);
}

/* In-table payload drill-downs (generated by app.js) */
td details { margin: 0; }

td details > summary {
  list-style: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--atg-accent);
}

td details > summary:hover { text-decoration: underline; }

/* ---------- Tables ---------- */

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--atg-border);
  background: #f8fafc;
  color: var(--atg-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid #e9eef5;
  vertical-align: top;
}

tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: #f7fafd; }
tbody tr:last-child td { border-bottom: none; }

td strong { font-weight: 650; }

/* ---------- Pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border: 1px solid rgba(16, 28, 44, 0.07);
  border-radius: 999px;
  background: #edf1f6;
  color: var(--atg-text-2);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
  flex: 0 0 auto;
}

.pill.high, .pill.critical,
.pill.denied, .pill.deny, .pill.failed,
.pill.suspended, .pill.rejected, .pill.expired {
  background: var(--atg-red-bg);
  color: var(--atg-red-text);
  border-color: var(--atg-red-border);
}

.pill.medium,
.pill.pending_approval, .pill.approval_required, .pill.pending {
  background: var(--atg-amber-bg);
  color: var(--atg-amber-text);
  border-color: var(--atg-amber-border);
}

.pill.low,
.pill.executed, .pill.allow, .pill.active,
.pill.connected, .pill.delivered, .pill.approved {
  background: var(--atg-green-bg);
  color: var(--atg-green-text);
  border-color: var(--atg-green-border);
}

/* ---------- Stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat {
  padding: 14px 16px;
  border: 1px solid var(--atg-border);
  border-radius: 12px;
  background: linear-gradient(180deg, #fbfcfe, #f4f7fb);
}

.stat .num {
  font-size: 25px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--atg-text);
}

.stat .label {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--atg-muted);
}

.stat.alert { background: #fdf1f1; border-color: var(--atg-red-border); }
.stat.alert .num { color: var(--atg-red-text); }
.stat.alert .label { color: #c05a5a; }

/* ---------- Notice ---------- */

.notice {
  margin-bottom: 18px;
  padding: 13px 16px;
  border: 1px solid var(--atg-amber-border);
  border-left: 4px solid #e8a13a;
  border-radius: 10px;
  background: #fffaf0;
  box-shadow: var(--atg-shadow);
  font-size: 14px;
  word-break: break-word;
}

.notice button { float: right; margin-left: 12px; }

/* ---------- Text helpers ---------- */

.muted { color: var(--atg-muted); font-size: 13px; }
.muted-light { color: var(--atg-muted); font-size: 13px; }

.flag { color: #b42318; font-size: 12px; font-weight: 600; }

.hidden { display: none; }

code {
  padding: 1px 6px;
  border-radius: 5px;
  background: #edf1f6;
  color: #33475e;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

pre {
  max-height: 280px;
  overflow: auto;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--atg-code-bg);
  color: #d5e3f2;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

pre code { padding: 0; background: transparent; color: inherit; }

#simResults { margin-top: 14px; overflow-x: auto; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: static;
    width: 100%;
    flex: none;
    height: auto;
    overflow: visible;
  }

  .brand { padding: 14px 16px 6px; }

  .nav {
    flex-direction: row;
    gap: 4px;
    padding: 6px 12px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-group, .sidebar-foot { display: none; }

  .topbar { padding: 10px 14px; }

  .topbar .bar { flex: 1 1 100%; }

  .topbar .bar input[type="password"],
  .topbar .bar select { flex: 1 1 150px; width: auto; min-width: 0; }

  main { padding: 16px 14px 40px; }

  section { padding: 18px 16px; scroll-margin-top: 128px; }

  .stats { grid-template-columns: repeat(2, 1fr); }

  button { padding: 9px 14px; }
}
