:root {
  --bg: #fbf3e4;
  --card-bg: #ffffff;
  --text: #2b2a28;
  --text-muted: #8a8171;
  --accent-green: #234b33;
  --accent-green-soft: #e4eee7;
  --accent-gold: #c99a3c;
  --accent-gold-soft: #f3e6c9;
  --border: #ece3d2;
  --danger: #b3452f;
  --danger-soft: #f7e3dd;
  --shadow: 0 2px 10px rgba(43, 42, 40, 0.06);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --chart-visits: #1f6b3f;
  --chart-clicks: #c08a2e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b18;
    --card-bg: #262420;
    --text: #f1ead9;
    --text-muted: #a79c86;
    --accent-green: #5ca47c;
    --accent-green-soft: #24382c;
    --accent-gold: #d8ae5c;
    --accent-gold-soft: #3a3122;
    --border: #3a362e;
    --danger: #e08a71;
    --danger-soft: #3a2620;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
    --chart-visits: #5ca47c;
    --chart-clicks: #d8ae5c;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

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

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font-family: inherit;
}

.icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- 連結頁 (index.html) ---------- */

.link-page {
  max-width: 460px;
  margin: 0 auto;
  padding: 56px 20px 40px;
  min-height: 100vh;
}

.hero {
  text-align: center;
  margin-bottom: 36px;
}

.brand-logo {
  display: block;
  width: 190px;
  height: 190px;
  margin: 0 auto 22px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 8px 28px rgba(43, 42, 40, 0.14);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hero h1 {
  font-size: 30px;
  font-weight: 800;
  margin: 0 0 10px;
  letter-spacing: 0.04em;
}

.hero p {
  color: var(--text-muted);
  margin: 0 0 22px;
  font-size: 15px;
}

.hero-divider {
  width: 120px;
  height: 2px;
  margin: 0 auto;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
}

.link-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.link-card:active {
  transform: scale(0.98);
}

@media (hover: hover) {
  .link-card:hover {
    box-shadow: 0 6px 18px rgba(43, 42, 40, 0.1);
  }
}

.link-icon {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent-green-soft);
  color: var(--accent-green);
  display: flex;
  align-items: center;
  justify-content: center;
}

.link-body {
  flex: 1;
  min-width: 0;
}

.link-body .title {
  font-size: 17px;
  font-weight: 700;
}

.link-body .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-chevron {
  flex: none;
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}

.link-page-footer {
  text-align: center;
  margin-top: 44px;
  color: var(--text-muted);
}

.sprouts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 64px;
  margin-bottom: 18px;
  opacity: 0.7;
}

.sprouts .line {
  position: relative;
  width: 100%;
  max-width: 380px;
  height: 1px;
  background: var(--accent-gold);
  margin: 0 auto 18px;
}

.sprouts-row {
  display: flex;
  justify-content: space-around;
  max-width: 380px;
  margin: 0 auto -30px;
  color: var(--accent-gold);
}

.link-page-footer small {
  font-size: 12px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 16px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
}

/* ---------- 登入頁 (login.html) ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card p.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 22px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.field input:focus {
  outline: 2px solid var(--accent-green);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent-green);
  border-color: var(--accent-green);
  color: #fff;
  width: 100%;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
}

.error-msg {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.error-msg.show {
  display: block;
}

/* ---------- 後台儀表板 (admin.html) ---------- */

.dash {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.dash-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.dash-header h1 {
  font-size: 22px;
  margin: 0 0 6px;
}

.dash-header .range-label {
  color: var(--text-muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.segmented button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--accent-green-soft);
  color: var(--accent-green);
  font-weight: 700;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.stat-card .label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 800;
}

.stat-card .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card + .card {
  margin-top: 20px;
}

.chart-legend {
  display: flex;
  gap: 18px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.chart-legend .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

.link-name {
  font-weight: 700;
}

.link-dest {
  font-size: 12px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--accent-green-soft);
  overflow: hidden;
  min-width: 80px;
}

.bar-fill {
  height: 100%;
  background: var(--accent-green);
  border-radius: 999px;
}

.num-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
}

@media (max-width: 900px) {
  .breakdown-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.breakdown-col h3 {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 6px 0;
}

.breakdown-row .pct {
  color: var(--text-muted);
  margin-left: 8px;
}

.footer-note {
  color: var(--text-muted);
  font-size: 13px;
  margin: 14px 0;
}

.add-link-row {
  margin-top: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 14, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 18px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-green);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.loading-row {
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}

.chip {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  margin-left: 8px;
}

.chip.inactive {
  background: var(--danger-soft);
  color: var(--danger);
}
