/* CF1 Self Storage — admin dashboard styles
   Reuses the brand palette from styles.css but is self-contained so admin
   pages don't pull the public marketing CSS. */

:root {
  --orange: #f6821f;
  --orange-dark: #d96a0d;
  --navy: #003682;
  --navy-dark: #00204f;
  --ink: #1d1d1f;
  --ink-soft: #4a4a55;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--navy);
  text-decoration: none;
}

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

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 12px;
  color: var(--ink-soft);
}

.subtitle {
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 13px;
}

/* ===== Top nav ===== */

.admin-nav {
  background: var(--navy-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-md);
}

.admin-nav__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.admin-nav__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

.admin-nav__brand:hover {
  color: #fff;
  text-decoration: none;
}

.admin-nav__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--orange);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  border-radius: 5px;
}

.admin-nav__links {
  display: flex;
  gap: 4px;
  margin-left: 16px;
}

.admin-nav__links a {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 500;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.admin-nav__links a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.admin-nav__links a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.admin-nav__ext {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 18px;
}

.admin-nav__site {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  white-space: nowrap;
}
.admin-nav__ext .admin-nav__site {
  margin-left: 0;
}

.admin-nav__site:hover {
  color: var(--orange);
  text-decoration: none;
}

/* ===== Main ===== */

.admin-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ===== KPIs ===== */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.kpi__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 600;
}

.kpi__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* ===== Panels ===== */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel__header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.panel__hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ===== Tables ===== */

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

.table thead th {
  text-align: left;
  padding: 10px 12px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}

.table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: #fafbfc;
}

.table--dense tbody td {
  padding: 6px 10px;
  font-size: 12px;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table .row--success td:nth-child(2) {
  color: var(--success);
  font-weight: 700;
}

.table .row--failure {
  background: #fef2f2;
}

.table .row--failure td:nth-child(2) {
  color: var(--error);
  font-weight: 700;
}

.table .row--blocked {
  background: #fff7ed;
}

.table .row--blocked td:nth-child(2) {
  color: var(--warning);
  font-weight: 700;
}

.table code.eph {
  font-size: 11px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.empty {
  padding: 32px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

/* ===== Active filter chips ===== */

.active-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.active-filters__label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--orange-dark);
  margin-right: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.chip:hover {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  text-decoration: none;
}

.chip:hover .chip__val {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

.chip__key {
  font-weight: 600;
  color: var(--ink-soft);
}

.chip:hover .chip__key {
  color: rgba(255, 255, 255, 0.92);
}

.chip__val {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--ink);
}

.chip__x {
  font-size: 14px;
  font-weight: 700;
  margin-left: 2px;
  line-height: 1;
}

.chip--clear {
  background: transparent;
  border: none;
  color: var(--orange-dark);
  font-weight: 600;
  text-decoration: underline;
  padding-left: 6px;
}

.chip--clear:hover {
  background: transparent;
  color: var(--ink);
  border: none;
}

/* ===== Clickable rows + view link ===== */

.table--clickable tbody tr.row-clickable {
  cursor: pointer;
}

.table--clickable tbody tr.row-clickable:hover {
  background: #fff8ec;
}

.table--clickable tbody tr.row-clickable:hover .view-link {
  color: var(--orange-dark);
  text-decoration: underline;
}

.row-id {
  font-weight: 600;
}

.view-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* ===== Filters ===== */

.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.filters input[type="text"],
.filters input:not([type]),
.filters select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  min-width: 180px;
}

.filters input:focus,
.filters select:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(246, 130, 31, 0.25);
}

.filters .checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.filters button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
}

.filters button:hover {
  background: var(--orange-dark);
}

.filters .reset {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 8px 4px;
}

/* ===== Detail dl ===== */

.kv {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 6px 16px;
  padding: 16px 18px;
  margin: 0;
  font-size: 13px;
}

.kv dt {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kv dd {
  margin: 0;
  color: var(--ink);
  word-break: break-all;
}

.kv dd code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ===== JSON pre ===== */

pre.json {
  margin: 0;
  padding: 16px 18px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  background: #0b1220;
  color: #e3e7ef;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 360px;
  overflow: auto;
}

/* ===== Buttons ===== */

.btn-link {
  background: none;
  border: none;
  color: var(--error);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.btn-link:hover {
  color: #b91c1c;
}

form.inline {
  display: inline;
  margin: 0;
}

/* ===== Mobile ===== */

@media (max-width: 720px) {
  .admin-nav__inner {
    flex-wrap: wrap;
    gap: 12px;
  }
  .admin-nav__site {
    display: none;
  }
  .admin-main {
    padding: 16px;
  }
  .kv {
    grid-template-columns: 1fr;
  }
  .kv dt {
    margin-top: 8px;
  }
  .table--dense {
    display: block;
    overflow-x: auto;
  }
}

/* ===== Chat transcript ===== */

.chat-transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  background: var(--bg);
  border-radius: 8px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.msg--user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

.msg__role {
  font-weight: 700;
}

.msg__meta {
  font-weight: 400;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: none;
  letter-spacing: 0;
}

.msg__body {
  white-space: pre-wrap;
}

/* ===== Guardrail flag pills ===== */

.flag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
  vertical-align: middle;
  border: 1px solid transparent;
  white-space: nowrap;
}

.flag code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 4px;
  border-radius: 3px;
}

.flag--flag {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.flag--block {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

.flag__dir {
  font-size: 9px;
  font-weight: 700;
  opacity: 0.55;
  background: rgba(0, 0, 0, 0.06);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 2px;
}

.flags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

/* ===== /admin/security page ===== */

.kpi--warn {
  border-left: 3px solid var(--warning);
}
.kpi--bad {
  border-left: 3px solid var(--error);
}
.kpi--info {
  border-left: 3px solid var(--navy);
}

.kpi__sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}

.kpi__sub a {
  color: var(--navy);
  text-decoration: underline;
}

.layout-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout-2col {
    grid-template-columns: 1fr;
  }
}

.panel--narrow {
  padding: 16px;
}

.event-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px;
}

.event {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.event:hover {
  border-color: var(--orange);
  transform: translateY(-1px);
}

.event__header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.event__ts {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.event__session code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

.event__body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin: 6px 0;
}

.event__label {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-right: 6px;
  min-width: 36px;
}

.event__user,
.event__asst {
  font-size: 13px;
  line-height: 1.45;
}

.event__user {
  color: var(--ink);
}

.event__asst {
  color: var(--ink-soft);
}

.event__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 11px;
}

.event__logid {
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.event__view {
  color: var(--navy);
  font-weight: 600;
}

/* Category breakdown bars */
.cat-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px 28px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.cat-row__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-row__label code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  margin-right: 4px;
}

.cat-row__bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.cat-row__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--orange) 0%, var(--orange-dark) 100%);
  border-radius: 4px;
}

.cat-row__n {
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  color: var(--ink);
}

/* Active rules dl */
.rules {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
}

.rules dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--navy);
  margin-bottom: 0;
}

.rules dd {
  margin: 0 0 6px 0;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.rules dd code {
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

/* Drill-down links */
.links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.links li a {
  display: block;
  font-size: 13px;
  padding: 6px 0;
  color: var(--navy);
}

/* ===== Inline flag display on chat messages + chats list ===== */

.row--flagged {
  background: linear-gradient(90deg, rgba(254, 243, 199, 0.4) 0%, transparent 30%);
}

.msg__flags {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.msg--flagged.msg--assistant {
  border-color: #fde68a;
  background: #fffbeb;
}

.msg__logid {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 4px;
  border-radius: 3px;
}
