/* FixDesk 電腦維修助理 —— 畫面樣式（淺色／深色都有） */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #dde1e6;
  --text: #1d2329;
  --muted: #69737d;
  --accent: #1f5fbf;
  --accent-soft: #e5eefb;
  --good: #1d7a46;
  --good-soft: #e3f4ea;
  --warn: #a35a00;
  --warn-soft: #fdf0dc;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --surface: #1e2227;
    --surface-2: #262b31;
    --line: #353b43;
    --text: #e6e9ec;
    --muted: #98a2ad;
    --accent: #6ea4f0;
    --accent-soft: #1f3150;
    --good: #5cc98a;
    --good-soft: #1b3326;
    --warn: #f0b155;
    --warn-soft: #3a2c14;
    --bad: #f08a80;
    --bad-soft: #3d1f1d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Microsoft JhengHei UI", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); font-size: 14px; }
.grow { flex: 1; }
[hidden] { display: none !important; }

/* ---------- 按鈕與輸入 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 36px; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 15px; }
label.chk { flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
label.chk input { width: auto; min-height: 0; }

/* ---------- 登入 ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 26px; }
.login-logo { width: 96px; height: 96px; justify-self: center; }
.login-card:not(.pin-card) h1, .login-card:not(.pin-card) > p.muted { text-align: center; }
.login-card p { margin: -10px 0 4px; }

/* ---------- PIN 解鎖 ---------- */
.pin-card { text-align: center; justify-items: center; }
.pin-dots { display: flex; gap: 12px; justify-content: center; min-height: 18px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 10px; justify-content: center; }
.pin-pad button {
  height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); font: inherit; font-size: 22px; cursor: pointer;
}
.pin-pad button:active { background: var(--accent-soft); }
.pin-pad button.ok { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 頁首 ---------- */
.top-actions { display: flex; gap: 6px; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 18px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand img { width: 30px; height: 30px; }
.brand span { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 8px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button {
  border: 0; background: none; font: inherit; color: var(--muted); padding: 8px 14px;
  border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
main { max-width: 1280px; margin: 0 auto; padding: 8px 20px 60px; }

/* ---------- 總覽 ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.tile .k { font-size: 13px; color: var(--muted); }
.tile .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.alerts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.alert {
  display: flex; align-items: center; gap: 12px; text-align: left; font: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--text);
}
.alert:hover { border-color: var(--accent); }
.alert .n { font-size: 22px; font-weight: 700; min-width: 34px; font-variant-numeric: tabular-nums; }
.alert.zero { opacity: .55; }
.alert.bad .n { color: var(--bad); }
.alert.warn .n { color: var(--warn); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.log { display: grid; grid-template-columns: auto auto 1fr; gap: 4px 12px; font-size: 13px; margin-top: 10px; }
.log .ok { color: var(--good); }
.log .no { color: var(--bad); }

/* ---------- 工具列與表格 ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px 0 12px; }
.toolbar input[type=search] { flex: 1 1 260px; width: auto; }
.toolbar select { width: auto; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr.click { cursor: pointer; }
table.list tbody tr.click:hover { background: var(--surface-2); }
table.list.compact th, table.list.compact td { padding: 6px 10px; font-size: 14px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { font-size: 12px; color: var(--muted); }
.neg { color: var(--bad); font-weight: 700; }
.inactive td { opacity: .5; }
.tag {
  display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 99px; margin: 1px 2px 1px 0;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.info { background: var(--accent-soft); color: var(--accent); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- 市價查詢 ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.results { display: grid; gap: 6px; }
.res {
  display: flex; gap: 10px; align-items: flex-start; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.res .nm { flex: 1; min-width: 0; word-break: break-word; }
.res .pr { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 700; }
.res .pr s { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.res .act { display: flex; flex-direction: column; gap: 4px; }

/* ---------- 面板 ---------- */
dialog.panel {
  border: 0; padding: 0; margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(760px, 100vw);
  max-width: 100vw; background: var(--bg); color: var(--text); box-shadow: -4px 0 24px rgba(0, 0, 0, .2);
}
dialog.panel.narrow { width: min(640px, 100vw); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.panel-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; flex: 1; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-body { padding: 8px 20px 40px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 12px; }
.grid-form.compact { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); align-items: end; }
.grid-form .span2 { grid-column: 1 / -1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); font: inherit; padding: 6px 16px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.link-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.link-card .hd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.link-card .hd b { min-width: 52px; }
.link-card .nm { font-size: 13px; color: var(--muted); margin-top: 4px; word-break: break-word; }
.link-card .pr { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.spark { display: block; width: 100%; height: 44px; margin-top: 6px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.spark circle { fill: var(--accent); }
.spark-note { margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px;
  max-width: calc(100vw - 32px);
}

/* ---------- 手機 ---------- */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 6px 10px; padding: 8px 16px; }
  .brand span { display: none; }
  .top-actions { margin-left: auto; }
  .tabs { order: 3; flex-basis: 100%; }
  main, .panel-body { padding-left: 16px; padding-right: 16px; }
  .panel-head { padding: 10px 16px; }
  .two-col { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr; }
  /* 庫存表改成一張張卡片 */
  #itemTable thead { display: none; }
  #itemTable, #itemTable tbody, #itemTable tr, #itemTable td { display: block; }
  #itemTable tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  #itemTable td { border: 0; padding: 1px 0; text-align: left !important; }
  #itemTable td[data-l]::before { content: attr(data-l) "　"; color: var(--muted); font-size: 13px; }
  #itemTable td.num { display: inline-block; margin-right: 14px; }
}
