:root {
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, "Noto Sans TC", "PingFang TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

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

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: #e2e8f0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  font-size: 1.25rem;
  font-weight: 700;
  border-bottom: 1px solid #334155;
  color: #fff;
}

.sidebar-brand span { color: var(--primary); }

.sidebar nav { padding: 0.75rem 0; flex: 1; }

.nav-section {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.nav-link {
  display: block;
  padding: 0.55rem 1rem;
  color: #cbd5e1;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}

.nav-link:hover, .nav-link.active {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.nav-link.active { border-left-color: var(--primary); }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.breadcrumb { font-size: 0.875rem; color: var(--muted); }
.breadcrumb strong { color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 1rem; font-size: 0.875rem; }

.search-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  width: 220px;
  font-size: 0.875rem;
}

.content { padding: 1.5rem; flex: 1; }

/* Cards & KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.kpi-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.kpi-value { font-size: 1.75rem; font-weight: 700; }
.kpi-value.positive { color: var(--success); }
.kpi-value.warning { color: var(--warning); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body { padding: 1.25rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); text-decoration: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

/* Forms */
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.form-group { flex: 1; min-width: 160px; }
.form-group label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  background: #fff;
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 0.65rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #f8fafc; }
.text-right { text-align: right; }
.mono { font-family: ui-monospace, monospace; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-pending { background: #fef3c7; color: #b45309; }
.badge-approved { background: #dcfce7; color: #15803d; }
.badge-void { background: #fee2e2; color: #b91c1c; }
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-closed { background: #f1f5f9; color: #64748b; }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.login-brand { text-align: center; margin-bottom: 2rem; }
.login-brand h1 { font-size: 1.75rem; }
.login-brand p { color: var(--muted); font-size: 0.9rem; }

/* Wireframe mode */
.wireframe body, body.wireframe-mode { background: #fff; }
.wf-box {
  border: 2px dashed #94a3b8;
  background: #f8fafc;
  border-radius: 4px;
  padding: 0.75rem;
  color: #64748b;
  font-size: 0.85rem;
  min-height: 2rem;
}
.wf-label { font-size: 0.7rem; color: #94a3b8; text-transform: uppercase; margin-bottom: 0.25rem; }

/* Index hub */
.hub { max-width: 960px; margin: 0 auto; padding: 2rem; }
.hub h1 { margin-bottom: 0.5rem; }
.hub > p { color: var(--muted); margin-bottom: 2rem; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.page-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: box-shadow 0.15s;
}
.page-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.page-card h3 { margin-bottom: 0.35rem; font-size: 1rem; }
.page-card p { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }

.balance-ok { color: var(--success); font-weight: 600; }
.balance-error { color: var(--danger); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 1rem; }

.tag-mockup {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--sidebar);
  color: #fff;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  opacity: 0.85;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.banner-locked { background: #fef2f2; border-bottom: 1px solid #fecaca; padding: 0.65rem 1.5rem; color: #b91c1c; font-size: 0.875rem; }
.field-error { border-color: var(--danger) !important; }
.hint-error { color: var(--danger); font-size: 0.75rem; margin-top: 0.25rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.page-section-title { font-size: 1rem; font-weight: 600; margin: 2rem 0 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.flow-tag { font-size: 0.7rem; background: #e0f2fe; color: #0369a1; padding: 0.15rem 0.5rem; border-radius: 4px; margin-left: 0.5rem; }
.flow-tag-neg { background: #fee2e2; color: #b91c1c; }

.tag-mockup.phase2 { background: #15803d; }
.tag-mockup.phase3 { background: #b45309; }
.tag-mockup.phase4 { background: #7c3aed; }
