/* Malintent Detector — customer console.

   The high-fidelity pass over UX Design/wireframes: it keeps every element, label
   and state the wireframes specify and adds the visual system they hand off — a
   four-step type scale, a neutral palette with one accent for primary actions and
   one for warnings, and the responsive rules for the shell.

   The palette is the product's: the editorial cream/ink/rust of the marketing site
   (site/styles.css), so a customer crossing from the site into the console stays in
   one product. The console inverts the emphasis — a dark sidebar against a cream
   canvas — because the shell is furniture and the data is the subject. */

:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --panel: #ebe7df;
  --ink: #1c1a17;
  --muted: #4a4640;
  --muted-2: #7a756c;
  --rule: #d8d2c6;
  --rust: #b3492b;
  --rust-soft: #f3e2db;
  --amber: #8a6415;
  --amber-soft: #f7ecd4;
  --danger: #9e2b1e;
  --danger-soft: #f6ddd8;
  --ok: #2f6b46;
  --ok-soft: #dfeee5;
  --dark: #1c1a17;
  --dark-text: #efe9df;
  --dark-muted: #9a8f7c;
  --dark-rule: #35312c;

  /* Type scale: page title, section title, body, caption. */
  --t-page: 22px;
  --t-section: 15px;
  --t-body: 14px;
  --t-caption: 12.5px;

  --sidebar: 236px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 26, 23, .06), 0 6px 20px rgba(28, 26, 23, .05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--t-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.serif { font-family: "Newsreader", Georgia, "Times New Roman", serif; }
.mono { font-family: "IBM Plex Mono", Menlo, Consolas, monospace; font-size: 12.5px; }

a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--rust); }
h1, h2, h3 { margin: 0; font-weight: 500; }

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

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--dark);
  color: var(--dark-text);
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 0 6px; }
.brand .mark { width: 22px; height: 22px; flex: none; }
.brand b { font-family: "Newsreader", Georgia, serif; font-weight: 500; font-size: 16px; letter-spacing: .1px; }

.orgswitch { border: 1px solid var(--dark-rule); border-radius: 8px; padding: 8px 10px; background: rgba(255,255,255,.03); }
.orgswitch .label { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--dark-muted); }
.orgswitch select {
  width: 100%; margin-top: 4px; background: transparent; color: var(--dark-text);
  border: 0; font: inherit; font-size: 13px; padding: 0; cursor: pointer;
}
.orgswitch select option { color: var(--ink); }

.navlist { display: flex; flex-direction: column; gap: 1px; }
.navlist a {
  color: var(--dark-muted); padding: 7px 10px; border-radius: 7px; font-size: 13.5px;
  display: flex; align-items: center; gap: 9px;
}
.navlist a:hover { background: rgba(255,255,255,.05); color: var(--dark-text); }
.navlist a[aria-current="page"] { background: rgba(255,255,255,.09); color: #fff; }
.navlist svg { width: 15px; height: 15px; flex: none; opacity: .85; }

.sidefoot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.usagechip {
  border: 1px solid var(--dark-rule); border-radius: 8px; padding: 9px 10px; font-size: 12px; color: var(--dark-muted);
}
.usagechip .amount { display: block; font-size: 17px; color: var(--dark-text); font-family: "Newsreader", Georgia, serif; }
.usagechip a { color: var(--dark-text); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- main column ---------- */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 28px;
  border-bottom: 1px solid var(--rule); background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.crumbs { display: flex; align-items: center; gap: 7px; font-size: var(--t-caption); color: var(--muted-2); min-width: 0; }
.crumbs a { color: var(--muted); }
.crumbs .sep { opacity: .5; }
.topbar .spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--rule);
  border-radius: 999px; padding: 2px 9px; font-size: 11.5px; color: var(--muted); background: var(--surface);
}
.chip.role { text-transform: uppercase; letter-spacing: .07em; }
.chip.ok { border-color: #bcd8c7; background: var(--ok-soft); color: var(--ok); }
.chip.warn { border-color: #e3cf9f; background: var(--amber-soft); color: var(--amber); }
.chip.danger { border-color: #e3b6ae; background: var(--danger-soft); color: var(--danger); }

.profile { position: relative; }
.profile summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 7px; font-size: 13px; }
.profile summary::-webkit-details-marker { display: none; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--panel); border: 1px solid var(--rule);
  display: grid; place-items: center; font-size: 11px; color: var(--muted); text-transform: uppercase;
}
.profile .menu {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow); min-width: 210px; padding: 6px; z-index: 20;
}
.profile .menu a, .profile .menu button {
  display: block; width: 100%; text-align: left; padding: 7px 9px; border: 0; background: none;
  font: inherit; color: var(--ink); border-radius: 7px; cursor: pointer;
}
.profile .menu a:hover, .profile .menu button:hover { background: var(--panel); }
.profile .menu .who { padding: 7px 9px; color: var(--muted-2); font-size: var(--t-caption); border-bottom: 1px solid var(--rule); margin-bottom: 4px; }

/* ---------- banner region (S24) ---------- */

.banners { display: flex; flex-direction: column; }
.banner {
  display: flex; align-items: center; gap: 14px; padding: 11px 28px; font-size: 13.5px;
  border-bottom: 1px solid var(--rule);
}
.banner .txt { flex: 1; }
.banner.info { background: var(--panel); color: var(--muted); }
.banner.warn { background: var(--amber-soft); color: var(--amber); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner .btn { flex: none; }

/* ---------- content ---------- */

.content { padding: 26px 28px 64px; max-width: 1180px; width: 100%; }

.pagehead { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.pagehead h1 { font-family: "Newsreader", Georgia, serif; font-size: var(--t-page); line-height: 1.2; }
.pagehead p { margin: 5px 0 0; color: var(--muted-2); font-size: 13px; max-width: 62ch; }
.pagehead .spacer { flex: 1; }
.pagehead .actions { display: flex; gap: 8px; flex: none; }

.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card > header {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--rule);
}
.card > header h2 { font-size: var(--t-section); font-weight: 600; }
.card > header .spacer { flex: 1; }
.card > header .hint { font-size: var(--t-caption); color: var(--muted-2); }
.card .body { padding: 16px; }
.card .body > p:first-child { margin-top: 0; }
.card .body > p:last-child { margin-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .k { font-size: var(--t-caption); color: var(--muted-2); text-transform: uppercase; letter-spacing: .07em; }
.stat .v { font-family: "Newsreader", Georgia, serif; font-size: 26px; line-height: 1.15; margin-top: 6px; }
.stat .sub { font-size: var(--t-caption); color: var(--muted-2); margin-top: 4px; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }

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

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 16px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted-2);
  font-weight: 600; white-space: nowrap; background: rgba(235, 231, 223, .45);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(235, 231, 223, .35); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }

.empty { padding: 28px 16px; text-align: center; color: var(--muted-2); }
.empty strong { display: block; color: var(--ink); font-size: var(--t-section); margin-bottom: 5px; }
.loaderr { padding: 16px; background: var(--danger-soft); color: var(--danger); font-size: 13px; display: flex; gap: 12px; align-items: center; }

/* ---------- forms and controls ---------- */

label { display: block; font-size: var(--t-caption); color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--surface); font: inherit; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--rust); outline-offset: 1px; }
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 13px; }
.field .help { font-size: var(--t-caption); color: var(--muted-2); margin-top: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.checkline { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin-bottom: 10px; }
.checkline input { margin-top: 3px; }
.checkline label { margin: 0; font-weight: 400; font-size: 13px; color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink); font: inherit;
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted-2); color: var(--ink); }
.btn.primary { background: var(--rust); border-color: var(--rust); color: #fff; }
.btn.primary:hover { background: #9d3f25; color: #fff; }
.btn.danger { color: var(--danger); border-color: #e3b6ae; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn[disabled]:hover, .btn[aria-disabled="true"]:hover { border-color: var(--rule); }

.inline { display: inline; }
.muted { color: var(--muted-2); }
.small { font-size: var(--t-caption); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

/* The folded rotate control on the key row (S08). Closed it is one button; open it
   is the grace-period choice, anchored to the row. */
.rotate { display: inline-block; vertical-align: top; }
.rotate > summary { list-style: none; cursor: pointer; }
.rotate > summary::-webkit-details-marker { display: none; }
/* The panel expands the row rather than floating over it: the table scrolls
   horizontally, and a floating panel would be clipped by that scroll container. */
.rotate > form {
  width: 232px; text-align: left; margin-top: 8px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 10px;
}
.rotate > form p { margin: 0 0 8px; }

/* Reveal-once secret (S05, S09). */
.secret {
  display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--rule);
  border-radius: 8px; padding: 10px 12px; word-break: break-all;
}
.secret code { flex: 1; }

/* Meter used by budgets and the next-charge threshold. */
.meter { height: 7px; background: var(--panel); border-radius: 999px; overflow: hidden; border: 1px solid var(--rule); }
.meter > span { display: block; height: 100%; background: var(--rust); }
.meter.warn > span { background: var(--amber); }
.meter.over > span { background: var(--danger); }

/* Bar chart for the usage series — CSS only, no chart library. */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 132px; padding: 0 2px; }
.bars .bar { flex: 1; background: var(--rust-soft); border: 1px solid #e2c6bb; border-bottom: 0; border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .bar > i { position: absolute; inset: auto 0 0 0; background: var(--rust); border-radius: 2px 2px 0 0; display: block; }
.barlabels { display: flex; gap: 3px; margin-top: 6px; font-size: 10.5px; color: var(--muted-2); }
.barlabels span { flex: 1; text-align: center; overflow: hidden; white-space: nowrap; }

/* Dialogs (S09, S11, S25). Each also renders open without JavaScript when the page
   is requested with its ?dialog= parameter, so no flow depends on script. */
dialog {
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 0; max-width: 520px; width: calc(100% - 32px);
  box-shadow: 0 18px 48px rgba(28, 26, 23, .22); background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(28, 26, 23, .38); }
dialog header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--rule); }
dialog header h2 { font-size: var(--t-section); font-weight: 600; }
dialog .body { padding: 18px; }
dialog footer { display: flex; gap: 9px; justify-content: flex-end; padding: 13px 18px; border-top: 1px solid var(--rule); background: var(--panel); }

/* Consequence-before-commit panel (S04, S23, S25). */
.consequence {
  background: var(--panel); border: 1px solid var(--rule); border-left: 3px solid var(--rust);
  border-radius: 6px; padding: 11px 13px; font-size: 13px; color: var(--muted);
}
.consequence b { color: var(--ink); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #bcd8c7; }
.flash.err { background: var(--danger-soft); color: var(--danger); border: 1px solid #e3b6ae; }

/* ---------- out-of-shell screens (S01–S05, S12) ---------- */

.plain { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 56px 16px 64px; }
.plain .brandmark { display: flex; align-items: center; gap: 9px; margin-bottom: 22px; color: var(--ink); }
.plain .brandmark b { font-family: "Newsreader", Georgia, serif; font-weight: 500; font-size: 17px; }
.authcard {
  width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--rule);
  border-radius: 14px; box-shadow: var(--shadow); padding: 26px;
}
.authcard.wide { max-width: 620px; }
.authcard h1 { font-family: "Newsreader", Georgia, serif; font-size: var(--t-page); margin-bottom: 4px; }
.authcard .lede { color: var(--muted-2); font-size: 13px; margin: 0 0 18px; }
.steps { display: flex; gap: 6px; align-items: center; font-size: var(--t-caption); color: var(--muted-2); margin-bottom: 16px; }
.steps i { display: block; height: 3px; width: 34px; background: var(--rule); border-radius: 2px; }
.steps i.on { background: var(--rust); }
.oauth { display: flex; gap: 9px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--rule); }
.oauth a { flex: 1; justify-content: center; }
.foot { margin-top: 16px; font-size: 13px; color: var(--muted-2); text-align: center; }
.foot a { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- responsive ----------
   Below 1024px the sidebar becomes a horizontal bar above the content; below 768px
   the tables that carry twelve columns collapse into stacked cards, each cell
   labelled by its column header. */

@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center; gap: 14px;
    padding: 10px 16px; flex-wrap: wrap;
  }
  .navlist { flex-direction: row; flex-wrap: wrap; gap: 2px; }
  .sidefoot { margin: 0; flex-direction: row; align-items: center; }
  .usagechip { display: flex; gap: 8px; align-items: baseline; }
  .usagechip .amount { font-size: 14px; }
  .orgswitch { min-width: 180px; }
  .topbar, .banner, .content { padding-left: 18px; padding-right: 18px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 768px) {
  table.stack thead { display: none; }
  table.stack tbody tr {
    display: block; border: 1px solid var(--rule); border-radius: 8px; margin: 10px 12px; padding: 4px 0;
  }
  table.stack td {
    display: flex; justify-content: space-between; gap: 16px; border: 0; padding: 6px 12px; text-align: right;
  }
  table.stack td::before {
    content: attr(data-label); font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--muted-2); text-align: left; flex: none;
  }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .pagehead { flex-direction: column; }
}

@media print {
  .sidebar, .topbar, .banners, .pagehead .actions { display: none; }
  .card { box-shadow: none; }
}
