:root {
  --ink: #0f2231;
  --ink-soft: #44606e;
  --muted: #7f97a1;
  --ice: #eef5f6;
  --ice-2: #e3eef0;
  --surface: #ffffff;
  --line: #d8e5e8;
  --glacial: #0b6e7d;
  --glacial-deep: #0a5663;
  --glacial-bright: #2fa6b8;
  --ok: #1f9c6b;
  --ok-bg: #e3f4ec;
  --pending: #c07a14;
  --pending-bg: #fbeed6;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 34, 49, .06), 0 8px 24px rgba(15, 34, 49, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", "Noto Sans TC", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 100% -10%, #dff0f2 0%, transparent 60%),
    var(--ice);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--glacial); text-decoration: none; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 28px; height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--glacial-bright), var(--glacial-deep));
  display: inline-block; align-self: center;
  box-shadow: 0 0 0 4px rgba(47, 166, 184, .15);
}
.brand-mark.big { width: 20px; height: 20px; box-shadow: 0 0 0 6px rgba(47, 166, 184, .15); }
.brand-name { font-weight: 700; letter-spacing: .14em; font-size: 18px; }
.brand-sub { color: var(--muted); font-size: 13px; letter-spacing: .05em; }

.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a {
  color: var(--ink-soft); padding: 8px 14px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--ice-2); }
.nav a.active { color: var(--glacial-deep); background: var(--ice-2); }

.account { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.who { font-size: 13px; color: var(--ink-soft); }
.logout { font-size: 13px; color: var(--muted); }
.logout:hover { color: var(--danger); }
.bell { font-size: 18px; text-decoration: none; line-height: 1; filter: grayscale(15%); }
.bell.active, .bell:hover { filter: none; }

/* ---- Layout ---- */
.container { max-width: 1120px; margin: 0 auto; padding: 28px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.page-head .muted { font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---- Stat cards ---- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.card.stat { padding: 20px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.card.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(var(--glacial-bright), var(--glacial-deep));
}
.card.stat.warn::before { background: linear-gradient(#e7b85c, var(--pending)); }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat-meta { font-size: 12px; color: var(--ink-soft); }

/* ---- Charts ---- */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-card { padding: 18px 20px; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; color: var(--ink-soft); }

/* ---- Tables ---- */
.table-card { padding: 0; overflow: hidden; }
.table-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.table-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--ice-2); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #f7fafb; letter-spacing: .03em; }
tbody tr:hover { background: #f9fcfc; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; }
td.empty { text-align: center; color: var(--muted); padding: 36px; }

/* ---- Tags ---- */
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.pending { background: var(--pending-bg); color: var(--pending); }
.tag.warn { background: #fdf0e3; color: #b9772b; }
.tag.as-btn { border: none; cursor: pointer; font-family: inherit; }
.ship-sel { font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; font-family: inherit; }
.ship-sel.ship-shipped { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.ship-sel.ship-partial { background: #fdf0e3; color: #b9772b; border-color: transparent; }
.ship-sel.ship-unshipped { background: var(--pending-bg); color: var(--pending); border-color: transparent; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 9px; padding: 9px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: background .15s, border-color .15s;
}
.btn.primary { background: var(--glacial); color: #fff; }
.btn.primary:hover { background: var(--glacial-deep); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink-soft); }
.btn.ghost:hover { border-color: var(--glacial-bright); color: var(--glacial-deep); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.link-danger { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; font-family: inherit; }
.link-danger:hover { color: var(--danger); }
.as-btn { padding: 0; }
.inline { display: inline; margin: 0; }
.inline-row { display: flex; gap: 6px; align-items: center; }
.inline-row input { width: 120px; }

/* ---- Forms ---- */
.form-card { padding: 0 20px; margin-bottom: 16px; }
.form-card > summary {
  cursor: pointer; padding: 16px 0; font-weight: 600; color: var(--glacial-deep);
  list-style: none;
}
.form-card > summary::-webkit-details-marker { display: none; }
.record-form { padding-bottom: 20px; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid .span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 10px; }
input, select {
  font-family: inherit; font-size: 14px; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--glacial-bright); box-shadow: 0 0 0 3px rgba(47, 166, 184, .15); }
.form-actions { margin-top: 16px; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; margin-bottom: 16px; }
.filter-bar input[name="q"] { flex: 1 1 200px; }
.filter-bar .dash { color: var(--muted); }

/* ---- Alerts ---- */
.alert { padding: 12px 16px; border-radius: 9px; font-size: 14px; margin-bottom: 16px; }
.alert.error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c0; }

/* ---- Login ---- */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px;
}
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); padding: 36px 32px; }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { margin: 12px 0 2px; letter-spacing: .16em; font-size: 24px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .cards { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr 1fr; }
  .grid .span2 { grid-column: span 2; }
  .brand-sub, .who { display: none; }
  .container { padding: 18px 14px; }

  /* 導覽列改兩行:第一行 logo + 登出,第二行選單可橫向滑 */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    gap: 8px 14px;
    padding: 10px 14px;
  }
  .nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; flex: 0 0 auto; }

  /* 防止任何元件把頁面撐寬 */
  input, select, textarea, canvas { max-width: 100%; }

  /* 手機版文字放大 */
  body { font-size: 17px; }
  .nav a { font-size: 16px; padding: 8px 12px; }
  .page-head h1 { font-size: 27px; }
  .page-head .muted { font-size: 15px; }
  .form-card > summary { font-size: 17px; }
  label { font-size: 15px; }
  input, select, textarea { font-size: 16px; padding: 11px 13px; }
  th { font-size: 14px; }
  td { font-size: 15px; padding: 14px 16px; }
  .stat-label { font-size: 15px; }
  .stat-value { font-size: 31px; }
  .stat-meta { font-size: 13px; }
  .table-head h2 { font-size: 17px; }
  .btn { font-size: 16px; }
  .btn.small { font-size: 14px; }
  .tag { font-size: 13px; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr; }
  .grid .span2 { grid-column: span 1; }
}
