/* Mobile-first, big tap targets, readable in a bright room. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --muted: #5f5d57;
  --line: #dedad0;
  --brand: #1f5c4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --changed: #fff3c4;
  --low: #b3261e;
  --low-soft: #fbe3e1;
  --warn-soft: #fff1d6;
  --warn-ink: #7a4b00;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.25rem; }
p { margin: 0.25rem 0; }
a { color: var(--brand); }

.page { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

/* --- top bar ------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.topbar[hidden] { display: none; }
.brand { font-weight: 700; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; margin-left: auto; }
.topbar nav a {
  color: var(--brand-ink); text-decoration: none; padding: 10px 12px; border-radius: 999px;
  min-height: 44px; display: inline-flex; align-items: center; white-space: nowrap; font-weight: 600;
}
.topbar nav a.on { background: rgba(255, 255, 255, 0.2); }

@media (max-width: 520px) {
  .brand { display: none; }
  .topbar nav { margin: 0; width: 100%; justify-content: space-between; }
  .topbar nav a { padding: 10px 8px; font-size: 0.95rem; }
}

/* --- building blocks ----------------------------------------------------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.card.stack { margin-bottom: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; gap: 12px; }
.row.tight { gap: 2px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.95rem; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; min-height: 40px; }
label.check input { width: 22px; height: 22px; flex: none; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; }
legend { font-weight: 600; font-size: 0.95rem; padding: 0 4px; }

input, select, textarea {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #b9b4a8; border-radius: 8px; padding: 10px 12px; min-height: var(--tap); width: 100%;
}
input[type="checkbox"] { min-height: 0; width: auto; accent-color: var(--brand); }
input.narrow { max-width: 8rem; }
textarea { min-height: 0; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid #f0a020; outline-offset: 2px;
}

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  min-height: var(--tap); padding: 10px 16px; border-radius: 10px;
  border: 1px solid #b9b4a8; background: #fff; color: var(--ink);
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--low); border-color: #e0b4b0; }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.1rem; margin-top: 12px; }
.link { background: none; border: 0; color: var(--brand); font: inherit; text-decoration: underline; cursor: pointer; padding: 8px 0; text-align: left; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 8px; font-size: 1.15rem; min-width: 40px; min-height: 40px; cursor: pointer; color: var(--ink); }
.icon-btn:disabled { opacity: 0.3; }
.icon-btn:hover:not(:disabled) { border-color: var(--line); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  font: inherit; font-weight: 600; min-height: 44px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid #b9b4a8; background: #fff; color: var(--ink); cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.notice { background: var(--brand-soft); border-radius: 8px; padding: 10px 12px; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); font-weight: 600; }
.note { font-style: italic; color: var(--muted); margin-top: 8px; }

.tag { display: inline-block; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); margin-left: 4px; }
.tag.admin { background: #e6e1f5; color: #4a3a8a; }
.tag.viewer { background: #e4eef8; color: #2a5a8a; }
.tag.off { background: #eee; color: #777; }

.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.list-row {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; min-height: 56px;
  border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: inherit; text-align: left; width: 100%;
}
button.list-row { cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row.inactive { opacity: 0.6; }
.list-row.selected { background: var(--brand-soft); }
.tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
ul.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }

/* --- the sheet ----------------------------------------------------------- */

.sheet-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sheet { width: 100%; border-collapse: separate; border-spacing: 4px; }
.sheet th { text-align: left; font-size: 0.9rem; }
.sheet thead th { text-align: center; color: var(--muted); font-weight: 600; padding: 4px; }
.sheet tbody th { padding-right: 8px; font-weight: 600; }
.sheet td { text-align: center; }
.sheet .short { display: none; }
@media (max-width: 520px) {
  .sheet .long { display: none; }
  .sheet .short { display: inline; }
}
.sheet td.na { color: #b0aba0; font-size: 1.2rem; background: repeating-linear-gradient(45deg, #f1eee7, #f1eee7 6px, #e9e5dc 6px, #e9e5dc 12px); border-radius: 8px; }

.cell {
  width: 100%; min-width: 64px; min-height: 56px; font: inherit; font-size: 1.25rem; font-weight: 700;
  border: 2px solid #b9b4a8; border-radius: 10px; background: #fff; color: var(--ink); cursor: pointer;
}
.cell.empty { color: #aaa; border-style: dashed; }
.cell.changed { background: var(--changed); border-color: #d9b100; }

.sheet.readonly td { font-size: 1.15rem; font-weight: 700; padding: 10px 4px; background: #faf9f5; border-radius: 8px; }
.sheet.readonly td.low { background: var(--low-soft); color: var(--low); }
.sheet.readonly tbody th a { color: inherit; }
.low-key { color: var(--low); font-weight: 600; }

.sheet.setup td { background: #faf9f5; border-radius: 8px; padding: 6px; }
.cell-setup { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.cell-setup input[type="checkbox"] { width: 24px; height: 24px; }
.cell-setup .par { min-height: 36px; padding: 4px 6px; width: 5rem; text-align: center; }

.chart-box { height: 300px; padding: 8px; }

/* --- dialogs and the number pad ------------------------------------------ */

.dialog { border: 0; border-radius: 16px; padding: 0; width: min(420px, calc(100vw - 24px)); max-height: calc(100vh - 24px); color: var(--ink); background: var(--surface); }
.dialog::backdrop { background: rgba(20, 20, 18, 0.5); }
.dialog header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 0 16px; }
.dialog header h2 { margin: 0; font-size: 1.1rem; }
.dialog-body { padding: 12px 16px; }
.dialog footer { display: flex; gap: 8px; justify-content: flex-end; padding: 0 16px 16px; flex-wrap: wrap; }
.dialog footer .btn { flex: 1; }

.pad { display: flex; flex-direction: column; gap: 10px; }
.pad-display { display: block; text-align: center; font-size: 2.5rem; font-weight: 700; padding: 8px; background: #faf9f5; border-radius: 10px; min-height: 72px; }
.pad-quick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pad-quick .btn { padding: 8px 0; font-size: 1.1rem; }
.pad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pad-keys .key { min-height: 56px; font-size: 1.4rem; }

/* --- login and toast ----------------------------------------------------- */

.login { max-width: 400px; margin: 10vh auto 0; display: flex; flex-direction: column; gap: 14px; }
.login h1 { text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px; background: #1d1d1b; color: #fff;
  font-weight: 600; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); transition: transform 0.2s ease; z-index: 50; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--low); }
