/* Keoses platform styles. Tokens first; dark mode follows the system. No external fonts or CDNs, no inline styles (CSP). */
:root {
  --brand: #3f51e0;
  --brand-ink: #ffffff;
  --bg: #f5f6fa;
  --card: #ffffff;
  --ink: #12151f;
  --muted: #5a6278;
  --line: #e1e5ee;
  --ok: #0f7a5a;
  --ok-bg: #e2f5ee;
  --warn: #8f5600;
  --warn-bg: #fdf0d9;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #8b98ff; --brand-ink: #0d1020;
    --bg: #0d1017; --card: #161a23; --ink: #eef0f6; --muted: #9aa2b6; --line: #272d3a;
    --ok: #4fd1a1; --ok-bg: #12342a; --warn: #f2b34a; --warn-bg: #3a2b0e; --bad: #ff8f86; --bad-bg: #3d1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  --brand: #8b98ff; --brand-ink: #0d1020;
  --bg: #0d1017; --card: #161a23; --ink: #eef0f6; --muted: #9aa2b6; --line: #272d3a;
  --ok: #4fd1a1; --ok-bg: #12342a; --warn: #f2b34a; --warn-bg: #3a2b0e; --bad: #ff8f86; --bad-bg: #3d1a17;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.center { text-align: center; }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 440px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 720px) { .wrap { padding: 24px; } h1 { font-size: 1.9rem; } .grid.two { grid-template-columns: 1fr 1fr; } }

/* brand mark */
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.25rem; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; }
.hero { text-align: center; padding-top: 10vh; }
.hero .logo { margin-bottom: 18px; }
.hero .card { text-align: start; }

/* top bar (admin) */
.top { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.top .space { flex: 1; }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; min-height: 40px; display: inline-flex; align-items: center; }
.top nav a[aria-current="page"] { background: var(--bg); color: var(--ink); }

@media (max-width: 479px) { .top .wrap > .muted { display: none; } }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 1.45rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: .85rem; }
.big { font-size: 2.1rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.field + .field { margin-top: 12px; }
.help { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.pwrow { position: relative; }
.pwrow input { padding-inline-end: 64px; }
.pwrow button { position: absolute; inset-inline-end: 4px; top: 4px; min-height: 36px; border: 0; background: none; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 0 10px; }

.btn { white-space: nowrap; font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 16px; min-height: 44px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chipbtn { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 6px 12px; min-height: 36px; font: inherit; font-size: .9rem; cursor: pointer; }
.chipbtn:hover { border-color: var(--brand); }

.chip { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 650; background: var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

.banner { border-radius: var(--radius); padding: 12px 14px; background: var(--warn-bg); color: var(--warn); border: 1px solid var(--line); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.error { color: var(--bad); }
.error:empty { margin: 0 !important; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: var(--mono); font-size: .85rem; }
pre.envbox { margin: 0; padding: 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); overflow-x: auto; font: .82rem/1.5 var(--mono); user-select: all; white-space: pre; }
details > summary { cursor: pointer; font-weight: 650; min-height: 32px; }

/* tables: a real table on desktop, stacked rows on a phone */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 650; }
td.r, th.r { text-align: end; }
.tablewrap { overflow-x: auto; }
@media (max-width: 639px) {
  table.stackable thead { display: none; }
  table.stackable tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
  table.stackable td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 3px 0; text-align: end; }
  table.stackable td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: start; flex: none; }
  table.stackable td.first { display: block; font-weight: 650; text-align: start; }
  table.stackable td.first::before { content: none; }
  table.stackable td.first .row { margin-top: 4px; }
  table.stackable td.first .muted { font-weight: 400; }
}

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 99; max-width: 90vw; box-shadow: var(--shadow); }

/* ---- console: apps list, app page ---- */
.avatar { width: 40px; height: 40px; border-radius: 12px; flex: none; display: inline-grid; place-items: center; color: #fff; font-weight: 750; font-size: 1.1rem; object-fit: cover; background: var(--brand); text-shadow: 0 1px 1px rgba(0, 0, 0, .25); }
img.avatar { background: var(--card); border: 1px solid var(--line); object-fit: contain; }
.avatar.big { width: 64px; height: 64px; border-radius: 16px; font-size: 1.7rem; }
.appname { display: flex; gap: 12px; align-items: center; min-width: 0; }
.appname > div { min-width: 0; }
.appname a { font-weight: 650; }
.appname .muted { overflow-wrap: anywhere; }
.headrow { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.headrow .grow { min-width: 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.tabs button { flex: none; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 650; padding: 10px 14px; min-height: 44px; cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }
.kv { display: grid; grid-template-columns: 1fr; gap: 2px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (min-width: 640px) { .kv { grid-template-columns: 200px 1fr; } .kv dt { margin-top: 0; padding: 6px 0; font-size: .85rem; } .kv dd { padding: 6px 0; } }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input[type="checkbox"] { width: 22px; height: 22px; min-height: 22px; margin-top: 2px; flex: none; accent-color: var(--brand); }
.check label { margin: 0; font-weight: 600; cursor: pointer; }
.check .help { margin-top: 0; }
.rolegrid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .rolegrid { grid-template-columns: 1fr 1fr; } }
input[type="color"] { padding: 4px; min-height: 44px; }
input[type="file"] { padding: 8px; }
.codebox { margin: 0; padding: 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font: .85rem/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
.people-row .roles { display: flex; gap: 6px; flex-wrap: wrap; }
.preview { max-width: 100%; max-height: 120px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 8px; }
.preview.square { width: 96px; height: 96px; max-height: none; object-fit: contain; border-radius: 22px; align-self: flex-start; } /* the icon's frame is square, like a home-screen tile */
.notice { font-size: .85rem; color: var(--muted); }

/* the console's top bar on a phone: the links move to their own row instead of running off the screen */
@media (max-width: 479px) {
  .top .wrap { flex-wrap: wrap; row-gap: 2px; }
  .top nav { order: 3; width: 100%; overflow-x: auto; }
  .top nav a { padding: 8px 10px; }
}
.nowrap { white-space: nowrap; }

/* ---- Keoses 2: billing, statement, activity, usage ---- */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 8px 14px; min-height: 40px; cursor: pointer; }
.segmented button + button { border-inline-start: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.livebar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.livedot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.livedot.paused { background: var(--muted); }
.check.coming { opacity: .55; }
.check.coming label { cursor: not-allowed; }
.check.missing { opacity: .7; }
.statement-sheet { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--bg); }
.statement-sheet h3 { margin: 18px 0 4px; }
.statement-sheet table { margin: 4px 0 0; }
.statement-sheet .total td, .statement-sheet .total th { font-weight: 750; border-top: 2px solid var(--ink); }
.statement-sheet .internal { color: var(--warn); }
.voided td { text-decoration: line-through; color: var(--muted); }
.voided td.keep { text-decoration: none; }
.hbar { background: var(--line); border-radius: 999px; height: 8px; overflow: hidden; margin-top: 4px; }
.hbar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; min-width: 2px; }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 8px; }
.chart .col { flex: 1 1 0; min-width: 0; background: var(--brand); opacity: .8; border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .col:hover { opacity: 1; }
.chartlabels { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed li.req { color: var(--muted); font-size: .9rem; }
.feed .when { color: var(--muted); font-size: .8rem; }
@media (min-width: 640px) { .feed li { grid-template-columns: 130px 130px 1fr; gap: 12px; align-items: baseline; } }
.filters { display: grid; gap: 10px; grid-template-columns: 1fr; align-items: end; }
@media (min-width: 640px) { .filters { grid-template-columns: 1fr 1fr auto; } }
progress { width: 100%; height: 10px; accent-color: var(--brand); }
.stepslist { list-style: none; margin: 6px 0 0; padding: 0; }
.stepslist li { padding: 3px 0; }
.stepslist li::before { content: "○ "; color: var(--muted); }
.stepslist li.done::before { content: "✓ "; color: var(--ok); }
details.more > summary { padding: 6px 0; color: var(--brand); }

/* printing a statement from the Billing tab: only the statement, on white */
@media print {
  body { background: #fff; color: #000; }
  .top, .tabs, .headrow, .noprint, .toast { display: none !important; }
  #tab-panel > .stack > :not(.statement-card) { display: none !important; }
  .statement-card { border: 0; box-shadow: none; padding: 0; background: #fff; }
  .statement-sheet { border: 0; padding: 0; background: #fff; }
  .statement-card .noprint { display: none !important; }
  a { color: inherit; text-decoration: none; }
}
