/*
 * Tool Library styles. Mobile first: everything is sized for a thumb
 * (tap targets at least 48px tall) and widens gently on bigger screens.
 * Colors are defined once at the top and swapped for dark mode.
 */
:root {
  color-scheme: light;
  --bg: #F6F3EF; --surface: #FFFFFF; --surface-2: #EFEAE4; --ink: #1E1914; --muted: #6A6158; --line: #E0D9D0;
  --accent: #C2410C; --accent-ink: #FFFFFF; --accent-soft: #FCE6DA;
  --ok: #15803D; --ok-soft: #DDF5E4;
  --warn: #92400E; --warn-soft: #FDF0D5;
  --danger: #B91C1C; --danger-soft: #FDE2E2;
  --shadow: 0 1px 2px rgba(30,25,20,.06), 0 8px 24px -16px rgba(30,25,20,.3);
  --radius: 14px;
  --tab-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #16130F; --surface: #211C17; --surface-2: #2C261F; --ink: #F3EEE8; --muted: #A99F94; --line: #3A322A;
    --accent: #FB8B4E; --accent-ink: #1C0E05; --accent-soft: #43261A;
    --ok: #5BD68A; --ok-soft: #173424;
    --warn: #F5B955; --warn-soft: #3A2C12;
    --danger: #FF7B7B; --danger-soft: #401D1D;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -18px rgba(0,0,0,.9);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.45;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 24px);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 8px 0 16px; }
h2 { font-size: 1.1rem; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }

/* ---------- Header and page ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.1rem; color: var(--ink); text-decoration: none; min-height: 36px; }
.brand img { border-radius: 7px; }
.page { max-width: 640px; margin: 0 auto; padding: 16px; }

/* ---------- Cards and lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card.narrow { max-width: 420px; margin: 8vh auto 16px; }
.card-title { font-size: 1.1rem; font-weight: 700; margin: 0 0 12px; }
details.card > summary { cursor: pointer; list-style: none; min-height: 32px; display: flex; align-items: center; justify-content: space-between; margin: 0; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "+"; font-size: 1.5rem; color: var(--muted); }
details.card[open] > summary { margin-bottom: 12px; }
details.card[open] > summary::after { content: "–"; }

.list { list-style: none; padding: 0; }
.list.card { padding: 0 16px; }
.item { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item-main { flex: 1 1 220px; display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); vertical-align: 2px;
}
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font-size: 16px; /* 16px stops iPhones zooming in on focus */
  font-weight: 400; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.optional { font-weight: 400; color: var(--muted); font-size: .85rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .88rem; margin: 0; }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.code-input { font-size: 1.6rem !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.login-logo { display: block; border-radius: 14px; margin-bottom: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font-weight: 650; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: .95rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- Messages ---------- */
.msg { padding: 12px 14px; border-radius: 10px; margin: 14px 0 0; }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.warn { background: var(--warn-soft); color: var(--warn); }
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 20; margin: 0 auto; max-width: 480px;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 12px);
  padding: 14px 16px; border-radius: 12px; font-weight: 600;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Bottom tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(var(--tabs, 3), 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--tab-h); color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 650;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--accent); }
