/* ============================================================
 *  湯屋計時系統 v1.0 — 樣式表（assets/style.css）
 *  設計概念：卡片上緣如同湯屋門口懸掛的「暖簾」，
 *  以顏色直接表達狀態，讓櫃檯遠看也能一眼辨識。
 * ============================================================ */

/* [可客製] 色彩變數：修改此處即可更換整體配色 */
:root {
  --ink: #1e2e4a;          /* 藍染深色：標題列、主要文字 */
  --ink-soft: #4a5a74;
  --paper: #eef1ef;        /* 背景：帶一點水氣的淡灰綠 */
  --surface: #ffffff;
  --line: #d3dad6;
  --clean: #2f7a55;        /* 乾淨：苔綠 */
  --dirty: #7d6655;        /* 待掃：原木褐 */
  --use: #1b6e86;          /* 使用中：湯色藍綠 */
  --warn: #e8850c;         /* 即將到時：亮橘 */
  --over: #b3322b;         /* 時間到 */
  --radius-lg: 10px;
  --radius-sm: 6px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #6aa7c9; outline-offset: 2px; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3em;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #2b4068; }
.btn-danger { color: var(--over); border-color: #e3b9b5; }
.btn-danger:hover { background: #fbeceb; border-color: var(--over); }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.btn-ghost:hover { border-color: #fff; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 14px; }
.inline { display: inline; margin: 0; }

/* ---------- 登入與首次設定 ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-box {
  width: min(420px, 100%); background: var(--surface);
  border-top: 8px solid var(--ink); border-radius: var(--radius-lg);
  padding: 28px 26px; box-shadow: 0 10px 30px rgba(30,46,74,.12);
}
.gate-title { margin: 0 0 8px; font-size: 24px; letter-spacing: .05em; }
.gate-lead { margin: 0 0 16px; color: var(--ink-soft); }
.gate-error { background: #fbeceb; color: var(--over); padding: 8px 12px; border-radius: var(--radius-sm); }
.gate-hint { color: var(--ink-soft); }
.gate-box fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0 0 14px; padding: 10px 14px 4px; }
.gate-box legend { padding: 0 6px; font-weight: 700; }
label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--ink-soft); }
label > input, label > select, label > textarea {
  display: block; width: 100%; margin-top: 4px;
  min-height: 42px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); font-size: 16px;
}
.toolbar label > select { display: inline-block; width: auto; min-width: 120px; margin: 0 0 0 4px; }

/* ---------- 標題列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 18px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; letter-spacing: .06em; }
.brand-mark { font-size: 24px; }
.clock { font-variant-numeric: tabular-nums; font-size: 20px; letter-spacing: .04em; opacity: .9; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.role-badge { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.15); }
.role-admin { background: #c9a25a; color: #1e2e4a; }

.tabs {
  display: flex; gap: 2px; padding: 0 18px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.tab {
  border: 0; background: none; padding: 12px 14px; cursor: pointer;
  color: var(--ink-soft); border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab.is-active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }

.page { padding: 18px; padding-bottom: 90px; max-width: 1500px; margin: 0 auto; }

/* ---------- 警報列 ---------- */
.alarm-bar {
  position: sticky; top: 56px; z-index: 15;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 18px; background: var(--over); color: #fff; font-weight: 700;
  animation: alarmPulse 1s steps(2) infinite;
}
.alarm-bar .btn { background: #fff; color: var(--over); border-color: #fff; min-height: 34px; }
@keyframes alarmPulse { 50% { background: #8c211b; } }

/* ---------- 狀態統計 ---------- */
.summary { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 14px; color: var(--ink-soft); }
.summary b { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-clean { background: var(--clean); } .dot-dirty { background: var(--dirty); } .dot-in_use { background: var(--use); }

/* ---------- 看板卡片 ---------- */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.empty { color: var(--ink-soft); grid-column: 1 / -1; padding: 30px 0; text-align: center; }

.card {
  --c: var(--clean);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: 0 1px 0 var(--line), 0 6px 18px rgba(30,46,74,.07);
  overflow: hidden;
}
.card.st-dirty  { --c: var(--dirty); }
.card.st-in_use { --c: var(--use); }
.card.is-warn   { --c: var(--warn); }
.card.is-over   { --c: var(--over); }

/* 暖簾：上方為整片布面，最下緣在中央留一道開衩 */
.noren {
  position: relative; padding: 12px 14px 24px; color: #fff; text-align: center;
  background:
    linear-gradient(90deg, var(--c) calc(50% - 1.5px), rgba(255,255,255,.6) calc(50% - 1.5px) calc(50% + 1.5px), var(--c) calc(50% + 1.5px)) bottom / 100% 14px no-repeat,
    var(--c);
}
.noren-name { font-size: 20px; font-weight: 700; letter-spacing: .12em; overflow-wrap: anywhere; }
.noren-status { font-size: 13px; opacity: .92; letter-spacing: .08em; }
.card.is-over .noren { animation: overBlink 1s steps(2) infinite; }
@keyframes overBlink { 50% { filter: brightness(.78); } }

.card-body { flex: 1; padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 6px; }
.countdown {
  font-variant-numeric: tabular-nums; font-size: 44px; font-weight: 700;
  line-height: 1.05; text-align: center; letter-spacing: .02em; color: var(--c);
}
.countdown-label { text-align: center; font-size: 13px; color: var(--ink-soft); margin-top: -2px; }
.progress { height: 6px; border-radius: 3px; background: #e6ebe8; overflow: hidden; margin: 4px 0 2px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--c); transition: width .9s linear; }
.meta { font-size: 14px; color: var(--ink-soft); display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.meta dt { color: #8390a3; } .meta dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.idle { text-align: center; color: var(--ink-soft); padding: 10px 0 4px; }
.idle-big { font-size: 30px; font-weight: 700; color: var(--c); letter-spacing: .1em; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 16px; }
.card-actions .btn { flex: 1 1 auto; }
.btn-main { background: var(--c); border-color: var(--c); color: #fff; font-weight: 700; }
.btn-main:hover { filter: brightness(1.08); border-color: var(--c); }

@media (prefers-reduced-motion: reduce) {
  .alarm-bar, .card.is-over .noren { animation: none; }
  .progress > i { transition: none; }
}

/* ---------- 表格與工具列 ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar label { margin: 0; }
.toolbar-info { color: var(--ink-soft); font-size: 14px; }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 1px 0 var(--line); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid #e7ebe9; text-align: left; vertical-align: top; }
.table th { background: #f6f8f7; color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
.table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; color: #fff; }
.tag-clean { background: var(--clean); } .tag-dirty { background: var(--dirty); } .tag-in_use { background: var(--use); }
.tag-over { background: var(--over); }

/* ---------- 帳號頁 ---------- */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.box { background: var(--surface); border-radius: var(--radius-lg); padding: 18px; box-shadow: 0 1px 0 var(--line); }
.box h2 { margin: 0 0 12px; font-size: 17px; }
.muted { color: var(--ink-soft); font-size: 14px; margin: 10px 0 4px; }
.url { display: block; padding: 8px 10px; background: #f3f5f4; border-radius: var(--radius-sm); font-size: 13px; overflow-wrap: anywhere; user-select: all; }

/* ---------- 對話視窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: 16px; background: rgba(20,30,48,.5);
}
.modal-card {
  width: min(460px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-lg); padding: 22px;
  border-top: 6px solid var(--ink);
}
.modal-card h2 { margin: 0 0 14px; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.presets .btn.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { color: var(--over); min-height: 1.4em; margin: 4px 0 0; font-size: 14px; }
.confirm-text { white-space: pre-line; }

/* ---------- 音效提示與訊息 ---------- */
.sound-gate {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  width: min(640px, calc(100% - 24px)); padding: 12px 16px;
  background: #fff7e8; border: 2px solid var(--warn); border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0,0,0,.15); font-size: 14px;
}
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60;
  max-width: calc(100% - 24px); padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.is-error { background: var(--over); }

@media (max-width: 600px) {
  .page { padding: 12px; }
  .topbar { position: static; gap: 8px; padding: 8px 12px; }
  .brand-name { font-size: 16px; }
  .clock { font-size: 16px; }
  .countdown { font-size: 38px; }
  .board { grid-template-columns: 1fr 1fr; gap: 10px; }
  .noren-name { font-size: 17px; letter-spacing: .05em; }
  .card-body { padding: 10px; } .card-actions { padding: 8px 10px 12px; }
  .alarm-bar { top: 0; }
}
@media (max-width: 380px) { .board { grid-template-columns: 1fr; } }
