/* 由 GAS 版 mod_styles.html 移植；配色與版面維持一致 */
/*
   * 配色沿用既有營運中心的視覺：米色底、深藍頂列、橘色重點。
   * 刻意只做淺色一套——這是內部營運工具，與既有系統並排使用時
   * 顏色跟著使用者的系統偏好變反而不一致。
   */
  :root {
    --bg: #f1eee4;
    --surface: #ffffff;
    --surface-alt: #faf8f2;
    --topbar: #1b2b33;
    --dark-card: #22343c;
    --accent: #e8672c;
    --accent-hover: #cf551c;
    --ink: #17272e;
    --muted: #6d7c83;
    --line: #e4dfd2;
    --line-strong: #d3ccbb;
    --ok: #2f9e6a;
    --danger: #d64545;
    --radius: 14px;
  }

  * { box-sizing: border-box; }

  html, body { height: 100%; }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
                 "PingFang TC", "Microsoft JhengHei", sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  .hidden { display: none !important; }

  /* ===== 頂列 ===== */

  .topbar {
    background: var(--topbar);
    color: #fff;
    padding: 14px 0;
  }
  .topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
  .brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
  .brand-logo {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(140deg, var(--accent), #a53c8e);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; color: #fff;
    flex: none;
  }
  .brand-name {
    font-size: 17px; font-weight: 700; letter-spacing: .3px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .topbar-right { display: flex; align-items: center; gap: 10px; }
  .who { text-align: right; line-height: 1.35; min-width: 0; }
  .who-name { font-size: 14px; font-weight: 700; }
  .who-meta { font-size: 12px; color: #a8b6bc; }

  .chip {
    padding: 7px 15px;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 13.5px; font-weight: 600; font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
  }
  .chip:hover { background: rgba(255,255,255,.12); }
  .chip-active { background: #fff; color: var(--topbar); border-color: #fff; }

  /* ===== 版面 ===== */

  .shell { max-width: 1180px; margin: 0 auto; padding: 26px 20px 60px; }

  /* ===== 分頁列 ===== */

  .tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }

  .tab {
    padding: 9px 16px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 14.5px; font-weight: 600; font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
  }
  .tab:hover { background: var(--surface-alt); }
  .tab-active { background: var(--topbar); color: #fff; }
  .tab-active:hover { background: var(--topbar); }

  /* ===== 麵包屑與標題 ===== */

  .crumb {
    margin: 20px 0 0;
    font-size: 13px;
    color: var(--muted);
  }
  .crumb span + span::before { content: '›'; margin: 0 9px; color: var(--line-strong); }

  .eyebrow {
    margin: 22px 0 6px;
    font-size: 12.5px; font-weight: 700;
    letter-spacing: .16em;
    color: var(--accent);
    text-transform: uppercase;
  }
  h1.page-title {
    margin: 0 0 10px;
    font-size: 40px; font-weight: 800;
    letter-spacing: -.01em;
    line-height: 1.15;
  }
  .page-lead { margin: 0 0 26px; font-size: 15px; color: var(--muted); max-width: 62ch; }

  @media (max-width: 640px) {
    h1.page-title { font-size: 29px; }
    .shell { padding: 20px 14px 48px; }
    .who-meta { display: none; }
  }

  /* ===== 卡片 ===== */

  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px 24px;
  }
  .card + .card { margin-top: 16px; }
  .card-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
  }
  .card h2 { margin: 0 0 3px; font-size: 17px; font-weight: 700; }
  .card .hint { margin: 0; font-size: 13.5px; color: var(--muted); }

  .card-dark {
    background: var(--dark-card);
    border-color: var(--dark-card);
    color: #fff;
  }
  .card-dark h2 { color: #fff; }
  .card-dark .hint { color: #9fb0b7; }

  /* ===== 按鈕 ===== */

  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    padding: 12px 20px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-size: 15px; font-weight: 600; font-family: inherit;
    text-decoration: none; cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .btn:hover { border-color: var(--muted); }
  .btn[aria-disabled="true"] { opacity: .55; }
  .btn-primary {
    background: var(--accent); border-color: var(--accent); color: #fff;
  }
  .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn-block { display: flex; width: 100%; }
  .btn-block + .btn-block { margin-top: 12px; }
  .btn-sm { padding: 7px 14px; font-size: 13px; font-weight: 600; }
  .btn-danger { color: var(--danger); }
  .btn-danger:hover { border-color: var(--danger); }

  /* ===== 訊息 ===== */

  .msg {
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 13.5px;
    margin-bottom: 16px;
    white-space: pre-wrap;
  }
  .msg-error { background: #fdecec; border-color: #f4c9c9; color: #a62c2c; }
  .msg-ok    { background: #e8f6ee; border-color: #bfe4d0; color: #1d7a4f; }
  .msg-info  { background: var(--surface-alt); border-color: var(--line); color: var(--muted); }
  .msg-warn  { background: #fdf3e3; border-color: #f0dcb4; color: #96631a; }

  /* ===== 其他元件 ===== */

  .spinner {
    width: 16px; height: 16px;
    border: 2px solid var(--line-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex: none;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .loading-row {
    display: flex; align-items: center; gap: 12px;
    color: var(--muted); font-size: 14px;
  }

  .kv {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 10px 16px;
    font-size: 14px;
    margin: 0;
  }
  .kv dt { color: var(--muted); }
  .kv dd { margin: 0; font-weight: 600; }

  .device {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 14px 0;
    border-top: 1px solid var(--line);
    font-size: 14px;
  }
  .device-name { font-weight: 700; }
  .device-meta { color: var(--muted); font-size: 12.5px; }

  .badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px; font-weight: 700;
  }
  .badge-off { background: #eeeae0; color: var(--muted); }

  /* 尚未開發的分頁 */
  .placeholder {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-alt);
    padding: 40px 26px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
  }
  .placeholder strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

  /* ===== 戰況：篩選列與數據 ===== */

  .filters {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 18px;
  }
  .field { display: flex; flex-direction: column; gap: 5px; }
  .field label { font-size: 12px; font-weight: 600; color: var(--muted); }
  .field select, .field input {
    padding: 9px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px; font-family: inherit;
    min-height: 40px;
  }

  .segmented { display: flex; gap: 3px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; padding: 3px; }
  .segmented button {
    padding: 7px 15px; border: 0; border-radius: 7px;
    background: transparent; color: var(--ink);
    font-size: 13.5px; font-weight: 600; font-family: inherit; cursor: pointer;
  }
  .segmented button.on { background: var(--topbar); color: #fff; }

  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
  }
  .stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
  }
  .stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
  .stat-value { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin-top: 3px; line-height: 1.15; }
  .stat-value .unit { font-size: 14px; font-weight: 700; color: var(--muted); margin-right: 3px; }
  .stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
  .stat-hero { background: var(--dark-card); border-color: var(--dark-card); color: #fff; }
  .stat-hero .stat-label, .stat-hero .stat-sub { color: #9fb0b7; }
  .neg { color: var(--danger); }

  .table-wrap { overflow-x: auto; margin: 0 -4px; }
  table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 460px; }
  table.data th, table.data td { padding: 10px 12px; text-align: right; white-space: nowrap; }
  table.data th:first-child, table.data td:first-child { text-align: left; white-space: normal; min-width: 140px; }
  table.data thead th {
    font-size: 12px; color: var(--muted); font-weight: 700;
    border-bottom: 1px solid var(--line-strong);
  }
  table.data tbody tr + tr td { border-top: 1px solid var(--line); }
  table.data tbody tr:hover { background: var(--surface-alt); }
  .num { font-variant-numeric: tabular-nums; }

  /* 查詢中：內容變淡但留在原地，頂端跑一條進度條。
     整塊清空再重畫會讓畫面跳動，反而更像壞掉。 */
  .is-loading { opacity: .45; pointer-events: none; transition: opacity .15s; }

  .loading-bar {
    height: 3px;
    border-radius: 3px;
    background: var(--line);
    overflow: hidden;
    margin-bottom: 14px;
    position: relative;
  }
  .loading-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 40%;
    background: var(--accent);
    border-radius: 3px;
    animation: slide 1s ease-in-out infinite;
  }
  @keyframes slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
  }

  /* 門市選擇對話框 */
  .picker-actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
  }
  .picker-count { font-size: 13.5px; font-weight: 600; color: var(--muted); }

  .picker-list {
    max-height: 46vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
  }
  .picker-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 11px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    font-size: 14px; font-family: inherit;
    text-align: left;
    cursor: pointer;
  }
  .picker-item:last-child { border-bottom: 0; }
  .picker-item:hover { background: var(--surface-alt); }
  .picker-item.on { font-weight: 700; }
  .picker-check {
    width: 20px; height: 20px;
    flex: none;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    font-size: 13px; line-height: 1;
    color: #fff;
  }
  .picker-item.on .picker-check { background: var(--accent); border-color: var(--accent); }

  /* ===== 設定對話框 ===== */

  /*
   * 用 position:fixed 覆蓋整個檢視區。開啟時同時鎖住 body 捲動，
   * 否則背景內容會跟著滑動，在手機上會很錯亂。
   */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(18, 30, 36, .55);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 32px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: modal-fade .15s ease-out;
  }
  @keyframes modal-fade { from { opacity: 0; } }

  .modal {
    width: 100%;
    max-width: 540px;
    background: var(--bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 26px 64px rgba(0, 0, 0, .34);
    animation: modal-rise .2s cubic-bezier(.2, .8, .3, 1);
  }
  @keyframes modal-rise { from { transform: translateY(14px); opacity: 0; } }

  .modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 17px 20px;
    background: var(--topbar);
    color: #fff;
  }
  .modal-title { font-size: 16.5px; font-weight: 700; }
  .modal-sub { font-size: 12.5px; color: #a8b6bc; margin-top: 1px; }

  .modal-close {
    width: 32px; height: 32px;
    flex: none;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 19px; line-height: 1; font-family: inherit;
    cursor: pointer;
    transition: background .15s;
  }
  .modal-close:hover { background: rgba(255,255,255,.14); }

  .modal-body { padding: 18px; }
  .modal-body .card { border-color: var(--line); }

  body.modal-open { overflow: hidden; }

  @media (max-width: 640px) {
    .modal-backdrop { padding: 0; }
    .modal { max-width: none; min-height: 100%; border-radius: 0; }
  }

  /* ===== 登入頁 ===== */

  .login-wrap { max-width: 430px; margin: 0 auto; padding: 56px 20px 40px; }
  .login-brand { text-align: center; margin-bottom: 26px; }
  .login-brand .brand-logo { width: 52px; height: 52px; font-size: 21px; margin: 0 auto 14px; }
  .login-brand h1 { margin: 0 0 4px; font-size: 23px; font-weight: 800; }
  .login-brand p { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: .06em; }

  .divider {
    display: flex; align-items: center; gap: 12px;
    margin: 18px 0; color: var(--muted); font-size: 12.5px;
  }
  .divider::before, .divider::after {
    content: ''; flex: 1; height: 1px; background: var(--line);
  }
