:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* 登入畫面 */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
  text-align: center;
}
.login-box h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
.error-text { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* 頂部列 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; gap: 8px; }

/* 分頁 */
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: none;
  background: none;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

main { padding: 16px 20px 60px; max-width: 900px; margin: 0 auto; }

/* 按鈕 */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f0f1f3; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: #fee2e2; color: var(--red); }

input, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

/* 分類標籤列 */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
}
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.template-row .chip { cursor: pointer; background: #eff6ff; border-color: #dbeafe; color: var(--primary); }

/* 卡片 */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.supply-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid var(--border);
}
.supply-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.supply-name { font-weight: 600; font-size: 15px; }
.supply-category {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  background: #f1f3f5;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 4px;
}
.supply-card-menu { display: flex; gap: 4px; }
.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 2px 6px;
}
.icon-btn:hover { color: var(--text); }

.progress-track {
  background: #eef0f3;
  border-radius: 999px;
  height: 10px;
  margin: 12px 0 6px;
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.progress-fill.green { background: var(--green); }
.progress-fill.yellow { background: var(--yellow); }
.progress-fill.red { background: var(--red); }

.progress-label { font-size: 13px; color: var(--text-muted); display: flex; justify-content: space-between; }
.progress-label .status.red { color: var(--red); font-weight: 600; }
.progress-label .status.yellow { color: var(--yellow); font-weight: 600; }
.progress-label .status.green { color: var(--green); font-weight: 600; }

.supply-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.supply-notes { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-style: italic; }

.supply-card-actions { margin-top: 14px; }
.supply-card-actions .btn { width: 100%; }

/* 更換紀錄表 */
.cost-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.cost-summary .stat {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  min-width: 130px;
}
.cost-summary .stat .num { font-size: 20px; font-weight: 700; }
.cost-summary .stat .label { font-size: 12px; color: var(--text-muted); }

.category-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.category-breakdown .cat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.category-breakdown .cat-name { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.category-breakdown .cat-total { font-size: 18px; font-weight: 700; }
.category-breakdown .cat-sub { font-size: 12px; color: var(--text-muted); }

.logs-table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: var(--radius); overflow: hidden; }
.logs-table th, .logs-table td { text-align: left; padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--border); }
.logs-table th { color: var(--text-muted); font-weight: 500; background: #fafbfc; }

.empty-text { text-align: center; color: var(--text-muted); padding: 40px 0; font-size: 14px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2430;
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .cost-summary .stat { flex: 1; min-width: 100px; }
}
