/* Dashboard styles, mobile first: the base rules are for phones, @media (min-width: 768px) grows the layout.
   Colours are tokens with a dark set for prefers-color-scheme: dark. Touch targets are at least 44px. */

:root {
  color-scheme: light dark;
  --bg: #f5f6f8; --card: #fff; --ink: #1d2330; --muted: #667085; --line: #e4e7ec;
  --accent: #2b6fd6; --accent-ink: #fff; --accent-soft: #e8f0fd;
  --bad: #c4321f; --bad-soft: #fdecea; --bad-line: #f3c3bc;
  --ok: #17803d; --ok-soft: #e7f6ec; --ok-line: #b7e3c4;
  --code: #f0f2f5; --bar: #1d2330; --bar-ink: #fff; --bar-muted: #cfd6e4;
  --series-1: #2a78d6; --series-2: #eb6834; --chart-grid: #e1e0d9; --chart-base: #c3c2b7; --chart-text: #898781;
  --chart-hover: rgba(29, 35, 48, .06);
  --tabbar: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --card: #181c24; --ink: #e6e9ef; --muted: #98a2b3; --line: #2a303b;
    --accent: #6aa1f0; --accent-ink: #0f1218; --accent-soft: #1f2d45;
    --bad: #f28b7d; --bad-soft: #3a1f1c; --bad-line: #6b2f27;
    --ok: #5fcf8a; --ok-soft: #173322; --ok-line: #24553a;
    --code: #232936; --bar: #181c24; --bar-ink: #e6e9ef; --bar-muted: #98a2b3;
    --series-1: #4a90e8; --series-2: #f07e4f; --chart-grid: #2a303b; --chart-base: #464d5a; --chart-text: #8b93a3;
    --chart-hover: rgba(255, 255, 255, .07);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
p { margin: .6rem 0; }
.muted { color: var(--muted); }
code {
  font-size: .85rem; background: var(--code); padding: .1rem .3rem; border-radius: 4px;
  overflow-wrap: anywhere;
}

/* ---- header and navigation: compact bar on top, tab bar at the bottom ---- */

header.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: calc(env(safe-area-inset-top) + .55rem) calc(env(safe-area-inset-right) + 1rem) .55rem calc(env(safe-area-inset-left) + 1rem);
  background: var(--bar); color: var(--bar-ink);
}
.brand { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 700; }
.brand img { width: 26px; height: 26px; }
.brand small { font-weight: 400; color: var(--bar-muted); font-size: .8rem; }
header.top .who, header.top form { display: none; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--card); border-top: 1px solid var(--line);
}
nav.tabs a {
  min-height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
nav.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs a[aria-current] { color: var(--accent); }

main {
  max-width: 1150px; margin: 0 auto;
  padding: 1rem calc(env(safe-area-inset-right) + .75rem) calc(var(--tabbar) + env(safe-area-inset-bottom) + 1.5rem) calc(env(safe-area-inset-left) + .75rem);
}

/* ---- cards, tiles, chips ---- */

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem; margin-bottom: 1rem;
}
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem .8rem; }
.stat b { display: block; font-size: 1.25rem; overflow-wrap: anywhere; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat small { display: block; color: var(--muted); font-size: .8rem; }
.stat b .muted { font-size: .9rem; font-weight: 400; }

.links { margin: 1rem 0 0; display: grid; gap: .5rem; }
.links dt { color: var(--muted); font-size: .85rem; }
.links dd { margin: 0; }
.links a { display: block; }
.links code { display: block; padding: .5rem .6rem; }

.chips {
  display: flex; gap: .5rem; overflow-x: auto; margin: 0 -.75rem .8rem; padding: 0 .75rem .2rem;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips a {
  flex: none; display: inline-flex; align-items: center; min-height: 40px; padding: 0 1rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card);
  color: var(--ink); text-decoration: none; font-size: .9rem; white-space: nowrap;
}
.chips a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.period { margin: -.3rem 0 .8rem; font-size: .85rem; }

.tag {
  display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }

.flash { border-radius: 12px; padding: .8rem 1rem; margin-bottom: 1rem; }
.flash.notice { background: var(--ok-soft); border: 1px solid var(--ok-line); }
.flash.error { background: var(--bad-soft); border: 1px solid var(--bad-line); color: var(--bad); }

/* ---- buttons and forms ---- */

button {
  font: inherit; font-size: .95rem; min-height: 44px; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad-line); }
form { margin: 0; }

label { display: block; font-weight: 600; font-size: .9rem; margin-top: .8rem; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; min-height: 44px; font: inherit; font-size: 16px; /* 16px: iOS does not zoom in on focus */
  padding: .5rem .7rem; margin: .3rem 0; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink);
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input.otp { font-size: 1.5rem; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums; }
label.check { display: flex; align-items: center; gap: .6rem; font-weight: 400; margin-top: 1rem; min-height: 44px; }
label.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }
form.stack button { margin-top: 1rem; width: 100%; }
.inline { display: flex; flex-direction: column; gap: .2rem; }
.inline button { margin-top: .5rem; }
.limit { max-width: 520px; }

details > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details.more { width: 100%; }
details.more > summary { font-weight: 400; color: var(--accent); }
details.more form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
details.more input { flex: 1; min-width: 10rem; margin: 0; }

/* ---- tables: cards on phones, rows from 768px ---- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; }

table.cards thead { display: none; }
table.cards, table.cards tbody, table.cards td { display: block; }
table.cards tr {
  display: flex; flex-direction: column; padding: .7rem .8rem; margin-bottom: .7rem;
  border: 1px solid var(--line); border-radius: 10px;
}
table.cards tr:last-child { margin-bottom: 0; }
table.cards td { position: relative; padding: .2rem 0 .2rem 8rem; min-height: 1.6rem; overflow-wrap: anywhere; }
table.cards td::before {
  content: attr(data-label); position: absolute; left: 0; top: .2rem; width: 7.5rem;
  color: var(--muted); font-size: .85rem;
}
table.cards td.title { order: -1; padding: 0 0 .35rem; font-weight: 600; font-size: 1.05rem; }
table.cards td.title::before, table.cards td.actions::before { content: none; }
table.cards td:empty { display: none; }
table.cards td.actions { display: flex; flex-wrap: wrap; gap: .5rem; padding: .6rem 0 0; }
table.cards tr.yanked { color: var(--muted); }

.scroll { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
.scroll table { min-width: 640px; }
.scroll th, .scroll td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }

/* ---- charts ---- */

.chart-box { margin-top: .4rem; }
svg.chart { display: block; width: 100%; height: auto; }
svg.chart.wide { display: none; }
svg.chart text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--chart-text); font-variant-numeric: tabular-nums; }
svg.chart line { stroke: var(--chart-grid); }
svg.chart line.base { stroke: var(--chart-base); }
svg.chart .hit { fill: transparent; cursor: pointer; }
svg.chart .hit:hover, svg.chart .hit.on { fill: var(--chart-hover); }
.s1 { fill: var(--series-1); background: var(--series-1); }
.s2 { fill: var(--series-2); background: var(--series-2); }
.legend { display: flex; gap: .4rem 1.2rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.legend b { color: var(--ink); font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; }
.readout { display: flex; flex-wrap: wrap; gap: .2rem 1rem; margin-top: .5rem; padding: .5rem .7rem; border-radius: 8px; background: var(--code); font-size: .85rem; }
.readout:empty { display: none; }
.readout b { flex-basis: 100%; }

/* ---- pages before login, recovery codes ---- */

.narrow {
  max-width: 420px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 1.5rem) calc(env(safe-area-inset-right) + 1rem) calc(env(safe-area-inset-bottom) + 2rem) calc(env(safe-area-inset-left) + 1rem);
}
.brandline { display: flex; align-items: center; justify-content: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; margin: 0 0 1.2rem; }
.brandline img { width: 36px; height: 36px; }
.qr { display: flex; justify-content: center; margin: 1rem 0; }
.qr svg { width: 220px; height: 220px; background: #fff; border-radius: 8px; }
.share-qr { margin: .6rem 0; }
.share-qr summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.share-qr p { text-align: center; font-size: .9rem; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; font: 1rem ui-monospace, monospace; margin: 1rem 0; }
.signed-in { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---- tablets and desktops ---- */

@media (min-width: 768px) {
  header.top { padding-top: calc(env(safe-area-inset-top) + .7rem); padding-bottom: .7rem; gap: 1.5rem; }
  header.top .who { display: block; color: var(--bar-muted); font-size: .85rem; }
  header.top form { display: block; }
  header.top button { min-height: 34px; padding: .3rem .8rem; background: transparent; color: var(--bar-ink); border-color: #ffffff55; font-size: .85rem; }
  nav.tabs {
    position: static; flex: 1; display: flex; gap: 1.2rem; padding: 0;
    background: none; border: 0;
  }
  nav.tabs a { min-height: 0; flex-direction: row; font-size: .95rem; font-weight: 400; color: var(--bar-muted); }
  nav.tabs a[aria-current] { color: var(--bar-ink); font-weight: 700; }
  nav.tabs svg { display: none; }
  .brand small { display: none; }
  .only-mobile { display: none; }

  main { padding: 1.5rem 1rem 2rem; }
  .card { padding: 1.1rem 1.3rem; margin-bottom: 1.2rem; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .stat b { font-size: 1.35rem; }
  .links { grid-template-columns: max-content 1fr; align-items: center; gap: .4rem 1rem; }
  .links code { display: inline; padding: .1rem .3rem; }
  .chips { margin: 0 0 .8rem; padding: 0; flex-wrap: wrap; }
  .inline { flex-direction: row; align-items: flex-end; gap: .6rem; flex-wrap: wrap; }
  .inline > div { flex: 1; min-width: 12rem; }
  .inline button { margin: 0 0 .3rem; }

  table.cards { display: table; }
  table.cards thead { display: table-header-group; }
  table.cards tbody { display: table-row-group; }
  table.cards tr { display: table-row; padding: 0; margin: 0; border: 0; }
  table.cards td, table.cards td.title, table.cards td.actions {
    display: table-cell; position: static; padding: .45rem .5rem; min-height: 0; font-size: inherit; font-weight: inherit;
    border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: normal;
  }
  table.cards th { padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
  table.cards td::before { content: none; }
  table.cards td:empty { display: table-cell; }
  table.cards tr.yanked td { text-decoration: line-through; }
  table.cards tr.yanked td.actions { text-decoration: none; }
  table.cards td.actions form { display: inline-flex; margin: 0 .3rem .2rem 0; vertical-align: middle; }
  td.actions details.more { display: inline-block; width: auto; vertical-align: middle; }
  .scroll { margin: 0; padding: 0; }

  svg.chart.narrow { display: none; }
  svg.chart.wide { display: block; }

  .narrow { padding-top: 10vh; }
}

@media (min-width: 768px) and (pointer: fine) {
  button { min-height: 34px; padding: .3rem .8rem; font-size: .88rem; }
  td.actions button { min-height: 30px; }
  details > summary { min-height: 30px; }
  label.check { min-height: 0; }
}
