:root {
  --ink: #1a1a2e;
  --ink2: #2d2d44;
  --muted: #7c7c8a;
  --light: #b0b0ba;
  --accent: #e63946;
  --accent2: #c1121f;
  --sea: #457b9d;
  --sky: #a8dadc;
  --warm: #e9a04f;
  --cream: #f8f6f2;
  --bg: #fefcf9;
  --card: #ffffff;
  --border: #e8e4df;
  --green: #2d6a4f;
  --green-bg: #ecfdf5;
  --red-bg: #fef2f2;
  --font: 'DM Sans', 'Noto Sans TC', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.5; }
a { color: var(--sea); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; }
input, select, textarea { font-family: var(--font); }

/* Layout */
.nav { position: sticky; top: 0; z-index: 100; background: rgba(254,252,249,0.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; height: 56px; }
.nav-brand { font-size: 18px; font-weight: 800; color: var(--ink); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.nav-brand span { color: var(--accent); }
.nav-links { display: flex; gap: 4px; }
.nav-links button { padding: 7px 16px; border-radius: 8px; border: none; font-size: 13px; font-weight: 600; background: transparent; color: var(--muted); transition: all .2s; }
.nav-links button.active { background: var(--ink); color: white; }
.nav-links button:hover:not(.active) { background: var(--cream); }
.nav-right { display: flex; gap: 8px; align-items: center; }

/* Buttons */
.btn { padding: 9px 20px; border-radius: 9px; border: none; font-size: 13px; font-weight: 700; transition: all .15s; }
.btn:hover { opacity: .88; }
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--cream); color: var(--ink); border: 1px solid var(--border); }
.btn-dark { background: var(--ink); color: white; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-danger { background: var(--accent); color: white; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* Inputs */
.input { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; outline: none; background: white; transition: border-color .2s; }
.input:focus { border-color: var(--accent); }
.textarea { min-height: 80px; resize: vertical; }
select.input { appearance: none; background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237c7c8a' d='M2 4l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 12px center; padding-right: 32px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 22px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h3 { font-size: 15px; font-weight: 700; }

/* Pills */
.pill { display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.pill-accent { background: #e6394618; color: var(--accent); }
.pill-sea { background: #457b9d18; color: var(--sea); }
.pill-warm { background: #e9a04f18; color: var(--warm); }
.pill-green { background: var(--green-bg); color: var(--green); }
.pill-muted { background: #7c7c8a12; color: var(--muted); }
.pill-filled { color: white !important; }
.pill-filled.pill-green { background: var(--green); }
.pill-filled.pill-accent { background: var(--accent); }

/* Stat cards */
.stat-card { background: white; border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
.stat-card .label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.stat-card .value { font-size: 26px; font-weight: 800; color: var(--ink); letter-spacing: -1px; }
.stat-card .sub { font-size: 11px; margin-top: 4px; font-weight: 600; }
.stat-card .sub.up { color: var(--green); }
.stat-card .sub.down { color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); background: #fafaf8; }
td { padding: 12px 14px; font-size: 13px; border-bottom: 1px solid #f5f3f0; }
tr:hover td { background: #fafaf8; }

/* Grid helpers */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.mt-md { margin-top: 16px; }

/* Admin sidebar */
.admin-layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 220px; background: var(--ink); padding: 20px 0; flex-shrink: 0; }
.sidebar-title { padding: 0 18px 18px; color: white; font-size: 15px; font-weight: 800; border-bottom: 1px solid #2d2d44; margin-bottom: 12px; }
.sidebar button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 20px; border: none; background: transparent; color: var(--light); font-size: 13px; font-weight: 500; text-align: left; border-left: 3px solid transparent; transition: all .15s; }
.sidebar button:hover { background: rgba(255,255,255,.05); }
.sidebar button.active { background: rgba(230,57,70,.1); color: var(--accent); border-left-color: var(--accent); font-weight: 700; }

/* Admin main */
.admin-main { flex: 1; padding: 28px; background: #fafaf8; overflow-y: auto; }
.admin-main h2 { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.admin-main .subtitle { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

/* Cost breakdown bar */
.cost-bar { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.cost-bar-fill { height: 100%; border-radius: 4px; transition: width .5s; }

/* Token badge */
.token-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; font-family: var(--mono); font-size: 11px; font-weight: 500; }
.token-badge.input { background: #457b9d18; color: var(--sea); }
.token-badge.output { background: #e9a04f18; color: var(--warm); }
.token-badge.cost { background: #e6394618; color: var(--accent); }

/* Log row */
.log-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.log-row:nth-child(odd) { background: #fafaf8; }
.log-time { font-family: var(--mono); font-size: 11px; color: var(--sea); min-width: 75px; }
.log-cost { font-family: var(--mono); font-size: 11px; font-weight: 600; min-width: 70px; text-align: right; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: white; border-radius: 18px; padding: 28px; max-width: 500px; width: 100%; max-height: 80vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.15); }
.modal h3 { font-size: 18px; font-weight: 800; margin-bottom: 16px; }

/* Loading */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; padding: 16px; color: var(--muted); font-size: 13px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 56px; overflow: hidden; }
  .sidebar button span:last-child { display: none; }
  .sidebar-title { font-size: 0; padding: 0 8px 12px; }
  .admin-main { padding: 16px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
