/* PALU 本機介面（自寫；唔用外部 CDN） */
:root {
  --side-bg: #1e293b;
  --side-ink: #e2e8f0;
  --side-muted: #94a3b8;
  --side-active: #0f766e;
  --side-width: 15.5rem;
  --bg: #eef1f4;
  --bg-card: #ffffff;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #d4d4d8;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --bad: #b91c1c;
  --ok: #15803d;
  --step-on: #0f766e;
  --step-off: #e4e4e7;
  --radius: 8px;
  --topbar-h: auto;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: "PingFang HK", "Noto Sans TC", "Helvetica Neue", sans-serif;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* —— 登入等無殼頁 —— */
.page-plain {
  background:
    radial-gradient(ellipse at top left, #dcefea 0%, transparent 50%),
    var(--bg);
}
.plain-wrap {
  max-width: 28rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem;
}

/* —— App 殼：側欄 + 主區 —— */
.side-toggle { position: absolute; opacity: 0; pointer-events: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: var(--side-width);
  height: 100vh;
  background: var(--side-bg);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem 1.25rem;
  overflow-y: auto;
}

.side-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.55rem 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  margin-bottom: 0.85rem;
}

.brand-mark {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #f8fafc;
  text-decoration: none;
}
.brand-mark:hover { color: #fff; text-decoration: none; }

.side-close {
  display: none;
  font-size: 0.85rem;
  color: var(--side-muted);
  cursor: pointer;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.side-link {
  display: block;
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  color: var(--side-ink);
  font-size: 1rem;
  text-decoration: none;
}
.side-link:hover {
  background: rgba(148, 163, 184, 0.15);
  text-decoration: none;
}
.side-link.is-active {
  background: var(--side-active);
  color: #fff;
  font-weight: 600;
}

.side-backdrop { display: none; }

.app-main {
  flex: 1;
  margin-left: var(--side-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem 1rem;
  padding: 0.9rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.35rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.top-title { flex: 1; min-width: 12rem; }

.page-title {
  font-size: 1.35rem;
  line-height: 1.3;
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
}

.top-status {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.45;
}
.top-status strong {
  display: inline;
  color: var(--ink);
  margin-right: 0.35rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}
.top-user { color: var(--muted); }

.content {
  padding: 1.15rem 1.25rem 2.5rem;
  max-width: 72rem;
  width: 100%;
}

.client-line {
  margin: 0 0 0.75rem;
  font-weight: 600;
}

/* —— 數字卡 —— */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin: 0.85rem 0 1.15rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}

/* —— 卡片面板 + 表格 —— */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0.85rem 0 1.15rem;
  overflow: hidden;
}

.panel-head {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.panel-body { padding: 0.85rem 1rem; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 36rem;
  margin: 0;
  background: var(--bg-card);
}

th, td {
  border: 1px solid var(--line);
  padding: 0.55rem 0.7rem;
  text-align: left;
  vertical-align: top;
  font-size: 0.95rem;
}

th {
  background: #f1f5f9;
  font-weight: 600;
}

.row-action {
  font-weight: 600;
  white-space: nowrap;
}

.flash {
  background: #ecfdf5;
  color: #065f46;
  padding: 0.7rem 0.9rem;
  border: 1px solid #6ee7b7;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.err {
  background: #fef2f2;
  color: #7f1d1d;
  padding: 0.7rem 0.9rem;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

h1 {
  font-size: 1.5rem;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}

h2 {
  font-size: 1.15rem;
  margin: 1.25rem 0 0.55rem;
}

h3 {
  font-size: 1.05rem;
  margin: 1rem 0 0.45rem;
}

p, li { color: var(--ink); }
.muted { color: var(--muted); }

.draft {
  white-space: pre-wrap;
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.85rem;
}

form.inline { display: inline; }

label { display: block; margin: 0.55rem 0 0.2rem; font-weight: 560; }

input[type=text],
input[type=password],
input[type=number],
textarea,
select {
  width: min(28rem, 100%);
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

button {
  margin: 0.4rem 0.4rem 0.4rem 0;
  padding: 0.55rem 1rem;
  font-size: 1rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

button[type=submit], button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

button.btn-quiet {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  padding: 0.4rem 0.75rem;
  font-size: 0.95rem;
}

.bar {
  background: var(--line);
  height: 0.95rem;
  width: min(28rem, 100%);
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--ok);
}

.bar.warn > span { background: var(--warn); }
.bar.over > span { background: var(--bad); }

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  list-style: none;
  padding: 0;
  margin: 0;
  min-width: 18rem;
}

.steps li {
  flex: 1 1 4.2rem;
  min-width: 4rem;
  text-align: center;
  font-size: 0.78rem;
  padding: 0.35rem 0.25rem;
  border-radius: 6px;
  background: var(--step-off);
  color: var(--muted);
}

.steps li.on {
  background: var(--step-on);
  color: #fff;
  font-weight: 600;
}

.trend-svg {
  width: 100%;
  max-width: 36rem;
  height: auto;
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0.35rem 0;
}

.week-grid {
  display: grid;
  gap: 0.75rem;
}

/* —— 窄螢幕：側欄收埋，☰ 開關 —— */
@media (max-width: 899px) {
  .sidebar {
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  .side-toggle:checked ~ .app-shell .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.35);
  }
  .side-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .side-toggle:checked ~ .app-shell .side-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .app-main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .side-close { display: inline; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .content { padding: 1rem; }
}

@media (max-width: 520px) {
  .stat-row { grid-template-columns: 1fr; }
  html { font-size: 16px; }
}
