/* 水電派工系統：共用樣式
   色彩：冷灰紙面、施工藍（操作）、電工黃（待施工）、完工綠 */
:root {
  --ink: #18222d;
  --ink-soft: #4b5866;
  --paper: #e8edf1;
  --sheet: #fafbfc;
  --line: #c9d3db;
  --line-soft: #dde4ea;
  --water: #1d5a9e;
  --water-dark: #15457b;
  --water-tint: #e3ecf6;
  --amber: #e2a11a;
  --amber-tint: #fbf1d9;
  --done: #2c7353;
  --done-tint: #e1f0e8;
  --danger: #b0281f;
  --danger-tint: #fbe7e5;
  --radius-sm: 6px;
  --radius: 10px;
  --font: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--water); }
:focus-visible { outline: 3px solid var(--water); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 頁首 ── */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px max(16px, calc((100vw - 1080px) / 2));
  background: var(--ink); color: #eef2f5;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 900; font-size: 19px; letter-spacing: 1px; }
.brand-mark { width: 14px; height: 22px; background: linear-gradient(var(--amber) 0 50%, #5b9be0 50% 100%); border-radius: 3px; }
.topnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topnav a { color: #c9d4de; text-decoration: none; padding: 6px 12px; border-radius: var(--radius-sm); font-weight: 500; }
.topnav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topnav a[aria-current='page'] { color: #fff; background: rgba(255, 255, 255, .14); }
.who { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.who-name { font-weight: 700; }
.role-tag { font-size: 13px; padding: 1px 8px; border-radius: 99px; background: rgba(255, 255, 255, .14); }
.btn-ghost { background: none; border: 1px solid rgba(255, 255, 255, .35); color: #eef2f5; border-radius: var(--radius-sm); padding: 4px 12px; font: inherit; cursor: pointer; }
.btn-ghost:hover { border-color: #fff; }

/* ── 版面 ── */
main { max-width: 1080px; margin: 0 auto; padding: 28px 16px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
h1 { font-size: 28px; font-weight: 900; margin: 0; line-height: 1.25; }
h2 { font-size: 19px; font-weight: 700; margin: 0 0 12px; }
.sub { color: var(--ink-soft); margin: 4px 0 0; }

/* ── 按鈕與表單 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 20px; border-radius: var(--radius-sm);
  border: 1px solid var(--water); background: var(--water); color: #fff;
  font: 700 16px/1 var(--font); text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--water-dark); border-color: var(--water-dark); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-line { background: var(--sheet); color: var(--water); }
.btn-line:hover { background: var(--water-tint); color: var(--water-dark); }
.btn-done { background: var(--done); border-color: var(--done); }
.btn-done:hover { background: #215a41; border-color: #215a41; }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 15px; }
.btn-danger-line { background: var(--sheet); color: var(--danger); border-color: var(--danger); }
.btn-danger-line:hover { background: var(--danger-tint); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 15px; }
.field .hint { color: var(--ink-soft); font-size: 14px; }
.req { color: var(--danger); font-weight: 700; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--water); box-shadow: 0 0 0 3px var(--water-tint); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

.msg { margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 500; }
.msg-error { background: var(--danger-tint); color: var(--danger); }
.msg-ok { background: var(--done-tint); color: var(--done); }

.panel { background: var(--sheet); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 24px; }

/* ── 工單卡：本系統的主角 ── */
.tickets { display: grid; gap: 12px; }
.ticket {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 20px; align-items: start;
  padding: 16px 20px 16px 28px; background: var(--sheet);
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  color: inherit; text-decoration: none;
}
.ticket::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; border-radius: var(--radius) 0 0 var(--radius); background: var(--amber); }
.ticket.is-completed::before { background: var(--done); }
.ticket:hover { border-color: var(--water); }
.ticket-no { font-weight: 900; font-size: 22px; letter-spacing: .5px; line-height: 1.2; white-space: nowrap; }
.ticket-main { min-width: 0; }
.ticket-customer { font-weight: 700; font-size: 18px; }
.ticket-addr { color: var(--ink-soft); }
.ticket-desc { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ticket-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ticket-metas { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.ticket-meta { color: var(--ink-soft); font-size: 14px; white-space: nowrap; }

.status { display: inline-block; font-size: 14px; font-weight: 700; padding: 2px 10px; border-radius: 99px; white-space: nowrap; }
.status-assigned { background: var(--amber-tint); color: #7a5300; }
.status-completed { background: var(--done-tint); color: var(--done); }

/* ── 列表工具列 ── */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.tabs { display: flex; background: var(--sheet); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 3px; }
.tabs button { border: 0; background: none; font: 500 15px var(--font); padding: 7px 14px; border-radius: 4px; cursor: pointer; color: var(--ink-soft); min-height: 38px; }
.tabs button[aria-pressed='true'] { background: var(--ink); color: #fff; }
.search { flex: 1; min-width: 200px; }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-soft); background: var(--sheet); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 0 16px; }
.summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.summary div { background: var(--sheet); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px 18px; }
.summary b { display: block; font-size: 22px; font-weight: 900; }
.summary span { color: var(--ink-soft); font-size: 14px; }

/* ── 單筆頁 ── */
.detail { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.big-no { font-size: 40px; font-weight: 900; letter-spacing: 1px; line-height: 1.1; }
.facts { display: grid; grid-template-columns: 7em 1fr; gap: 10px 16px; margin: 0; }
.facts dt { color: var(--ink-soft); font-weight: 500; }
.facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.facts .amount { font-weight: 900; font-size: 20px; color: var(--done); }
.stack { display: grid; gap: 20px; }

.notes { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 12px; }
.note { border-left: 3px solid var(--line); padding: 2px 0 2px 14px; }
.note.by-worker { border-left-color: var(--amber); }
.note.by-office { border-left-color: var(--water); }
.note-head { display: flex; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--ink-soft); }
.note-head b { color: var(--ink); }
.note-body { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.complete-box { border: 2px solid var(--done); background: var(--done-tint); }
.complete-box h2 { color: var(--done); }

/* ── 帳號管理 ── */
.users { width: 100%; border-collapse: collapse; background: var(--sheet); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.users th, .users td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.users th { font-size: 14px; color: var(--ink-soft); font-weight: 500; background: var(--paper); }
.users tr.is-off td { color: var(--ink-soft); }
.users .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

dialog { border: 0; border-radius: var(--radius); padding: 24px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(24, 34, 45, .3); }
dialog::backdrop { background: rgba(24, 34, 45, .45); }

/* ── 登入頁 ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(400px, 100%); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand .brand-mark { width: 18px; height: 30px; }
.login-brand h1 { font-size: 30px; }
.login form { display: grid; gap: 16px; }
.login .btn { width: 100%; }
.login-foot { margin-top: 20px; color: var(--ink-soft); font-size: 14px; }

/* ── 手機 ── */
@media (max-width: 720px) {
  .topbar { gap: 10px 16px; }
  .topnav { order: 3; flex-basis: 100%; }
  .who { margin-left: auto; }
  main { padding-top: 20px; }
  .ticket { grid-template-columns: 1fr auto; padding-left: 24px; gap: 6px 12px; }
  .ticket-no { grid-column: 1; grid-row: 1; }
  .ticket-side { display: contents; }
  .ticket-side .status { grid-column: 2; grid-row: 1; justify-self: end; align-self: center; }
  .ticket-main { grid-column: 1 / -1; grid-row: 2; }
  .ticket-metas { grid-column: 1 / -1; grid-row: 3; flex-direction: row; flex-wrap: wrap; gap: 4px 16px; align-items: center; padding-top: 6px; border-top: 1px dashed var(--line-soft); }
  .detail { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 5.5em 1fr; }
  .big-no { font-size: 32px; }
  .users thead { display: none; }
  .users, .users tbody, .users tr, .users td { display: block; width: 100%; }
  .users tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .users td { border: 0; padding: 4px 14px; }
  .users .actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
