/* =====================================================================
   Dashboard Ternumerik — charte graphique (design importé).
   teal #1E373E · lime #CCDD22 · crème #EDECE4.
   Polices Google (Space Grotesk / Instrument Sans / JetBrains Mono) chargées
   dans le <head> avec repli système si une CSP les bloque.
   ===================================================================== */
:root {
  --bg: #EDECE4;
  --sidebar: #1E373E;
  --sidebar-line: #2C4A52;
  --sidebar-muted: #9DB0AE;
  --sidebar-dim: #5C7370;
  --lime: #CCDD22;
  --card: #FFFFFF;
  --card-border: #E7E5DA;
  --row-line: #F0EEE4;
  --thead: #F3F2EA;
  --ink: #1E373E;
  --muted: #7A8785;
  --muted2: #5E6E6E;
  --green: #3E7A4E;
  --green-link: #4A6E2E;
  --green-soft-bg: #EAF3E7;
  --green-soft-border: #CDE3C6;
  --danger: #B23A2E;
  --danger-border: #E6C4BF;
  --scope-bg: #F0F3D8;
  --head: 'Space Grotesk', system-ui, sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, "SFMono-Regular", Menlo, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); }
a { color: var(--green-link); text-decoration: none; }
a:hover { color: #3a571f; }
button { font-family: var(--body); }

/* --- Layout --- */
.layout { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }

/* --- Sidebar --- */
.sidebar { background: var(--sidebar); padding: 28px 24px; display: flex; flex-direction: column;
           position: sticky; top: 0; height: 100vh; }
.brand { margin-bottom: 40px; }
.brand .brand-logo { display: block; width: 100%; max-width: 190px; height: auto; }
.brand .sub { font-family: var(--head); font-weight: 500; font-size: 13px; color: var(--sidebar-muted);
              margin-top: 12px; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
         font-size: 14px; cursor: pointer; color: var(--sidebar-muted); font-weight: 400; }
.nav a .dot { width: 7px; height: 7px; border-radius: 2px; background: #3F5B62; flex: 0 0 auto; }
.nav a:hover { color: #cfe0dd; }
.nav a.active { background: rgba(204,221,34,.14); color: var(--lime); font-weight: 600; }
.nav a.active .dot { background: var(--lime); }
.side-foot { margin-top: auto; padding-top: 24px; border-top: 1px solid var(--sidebar-line); }
.side-user { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--lime); color: var(--sidebar);
          display: flex; align-items: center; justify-content: center; font-family: var(--head);
          font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.side-user .name { font-size: 13px; color: #F1F5F3; font-weight: 500; }
.side-user .role { font-size: 11px; color: var(--lime); letter-spacing: .06em; font-weight: 600; }
.side-logout { font-size: 13px; color: var(--sidebar-muted); display: inline-block; margin-top: 6px; cursor: pointer; }
.side-diag { margin-top: 14px; font-family: var(--mono); font-size: 10px; line-height: 1.6; color: var(--sidebar-dim); }

/* --- Main --- */
.main { padding: 44px 56px 64px; }
.page-head { margin-bottom: 32px; }
.page-head h1 { font-family: var(--head); font-size: 26px; font-weight: 700; color: var(--ink); margin: 0 0 6px; }
.page-head .lead { font-size: 15px; color: var(--muted2); margin: 0; }
.page-head .mono { font-family: var(--mono); font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 32px; }

.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; }
.section-title .sq { width: 9px; height: 9px; background: var(--lime); border-radius: 2px; flex: 0 0 auto; }
.section-title h2 { font-family: var(--head); font-size: 18px; font-weight: 600; color: var(--ink); margin: 0; }

/* --- KPI --- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 36px; }
.kpi { background: var(--card); border: 1px solid var(--card-border); border-radius: 12px; padding: 22px 22px 20px; }
.kpi .k-label { font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 12px; }
.kpi .k-value { font-family: var(--head); font-size: 32px; font-weight: 700; color: var(--ink); line-height: 1; }
.kpi .k-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.kpi .k-hint.up { color: var(--green); }

/* --- Card / Chart --- */
.card { background: var(--card); border: 1px solid var(--card-border); border-radius: 12px; }
.card.pad { padding: 26px 28px 22px; margin-bottom: 36px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.card-head h2 { font-family: var(--head); font-size: 16px; font-weight: 600; color: var(--ink); margin: 0; }
.card-head .mono { font-family: var(--mono); font-size: 12px; color: #9AA6A4; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; }
.chart .bar { flex: 1; min-width: 0; border-radius: 3px 3px 0 0; background: var(--lime); }
.chart .bar.last { background: var(--ink); }
.chart-axis { display: flex; justify-content: space-between; margin-top: 10px; font-family: var(--mono);
              font-size: 11px; color: #9AA6A4; }

/* --- Tables --- */
.table { background: var(--card); border: 1px solid var(--card-border); border-radius: 12px; overflow: hidden; }
.table .thead, .table .trow { display: grid; align-items: center; }
.table .thead { padding: 14px 24px; background: var(--thead); font-size: 12px; font-weight: 600;
                letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.table .trow { padding: 16px 24px; font-size: 14px; color: var(--ink); border-top: 1px solid var(--row-line); }
.table .trow .mono { font-family: var(--mono); font-size: 13px; }
.table .trow .sub { color: var(--muted2); }
.usage-grid { grid-template-columns: 1.4fr 1fr 1.4fr .9fr; }
.tokens-grid { grid-template-columns: 1.4fr 1fr 1fr 1fr .8fr .9fr; }
.runs-grid { grid-template-columns: 1fr 1fr 1.1fr .9fr .9fr .7fr .7fr .8fr; }
.tl-grid { grid-template-columns: .8fr .8fr 1.8fr .8fr .8fr .8fr; }

.pill-ok { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--green); }
.pill-ok .d { width: 7px; height: 7px; background: var(--green); border-radius: 50%; }
.pill-wait { font-size: 12px; color: #9A6B00; background: rgba(214,158,46,.14); padding: 3px 9px; border-radius: 6px; }
.pill-run { font-family: var(--mono); font-size: 12px; color: var(--muted2); background: var(--scope-bg); padding: 3px 9px; border-radius: 6px; }

/* --- Sous-onglets (détail agent) --- */
.subtabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--card-border); }
.subtab { padding: 9px 16px; font-size: 14px; font-weight: 600; color: var(--muted2); cursor: pointer;
          border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--ink); border-bottom-color: var(--lime); }

/* --- Exécutions (runs) --- */
.run-row { cursor: pointer; }
.run-row:hover { background: rgba(204,221,34,.06); }
.run-row.open { background: rgba(204,221,34,.10); }
.run-detail { margin-top: 18px; background: var(--card); border: 1px solid var(--card-border); border-radius: 12px; padding: 20px 24px; }
.run-detail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.run-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; margin-bottom: 8px; }
.run-stats > div { display: flex; flex-direction: column; gap: 3px; }
.run-stats span { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #9AA6A4; }
.run-stats b { font-family: var(--head); font-size: 18px; color: var(--ink); }
.run-stats em { font-size: 11px; color: var(--muted2); font-style: normal; }
.run-err { margin: 8px 0 4px; padding: 10px 12px; border-radius: 8px; background: rgba(200,60,60,.08);
           color: var(--danger); font-family: var(--mono); font-size: 12.5px; word-break: break-word; }
.scope { display: inline-flex; align-items: center; white-space: nowrap;
         font-family: var(--mono); font-size: 12px; background: var(--scope-bg); color: var(--green-link);
         padding: 3px 9px; border-radius: 6px; }
/* Cellule Scopes : les badges wrappent proprement (flex-wrap + gap), jamais en flux texte. */
.scopes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.revoked { color: var(--danger); }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; gap: 8px; font-family: var(--head); font-weight: 600;
       font-size: 14px; border-radius: 9px; cursor: pointer; border: none; padding: 12px 20px; }
.btn .plus { font-size: 18px; line-height: 1; margin-top: -1px; }
.btn-primary { background: var(--lime); color: var(--ink); }
.btn-primary:hover { background: #bccb1f; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid #CFCDBF; padding: 9px 16px; font-size: 13px; }
.btn-ghost:hover { border-color: var(--ink); }
.btn-revoke { font-size: 13px; font-weight: 600; color: var(--danger); background: transparent;
              border: 1px solid var(--danger-border); padding: 6px 14px; border-radius: 7px; cursor: pointer; }
.btn-revoke:hover { background: var(--danger); color: #fff; }

/* --- Agent cards --- */
.agent-list { display: flex; flex-direction: column; gap: 16px; }
.agent-card { background: var(--card); border: 1px solid var(--card-border); border-radius: 12px; padding: 22px 26px; }
.agent-card.clickable { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.agent-card.clickable:hover { border-color: var(--lime); box-shadow: 0 2px 12px rgba(30,55,62,.06); }
.a-prompts-cue { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--green-link); font-weight: 600; }
.back-link { display: inline-block; font-size: 13px; color: var(--green-link); cursor: pointer; margin-bottom: 12px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.agent-card .a-name { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.agent-card .a-name b { font-family: var(--head); font-weight: 600; font-size: 16px; color: var(--ink); }
.agent-card .a-name .d { width: 7px; height: 7px; background: var(--lime); border-radius: 50%; }
.agent-card .a-call { font-family: var(--mono); font-size: 13px; color: var(--muted2); line-height: 1.6; }
.agent-card .a-call .verb { color: var(--green-link); font-weight: 600; }
.agent-card .a-call .ink { color: var(--ink); }
.agent-card .a-call .dim { color: #9AA6A4; }
.a-sep { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--row-line); }
.a-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px;
          margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--row-line); }
.keytag { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500;
          padding: 5px 12px; border-radius: 999px; }
.keytag .d { width: 7px; height: 7px; border-radius: 50%; }
.keytag.active { color: var(--green); background: var(--green-soft-bg); border: 1px solid var(--green-soft-border); }
.keytag.active .d { background: var(--green); }
.keytag.none { color: #9AA6A4; background: var(--thead); border: 1px solid #E2E0D5; }
.keytag.none .d { background: #C2C0B2; }

/* --- New-token banner (jeton affiché une fois) --- */
.newtoken { background: #F5F7E4; border: 1px solid var(--lime); border-radius: 12px; padding: 18px 22px; margin-bottom: 24px; }
.newtoken strong { font-family: var(--head); color: var(--ink); }
.newtoken code { display: block; margin-top: 10px; font-family: var(--mono); font-size: 13px; word-break: break-all;
                 background: #fff; border: 1px solid var(--card-border); padding: 12px; border-radius: 8px; color: var(--green-link); }

/* --- Empty state --- */
.empty { color: var(--muted2); font-style: italic; padding: 8px 2px; }

/* --- Drawer --- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(20,38,42,.45); z-index: 40;
                  transition: opacity .25s ease; opacity: 0; pointer-events: none; }
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw; background: #F7F6F0;
          box-shadow: -24px 0 60px -30px rgba(15,30,34,.6); z-index: 50; display: flex; flex-direction: column;
          transition: transform .28s cubic-bezier(.4,0,.2,1); transform: translateX(100%); }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 24px 28px; border-bottom: 1px solid var(--card-border); }
.drawer-head h2 { font-family: var(--head); font-size: 18px; font-weight: 600; color: var(--ink); margin: 0; }
.drawer-x { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
            background: transparent; border: 1px solid #DDDCD1; border-radius: 8px; color: var(--muted2);
            font-size: 18px; cursor: pointer; line-height: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 28px; }
.drawer-body label.fld { display: block; font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
.drawer-body input[type=text], .drawer-body input[type=password] {
                                width: 100%; padding: 11px 14px; border: 1px solid #D8D6CB; border-radius: 8px;
                                background: #FBFAF5; font-family: var(--body); font-size: 14px; color: var(--ink);
                                outline: none; margin-bottom: 24px; }
.drawer-body input[type=text]:focus, .drawer-body input[type=password]:focus { border-color: var(--lime); }
.drawer-body .agents-title { font-size: 14px; font-weight: 600; color: var(--ink); margin-top: 26px; margin-bottom: 14px; }
.secret-hint { font-size: 12.5px; color: var(--muted, #6b7472); line-height: 1.5; margin: 0 0 16px; }
.scope.secret { background: transparent; border: 1px solid #D8D6CB; color: var(--ink); }

/* Écran Prompts (admin) */
.prompt-card { background: var(--card, #FBFAF5); border: 1px solid #E3E1D6; border-radius: 12px;
               margin-bottom: 18px; overflow: hidden; }
.prompt-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
               padding: 14px 18px; border-bottom: 1px solid #E3E1D6; flex-wrap: wrap; }
.prompt-name { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--ink); }
.prompt-meta { display: inline-flex; align-items: center; gap: 8px; }
.prompt-body { margin: 0; padding: 18px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
               color: var(--ink); white-space: pre-wrap; word-break: break-word; overflow-x: auto;
               background: transparent; }
.check-list { display: flex; flex-direction: column; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--ink); cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box { width: 18px; height: 18px; border-radius: 5px; display: inline-flex; align-items: center;
              justify-content: center; background: #FBFAF5; border: 1px solid #CFCDBF; }
.check input:checked + .box { background: var(--lime); border-color: var(--lime); }
.check .box svg { display: none; }
.check input:checked + .box svg { display: block; }
.drawer-foot { display: flex; gap: 12px; justify-content: flex-end; padding: 20px 28px; border-top: 1px solid var(--card-border); }
.btn-cancel { font-family: var(--body); font-weight: 600; font-size: 14px; background: transparent;
              color: var(--muted2); border: 1px solid #DDDCD1; padding: 11px 20px; border-radius: 9px; cursor: pointer; }

/* --- Login (non authentifié) --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { background: var(--card); border: 1px solid var(--card-border); border-radius: 16px;
              padding: 3rem 2.75rem; max-width: 440px; text-align: center; }
.login-card .logo { font-family: var(--head); font-weight: 700; font-size: 24px; color: var(--ink); }
.login-card .logo b { color: var(--green-link); }
.login-card p { color: var(--muted2); line-height: 1.55; }
.login-card .warn { color: #b26b00; }

.run-logs { max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12px; }
