:root {
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1f2533;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #d97706;
  --blue: #2563eb;
  --brand: #C85F80;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

/* 防止 iOS Safari 在點擊 input 時自動縮放 */
input, select, textarea {
  font-size: 16px !important;
}
.credit-row { scroll-margin-top: 64px; }
@media (max-width: 860px) { .credit-row { scroll-margin-top: 96px; } }

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

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.brand { text-decoration: none; display: flex; align-items: center; }
.brand-logo { height: 70px; width: auto; }
.topbar nav {
  display: flex;
  align-items: center;
  position: relative;
}
.topbar nav a, .topbar nav .nav-main {
  margin-left: 16px;
  color: var(--brand);
  text-decoration: none;
  font-size: 0.92rem;
}
.topbar nav a:hover { color: var(--brand); text-decoration: underline; }

.nav-lang {
  border: 1px solid var(--brand);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 600;
}
.nav-lang:hover { text-decoration: none !important; background: #fdf0f4; }

.nav-toggle {
  display: inline-block;
  margin-left: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1.05rem;
  line-height: 1;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
}

.nav-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  padding: 6px;
  flex-direction: column;
  align-items: stretch;
  min-width: 200px;
  z-index: 30;
}
.nav-menu.open { display: flex; }
.nav-menu a {
  margin-left: 0;
  padding: 8px 10px;
  border-radius: 6px;
}
.nav-menu a:hover { background: #fdf0f4; text-decoration: none; }


.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

/* Summary */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  border: 1px solid var(--border);
}
.summary-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.summary-value { font-size: 1.5rem; font-weight: 700; }
.summary-value.used { color: var(--green); }
.summary-value.unused { color: var(--orange); }

/* Alert box */
.alert-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.alert-box h2 { font-size: 0.95rem; margin: 0 0 8px; color: #9a3412; }
.alert-list { margin: 0; padding-left: 18px; font-size: 0.9rem; }
.alert-list li { margin-bottom: 4px; }
.alert-link { color: inherit; text-decoration: none; }
.alert-link:hover { text-decoration: underline; cursor: pointer; }
.alert-list .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 4px;
}
.days-left { font-weight: 600; color: var(--orange); margin-left: 6px; }
.days-left.critical { color: var(--red); }

/* Card block */
.card-block {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  padding: 12px 16px;
  border-left: 6px solid var(--brand);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 1.05rem; }
.issuer, .annual-fee { font-size: 0.82rem; color: var(--muted); }
.card-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Rewards bar */
.rewards-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: #fafafa;
}
.reward-chip {
  font-size: 0.75rem; background: #ecfdf5; color: #047857;
  border-radius: 999px; padding: 3px 10px; cursor: help;
}

/* Credit rows (dashboard) */
.credit-list { display: flex; flex-direction: column; }
.credit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.credit-row:last-child { border-bottom: none; }
.credit-row.status-full { background: #f0fdf4; }
.credit-row.status-partial { background: #fffbeb; }

.credit-info { flex: 1; min-width: 0; }
.credit-name { font-weight: 600; font-size: 0.95rem; }
.credit-notes { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.credit-meta { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.history-link { margin-left: 8px; color: var(--brand); text-decoration: none; }
.tag {
  display: inline-block; font-size: 0.7rem; color: var(--brand);
  background: #eff6ff; border-radius: 6px; padding: 1px 6px; margin-left: 6px;
}
.credit-amount { font-weight: 700; min-width: 60px; text-align: right; }
.credit-days {
  font-size: 0.78rem; color: var(--muted); min-width: 70px; text-align: right;
}
.credit-days.warning { color: var(--orange); font-weight: 600; }
.credit-days.critical { color: var(--red); font-weight: 600; }

/* Usage progress / 分次使用 */
.usage-progress {
  margin-top: 8px;
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}
.usage-progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--muted);
  transition: width 0.2s ease;
}
.usage-progress-bar.status-none { background: var(--border); }
.usage-progress-bar.status-partial { background: var(--orange); }
.usage-progress-bar.status-full { background: var(--green); }

.usage-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.8rem;
}
.usage-status { font-weight: 600; color: var(--muted); }
.usage-status.status-partial { color: var(--orange); }
.usage-status.status-full { color: var(--green); }
.usage-amounts { color: var(--muted); }

.usage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.usage-actions button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  cursor: pointer;
}
.btn-quick-use {
  border-color: var(--green) !important;
  color: var(--green) !important;
}
.btn-toggle-entry {
  color: var(--brand) !important;
  border-color: var(--brand) !important;
}
.btn-clear-usage {
  color: var(--muted) !important;
}
.usage-actions button:disabled { opacity: 0.5; cursor: default; }

.usage-entry-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}
.usage-entry-form input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
}
.usage-entry-form .entry-amount { width: 90px; }
.usage-entry-form .entry-date { width: 130px; }
.usage-entry-form .entry-notes { flex: 1; min-width: 100px; }
.usage-entry-form .entry-submit {
  background: var(--brand); color: #fff; border: none; border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-size: 0.82rem;
}
.usage-entry-form .entry-cancel {
  background: #e5e7eb; color: var(--text); border: none; border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-size: 0.82rem;
}

.btn-delete-entry {
  background: var(--red); color: #fff; border: none; border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 0.78rem;
}

.empty-hint { padding: 16px; color: var(--muted); font-size: 0.9rem; }

/* Manage page */
.manage-section {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
}
.manage-section h2 { margin-top: 0; font-size: 1rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.inline-form input, .inline-form select {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem;
}
.inline-form input[type="text"], .inline-form input[type="number"] { flex: 1; min-width: 110px; }
.inline-form input[type="color"] { width: 40px; padding: 2px; }
.inline-form button, .manage-section button {
  background: var(--brand); color: #fff; border: none; border-radius: 6px;
  padding: 6px 14px; cursor: pointer; font-size: 0.85rem;
}
.inline { display: inline-block; }
.btn-secondary {
  background: #e5e7eb !important; color: var(--text) !important;
}
.btn-danger {
  background: var(--red) !important;
}

.credit-manage-list { padding: 4px 16px; }
.credit-manage-row { border-bottom: 1px solid var(--border); padding: 6px 0; }
.credit-manage-row:last-child { border-bottom: none; }
.credit-manage-row.inactive { opacity: 0.5; }
.credit-manage-row summary { cursor: pointer; font-size: 0.9rem; padding: 4px 0; }
.credit-row-actions { display: flex; gap: 8px; margin-top: 6px; }

.add-credit { padding: 12px 16px; }
.add-credit summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--brand); }

.reward-manage-list { margin: 8px 0; }
.reward-row { border-bottom: 1px solid var(--border); padding: 4px 0; }
.reward-row:last-child { border-bottom: none; }
.reward-row summary { cursor: pointer; font-size: 0.85rem; padding: 4px 0; }

textarea#import-data {
  width: 100%; font-family: monospace; font-size: 0.8rem; margin: 8px 0;
  border: 1px solid var(--border); border-radius: 6px; padding: 8px;
}

/* Card nickname badge (總覽頁) */
.card-nickname {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 8px;
  vertical-align: middle;
}

/* My Cards page — instance list */
.instance-list {
  list-style: none;
  margin: 0;
  padding: 0 16px 4px;
}
.instance-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.instance-row:last-child { border-bottom: none; }
.instance-icon { font-size: 1rem; }
.instance-nickname { flex: 1; }

.btn-edit-nickname {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  opacity: 0.5;
  line-height: 1;
}
.btn-edit-nickname:hover { opacity: 1; }

.add-instance-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.add-instance-form .instance-nickname-input {
  flex: 1;
  min-width: 140px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

/* ── Report page ── */
.summary-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.report-year-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.report-year-btn {
  padding: 5px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
}
.report-year-btn:hover { background: var(--bg); text-decoration: none; }
.report-year-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.report-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot {
  width: 12px; height: 12px;
  border-radius: 3px;
  border: 1.5px solid transparent;
}
.legend-dot.status-full    { background: #dcfce7; border-color: #86efac; }
.legend-dot.status-partial { background: #fef9c3; border-color: #fde047; }
.legend-dot.status-none    { background: #fee2e2; border-color: #fca5a5; }
.legend-dot.status-current { background: #dbeafe; border-color: #93c5fd; }
.legend-dot.status-future  { background: var(--bg); border-color: var(--border); }

.report-credit-list { padding: 4px 0; }
.report-credit-row {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.report-credit-row:last-child { border-bottom: none; }
.report-credit-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  flex-wrap: wrap;
}
.report-credit-meta {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--muted);
}

.report-periods {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.report-period {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.75rem;
  text-align: center;
  cursor: default;
  border: 1.5px solid transparent;
  line-height: 1.3;
}
.period-label { font-weight: 600; }
.period-used  { font-size: 0.68rem; opacity: 0.85; margin-top: 1px; }

.report-period.status-full    { background: #dcfce7; border-color: #86efac; color: #15803d; }
.report-period.status-partial { background: #fef9c3; border-color: #fde047; color: #854d0e; }
.report-period.status-none    { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }
.report-period.status-current { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }
.report-period.status-future  { background: var(--bg); border-color: var(--border); color: var(--muted); }

/* History page */
.history-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.history-table th, .history-table td {
  padding: 8px 16px; border-bottom: 1px solid var(--border); text-align: left;
}
.badge-used { color: var(--green); font-weight: 600; }
.badge-unused { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--brand); text-decoration: none; }
.hint { color: var(--muted); font-size: 0.85rem; padding: 0 16px; }

@media (max-width: 600px) {
  .summary { grid-template-columns: 1fr; }
  .credit-row { flex-wrap: wrap; }
  .credit-amount, .credit-days { min-width: auto; }
}

/* Auth pages */
.auth-box { max-width: 380px; margin: 32px auto; }
.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.auth-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; }
.auth-form button {
  background: var(--brand); color: #fff; border: none; border-radius: 6px;
  padding: 8px 14px; cursor: pointer; font-size: 0.9rem; margin-top: 4px;
}

/* Flash messages */
.flash-box {
  background: #fef3c7; border: 1px solid #fde68a; border-radius: 8px;
  padding: 8px 14px; margin-bottom: 12px; font-size: 0.88rem; color: #92400e;
}
.flash-box p { margin: 2px 0; }
