:root {
  --brand: #0b7a3e;
  --brand-dark: #075c2e;
  --brand-soft: #e7f4ec;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --danger: #d70015;
  --danger-soft: #fdecee;
  --warn: #b25000;
  --warn-soft: #fff4e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC",
    "Microsoft JhengHei", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 19px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* 版面 */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: rgba(255, 255, 255, .8);
  backdrop-filter: saturate(180%) blur(20px); border-right: 1px solid var(--line);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 17px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 15px;
}
.nav-group { font-size: 12px; color: var(--muted); padding: 14px 10px 4px; }
.nav a {
  display: block; padding: 7px 10px; border-radius: 8px; color: var(--text); font-size: 14.5px;
}
.nav a:hover { background: #f0f0f2; text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.sidebar-foot { margin-top: 18px; padding: 12px 10px; border-top: 1px solid var(--line); font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1200px; }
.topbar { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

/* 卡片與表格 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.two-col { grid-template-columns: 1fr 1fr; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 500; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafafa; }
tr.inactive td { color: var(--muted); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--brand-soft); color: var(--brand-dark); }
.badge.gray { background: #f0f0f2; color: var(--muted); }
.badge.orange { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

/* 表單 */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11, 122, 62, .15); }
input[type="checkbox"] { width: auto; margin-right: 6px; }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.check { display: flex; align-items: center; color: var(--text); font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500;
  padding: 9px 18px; border-radius: 999px; border: none; cursor: pointer; background: var(--brand);
  color: #fff; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: #e8e8ed; color: var(--text); }
.btn.secondary:hover { background: #dcdce1; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.link { background: none; color: var(--brand); padding: 4px 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { max-width: 280px; }
.tabs { display: inline-flex; background: #e8e8ed; border-radius: 10px; padding: 3px; }
.tabs button { border: none; background: none; font: inherit; font-size: 14px; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--text); }
.tabs button.active { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); font-weight: 600; }

.items-table input, .items-table select { padding: 7px 9px; }
.items-table td { padding: 6px; }
.totals { margin-left: auto; max-width: 300px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-size: 20px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

.ai-box { border: 1.5px dashed #9fcfb2; background: #f6fbf8; }
.photo-preview { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; margin-top: 8px; }
.ship-photo { max-width: 100%; max-height: 420px; border-radius: 10px; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar .fill { width: 100%; max-width: 44px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar .lbl { font-size: 12px; color: var(--muted); }
.bar .val { font-size: 11px; color: var(--muted); white-space: nowrap; }

dialog {
  border: none; border-radius: 18px; padding: 0; width: min(640px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(0, 0, 0, .3); backdrop-filter: blur(2px); }
.dialog-body { padding: 24px; max-height: 80vh; overflow-y: auto; }

/* 登入頁 */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; font-size: 22px; padding-bottom: 8px; }

.info-list { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14.5px; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1d1d1f; color: #fff;
  padding: 10px 20px; border-radius: 999px; font-size: 14px; z-index: 100; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

/* 對帳單列印 */
.statement h1 { font-size: 22px; }
@media print {
  .sidebar, .topbar, .no-print, .page-head .actions { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; padding: 0; }
}

/* 手機 */
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s;
    background: #fff; box-shadow: 0 0 40px rgba(0, 0, 0, .15);
  }
  .sidebar.open { transform: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; padding: 10px 16px;
    background: rgba(255, 255, 255, .85); backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--line);
    font-weight: 700;
  }
  .topbar button { border: none; background: none; font-size: 22px; padding: 2px 6px; cursor: pointer; }
  .main { padding: 18px 16px 60px; }
  .two-col { grid-template-columns: 1fr; }
  h1 { font-size: 24px; }
}
