/* ==========================================
   Design tokens
   ========================================== */
:root {
  color-scheme: light dark;

  --bg: #eef4fb;
  --surface: #ffffff;
  --surface-alt: #f5f9fd;
  --text: #1f2d3a;
  --text-muted: #5c7085;
  --border: #d8e4f0;

  --accent: #3f7cb3;
  --accent-hover: #336a9c;
  --accent-soft: #dfedf9;
  --accent-contrast: #ffffff;

  --success: #2f9e6e;
  --success-soft: #e1f5ec;
  --warning: #b8791f;
  --warning-soft: #faf0dc;
  --danger: #c1443a;
  --danger-soft: #fbe7e4;

  --shadow-card: 0 1px 2px rgba(31, 45, 58, 0.04), 0 8px 24px -12px rgba(31, 45, 58, 0.12);
  --shadow-header: 0 1px 0 rgba(31, 45, 58, 0.06);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Noto Sans Mono", monospace;

  --radius-lg: 14px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --radius-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #16212c;
    --surface-alt: #1b2733;
    --text: #e6eef6;
    --text-muted: #93a7b8;
    --border: #28394a;

    --accent: #6fa8d8;
    --accent-hover: #86b8e2;
    --accent-soft: #1f3548;
    --accent-contrast: #0b141c;

    --success: #4cbf8f;
    --success-soft: #163826;
    --warning: #d9a13f;
    --warning-soft: #3a2d14;
    --danger: #e2695c;
    --danger-soft: #3a1d1a;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
    --shadow-header: 0 1px 0 rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1720;
  --surface: #16212c;
  --surface-alt: #1b2733;
  --text: #e6eef6;
  --text-muted: #93a7b8;
  --border: #28394a;
  --accent: #6fa8d8;
  --accent-hover: #86b8e2;
  --accent-soft: #1f3548;
  --accent-contrast: #0b141c;
  --success: #4cbf8f;
  --success-soft: #163826;
  --warning: #d9a13f;
  --warning-soft: #3a2d14;
  --danger: #e2695c;
  --danger-soft: #3a1d1a;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-header: 0 1px 0 rgba(0, 0, 0, 0.3);
}

:root[data-theme="light"] {
  --bg: #eef4fb;
  --surface: #ffffff;
  --surface-alt: #f5f9fd;
  --text: #1f2d3a;
  --text-muted: #5c7085;
  --border: #d8e4f0;
  --accent: #3f7cb3;
  --accent-hover: #336a9c;
  --accent-soft: #dfedf9;
  --accent-contrast: #ffffff;
  --success: #2f9e6e;
  --success-soft: #e1f5ec;
  --warning: #b8791f;
  --warning-soft: #faf0dc;
  --danger: #c1443a;
  --danger-soft: #fbe7e4;
  --shadow-card: 0 1px 2px rgba(31, 45, 58, 0.04), 0 8px 24px -12px rgba(31, 45, 58, 0.12);
  --shadow-header: 0 1px 0 rgba(31, 45, 58, 0.06);
}

/* ==========================================
   Reset & base
   ========================================== */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1, h2, h3 {
  text-wrap: balance;
  font-weight: 650;
  line-height: 1.3;
  margin: 0 0 0.75rem;
}

h2 {
  font-size: 1.3rem;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 0.75rem;
}

p:last-child {
  margin-bottom: 0;
}

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

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
}

/* ==========================================
   Layout
   ========================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0.9rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-header);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface-alt);
  object-fit: cover;
  flex-shrink: 0;
}

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ==========================================
   Cards
   ========================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.card + .card {
  margin-top: 0;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.error-card {
  border-color: var(--danger);
}

/* ==========================================
   Forms
   ========================================== */
form {
  display: flex;
  flex-direction: column;
}

label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

label:first-child {
  margin-top: 0;
}

input,
select,
textarea {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:hover, select:hover, textarea:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
  padding: 0.5rem;
  background: var(--surface-alt);
}

/* ==========================================
   Buttons
   ========================================== */
button,
.button-link {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.65rem 1.1rem;
  margin-top: 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  width: 100%;
}

.button-link {
  width: auto;
}

button:hover,
.button-link:hover {
  background: var(--accent-hover);
  text-decoration: none;
  box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* secondary / danger action buttons live inside forms alongside a primary one;
   this keeps delete-style buttons visually lighter than the main call to action */
.card-item form button {
  width: auto;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  margin-top: 0.25rem;
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
}

.card-item form button:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  box-shadow: none;
}

/* ==========================================
   Status badges
   ========================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

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

.badge-neutral {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ==========================================
   Utility
   ========================================== */
.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

.success {
  color: var(--success);
  font-size: 0.9rem;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.nav-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.nav-list a::after {
  content: "→";
  color: var(--text-muted);
  font-weight: 400;
}

.nav-list a:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
  text-decoration: none;
}

.page-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
}

/* wide content (tables, etc.) never forces the page itself to scroll sideways */
.scroll-x {
  overflow-x: auto;
}
