/* Agent Builder — "operations console" design system.
 * Light editorial theme: white paper, single vermilion red accent, black ink.
 * No gradients, no neon, no dark mode. Serif display + sans UI + mono data.
 * Hand-authored, dependency-free (no CDN, no Node, offline-safe).
 */
:root {
  --paper:    #ffffff;
  --paper-2:  #faf7f5;   /* faint warm tint for hovers/zebra (still ~white) */
  --ink:      #16110f;   /* near-black text */
  --ink-soft: #6b6360;   /* muted labels */
  --line:     #e9e3de;   /* hairline borders (warm) */
  --red:      #cf241b;   /* primary accent */
  --red-dark: #a81910;   /* hover */
  --red-tint: #fcebe9;   /* selected/active wash */
  --ring:     rgba(207,36,27,.22);
  --shadow:   0 10px 30px rgba(22,17,15,.10);
  --serif:    "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans:     system-ui, "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  --mono:     "Cascadia Mono", "Cascadia Code", "JetBrains Mono", "SF Mono", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--sans);
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }
a { color: var(--red); text-decoration: none; }
a:hover { color: var(--red-dark); }

/* ---- thin red scrollbar ---- */
* { scrollbar-width: thin; scrollbar-color: #e3a9a4 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #e3a9a4; border-radius: 99px; border: 2px solid var(--paper); }
::-webkit-scrollbar-thumb:hover { background: var(--red); }

/* ---- helpers ---- */
.flex { display: flex; } .col { flex-direction: column; } .flex-1 { flex: 1; }
.items-center { align-items: center; } .items-end { align-items: flex-end; }
.between { justify-content: space-between; } .center { justify-content: center; }
.wrap { flex-wrap: wrap; } .gap-1{gap:.4rem}.gap-2{gap:.7rem}.gap-3{gap:1rem}.gap-4{gap:1.5rem}
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-soft); }
.red { color: var(--red); }
.text-xs{font-size:.75rem}.text-sm{font-size:.86rem}.text-lg{font-size:1.1rem}
.right { text-align: right; } .truncate { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.mt-2{margin-top:.6rem}.mt-3{margin-top:1rem}.mt-4{margin-top:1.6rem}
.mb-2{margin-bottom:.6rem}.mb-3{margin-bottom:1rem}.mb-4{margin-bottom:1.6rem}
.w-full{width:100%}

/* uppercase tracked label (editorial / console feel) */
.eyebrow, label, .label {
  display: block; font-family: var(--mono); font-size: .68rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: .4rem;
}

/* ---- app shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px; flex-shrink: 0; background: var(--paper); border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 1.6rem 1rem;
}
.brand { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; padding: 0 .6rem 0; line-height: 1.1; }
.brand .dot { color: var(--red); }
.brand-sub { font-family: var(--mono); font-size: .62rem; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-soft); padding: .3rem .6rem 0; }
.brand-rule { height: 2px; background: var(--red); width: 34px; margin: .9rem .6rem 1.4rem; }
.nav { display: flex; flex-direction: column; gap: .15rem; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem;
  border-radius: 7px; color: var(--ink-soft); font-weight: 500; cursor: pointer; font-size: .95rem;
}
.nav-item:hover { background: var(--paper-2); color: var(--ink); }
.nav-item.active { color: var(--red); background: var(--red-tint); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -1rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; background: var(--red); border-radius: 0 3px 3px 0;
}
.nav-spacer { flex: 1; }
.side-foot { border-top: 1px solid var(--line); padding-top: 1rem; }
.side-foot .who { font-family: var(--mono); font-size: .7rem; color: var(--ink-soft); padding: 0 .6rem .6rem; }

/* ---- main ---- */
.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  padding: 2rem 2.4rem 1.2rem; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 2rem; }
.topbar .sub { color: var(--ink-soft); font-size: .9rem; margin-top: .25rem; }
.content { padding: 1.8rem 2.4rem 3rem; }

/* ---- card / panel ---- */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 1.4rem 1.5rem;
}
.card + .card { margin-top: 1.2rem; }
/* Lift a card whose dropdown is open above sibling cards so the (overflowing)
   menu is never painted behind the next card, regardless of stacking contexts. */
.card:has(.dd.open) { position: relative; z-index: 60; }
.card-accent { border-top: 3px solid var(--red); border-radius: 10px; }
.section-title { font-family: var(--mono); font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: .9rem; }
.row { display: flex; gap: 1.1rem; } .row > * { flex: 1; min-width: 0; }
@media (max-width: 720px) { .row { flex-direction: column; } .sidebar { width: 200px; } }

/* Compact form grid: pack 2–3 inputs per row and collapse gracefully on narrow
   screens. Fields keep their own bottom margin, which supplies the row spacing. */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); column-gap: 1.1rem; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; font-family: var(--sans);
  background: var(--paper); color: var(--ink); border: 1px solid var(--ink);
  border-radius: 7px; padding: .55rem 1rem; font-size: .9rem; font-weight: 600; transition: .12s;
}
.btn:hover { background: var(--paper-2); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-danger { background: var(--paper); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-tint); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); background: var(--paper-2); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 6px; }

/* ---- inputs ---- */
.input, input[type=text], input[type=email], input[type=password], input[type=number], textarea {
  width: 100%; background: var(--paper); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: .6rem .75rem; font-size: .92rem; font-family: var(--sans); transition: .12s;
}
textarea { min-height: 8rem; resize: vertical; line-height: 1.5; }
.input:focus, input:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--ring); }
.field { margin-bottom: 1.1rem; }
.hint { font-size: .78rem; color: var(--ink-soft); margin-top: .35rem; text-transform: none; letter-spacing: 0; font-family: var(--sans); }

/* checkbox */
.check { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.check input { appearance: none; width: 18px; height: 18px; border: 1.5px solid var(--ink); border-radius: 5px; cursor: pointer; position: relative; }
.check input:checked { background: var(--red); border-color: var(--red); }
.check input:checked::after { content: "✓"; color: #fff; font-size: 12px; position: absolute; left: 2.5px; top: -1px; }
.check span { text-transform: none; letter-spacing: 0; font-family: var(--sans); font-size: .9rem; color: var(--ink); }

/* ---- custom dropdown ---- */
.dd { position: relative; }
.dd.open { z-index: 50; }
.dd-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .75rem; font-size: .92rem; cursor: pointer; color: var(--ink); text-align: left; font-family: var(--sans);
}
.dd-trigger:focus, .dd.open .dd-trigger { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--ring); }
.dd-trigger .dd-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-trigger .dd-val.placeholder { color: var(--ink-soft); }
.dd-caret { color: var(--red); transition: transform .15s; flex-shrink: 0; font-size: .7rem; }
.dd.open .dd-caret { transform: rotate(180deg); }
.dd-menu {
  position: absolute; z-index: 40; top: calc(100% + 5px); left: 0; right: 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow);
  padding: .35rem; max-height: 17rem; overflow: auto; display: none;
}
.dd.open .dd-menu { display: block; animation: pop .12s ease-out; }
.dd-search { width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: .5rem .5rem; margin-bottom: .3rem; font-size: .88rem; position: sticky; top: 0; background: var(--paper); }
.dd-search:focus { outline: none; box-shadow: none; border-bottom-color: var(--red); }
.dd-opt {
  padding: .5rem .6rem; border-radius: 6px; cursor: pointer; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.dd-opt:hover, .dd-opt.kbd { background: var(--paper-2); }
.dd-opt.selected { color: var(--red); font-weight: 600; }
.dd-opt.selected::after { content: "●"; font-size: .55rem; }
.dd-opt .opt-sub { font-family: var(--mono); font-size: .72rem; color: var(--ink-soft); }
.dd-empty { padding: .6rem; color: var(--ink-soft); font-size: .85rem; text-align: center; }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-family: var(--mono); font-size: .68rem; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft); padding: .65rem .7rem; border-bottom: 1.5px solid var(--ink);
}
.table td { padding: .8rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: .92rem; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--paper-2); }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: .78rem; color: var(--ink-soft); }

/* ---- badge ---- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 99px;
  font-family: var(--mono); font-size: .68rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  border: 1px solid var(--line);
}
.badge-red { color: var(--red); border-color: var(--red); background: var(--red-tint); }
.badge-muted { color: var(--ink-soft); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; }

/* ---- chips / key pill ---- */
.pill { font-family: var(--mono); font-size: .85rem; background: var(--paper-2); border: 1px solid var(--line); padding: .55rem .7rem; border-radius: 7px; word-break: break-all; }

/* ---- empty state ---- */
.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-soft); }
.empty .big { font-family: var(--serif); font-size: 1.3rem; color: var(--ink); margin-bottom: .4rem; }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 1.4rem; right: 1.4rem; background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 8px;
  padding: .8rem 1.1rem; box-shadow: var(--shadow); max-width: 24rem; font-size: .9rem; z-index: 90;
  animation: pop .15s ease-out;
}

/* ---- auth (login) ---- */
/* Hairline grid via an inline SVG (no gradients). */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='46' height='46'%3E%3Cpath d='M46 0H0V46' fill='none' stroke='%23ece6e1' stroke-width='1'/%3E%3C/svg%3E"); }
.auth-card { width: 100%; max-width: 25rem; background: var(--paper); border: 1px solid var(--line); border-top: 3px solid var(--red); border-radius: 12px; padding: 2rem; box-shadow: var(--shadow); }

/* ---- motion (one orchestrated load) ----
 * NOTE: the `to` frames intentionally omit `transform` so no transform persists
 * after the animation — a lingering transform would create a stacking context
 * per card and trap dropdown menus behind the next card. */
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }
.reveal > * { animation: rise .42s cubic-bezier(.2,.7,.3,1) both; }
.reveal > *:nth-child(1){animation-delay:.02s}.reveal > *:nth-child(2){animation-delay:.08s}
.reveal > *:nth-child(3){animation-delay:.14s}.reveal > *:nth-child(4){animation-delay:.2s}
.reveal > *:nth-child(5){animation-delay:.26s}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
