/* Agrafe admin panel. Palette comes from dolfin-suite.css (--ctp-*). */
* { box-sizing: border-box; }
body { margin: 0; background: var(--ctp-base); color: var(--ctp-text); font: 14px/1.45 system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--ctp-surface0); border: 1px solid var(--ctp-surface2); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { background: var(--ctp-surface1); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--ctp-blue); outline-offset: 2px; }
input, select { background: var(--ctp-mantle); border: 1px solid var(--ctp-surface2); border-radius: 6px; padding: 5px 8px; }
a { color: var(--ctp-blue); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 24px 0 8px; }
.dn-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.muted { color: var(--ctp-subtext0); }
.error { color: var(--ctp-red); }

/* Auth screens */
.auth { max-width: 380px; margin: 10vh auto; padding: 24px; background: var(--ctp-mantle); border: 1px solid var(--ctp-surface1); border-radius: 10px; }
.auth form, .auth .stack { display: grid; gap: 10px; }
.auth label { display: grid; gap: 4px; }
.primary { background: var(--ctp-blue); color: var(--ctp-base); border-color: var(--ctp-blue); font-weight: 600; padding: 8px 12px; }
.primary:hover { background: var(--ctp-sapphire); }

/* Layout */
.app { display: grid; grid-template-columns: 180px 1fr; min-height: calc(100vh - 48px); }
.side { display: flex; flex-direction: column; gap: 2px; padding: 16px 8px; background: var(--ctp-mantle); border-right: 1px solid var(--ctp-surface0); }
.side a { padding: 6px 10px; border-radius: 6px; color: var(--ctp-subtext1); text-decoration: none; }
.side a:hover { background: var(--ctp-surface0); }
.side a[aria-current="page"] { background: var(--ctp-surface1); color: var(--ctp-text); font-weight: 600; }
.view { padding: 20px 24px; min-width: 0; }
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--ctp-surface0); padding: 8px 16px; }
  .view { padding: 16px; }
}

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--ctp-mantle); border: 1px solid var(--ctp-surface0); border-radius: 8px; padding: 12px; }
.tile .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .k { color: var(--ctp-subtext0); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--ctp-mantle); border: 1px solid var(--ctp-surface0); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.card h2 { margin-top: 0; }

/* Charts: one hue, recessive axes */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--ctp-blue); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart g:hover .bar { fill: var(--ctp-sapphire); }
.chart .axis { stroke: var(--ctp-surface2); stroke-width: 1; }
.chart text { fill: var(--ctp-subtext0); font-size: 10px; }
.chart .val { fill: var(--ctp-text); font-size: 11px; }
.hbar { display: grid; grid-template-columns: 130px 1fr 48px; gap: 8px; align-items: center; margin: 4px 0; }
.hbar .track { height: 10px; background: var(--ctp-surface0); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--ctp-blue); border-radius: 0 4px 4px 0; }
.hbar .n { text-align: right; font-variant-numeric: tabular-nums; }
details.table-view summary { cursor: pointer; color: var(--ctp-subtext0); font-size: 12px; margin-top: 6px; }

/* Tables */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--ctp-surface0); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--ctp-surface0); white-space: nowrap; }
th { background: var(--ctp-mantle); position: sticky; top: 0; font-weight: 600; }
th[data-sort] { cursor: pointer; user-select: none; }
th[aria-sort="ascending"]::after { content: " ▲"; }
th[aria-sort="descending"]::after { content: " ▼"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--ctp-surface0); }
.wrap { white-space: normal; word-break: break-word; }

/* Status badges: always icon + label, never color alone */
.badge { display: inline-flex; gap: 4px; align-items: center; padding: 1px 7px; border-radius: 10px; font-size: 12px; border: 1px solid currentColor; }
.badge.good { color: var(--ctp-green); }
.badge.warn { color: var(--ctp-peach); }
.badge.bad { color: var(--ctp-red); }
.badge.info { color: var(--ctp-subtext1); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid var(--ctp-surface0); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--ctp-subtext0); }
dl.kv dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Hold-to-confirm button */
.hold { position: relative; overflow: hidden; background: var(--ctp-surface0); border-color: var(--ctp-surface2); }
.hold::before { content: ""; position: absolute; inset: 0; width: 0; background: var(--ctp-peach); opacity: .35; transition: none; }
.hold.danger::before { background: var(--ctp-red); }
.hold.holding::before { width: 100%; transition: width var(--hold-ms, 1500ms) linear; }
.hold span { position: relative; }
.hold.danger { border-color: var(--ctp-red); color: var(--ctp-red); }

.toast { position: fixed; bottom: 16px; right: 16px; max-width: 360px; padding: 10px 14px; border-radius: 8px; background: var(--ctp-surface1); color: var(--ctp-text); box-shadow: 0 4px 16px rgb(0 0 0 / 25%); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left: 4px solid var(--ctp-red); }
pre { background: var(--ctp-mantle); border: 1px solid var(--ctp-surface0); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 12px; }
