@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;700&display=swap");

:root {
  --sidebar: #1e1b4b;
  --sidebar-hover: #2d2a6e;
  --sidebar-active: #4f46e5;
  --sidebar-text: #c7d2fe;
  --sidebar-muted: #818cf8;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e8edf5;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --warn: #d97706;
  --danger: #dc2626;
  --ok: #059669;
  --shadow: 0 4px 24px rgba(30, 27, 75, 0.06);
  --shadow-lg: 0 12px 40px rgba(30, 27, 75, 0.1);
  --radius: 14px;
  --font: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.error { color: var(--danger); min-height: 1.2em; }
code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.12em 0.4em;
  border-radius: 6px;
  font-size: 0.85em;
}

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(99, 102, 241, 0.15), transparent),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(30, 27, 75, 0.08), transparent),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 14px;
}
.login-card .brand-mark {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.login-card h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.login-card .lead { margin: 0 0 6px; color: var(--muted); }

/* ── Form controls ── */
label { display: grid; gap: 6px; font-size: 0.88rem; font-weight: 500; color: #475569; }
input, select, textarea, button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: var(--card);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 72px; }
button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--accent-hover); }
button.ghost {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}
button.ghost:hover { background: #f8fafc; }
button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

/* ── App shell: sidebar + content ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 24px;
}
.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.brand-title { font-weight: 700; font-size: 1rem; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.72rem; color: var(--sidebar-muted); margin-top: 2px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  background: transparent;
  color: var(--sidebar-text);
  border: none;
  border-radius: 10px;
  font-weight: 500;
  font-size: 0.92rem;
}
.sidebar-nav button:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav button.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.nav-icon {
  width: 20px;
  text-align: center;
  opacity: 0.85;
  font-size: 0.95rem;
}

.sidebar-foot {
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  gap: 8px;
}
.user-chip {
  font-size: 0.82rem;
  color: var(--sidebar-muted);
  padding: 0 10px;
}
.sidebar-logout {
  width: 100%;
  background: rgba(255, 255, 255, 0.08) !important;
  color: var(--sidebar-text) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  font-size: 0.85rem;
}
.sidebar-logout:hover { background: rgba(255, 255, 255, 0.14) !important; }

/* ── Main content ── */
.content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 48px;
  overflow-x: auto;
}

.panel { animation: fadeIn 0.3s ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h2 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.page-desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Segmented tabs (今日/本月) */
.seg-tabs {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-tabs button {
  padding: 7px 16px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
}
.seg-tabs button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.seg-tabs button:hover:not(.active) { background: #f1f5f9; color: var(--ink); }

.status-pill.active-run { background: #dcfce7; color: #166534; }
.status-pill.warmup-run { background: #fef3c7; color: #92400e; }
.status-pill.parked-run { background: #e2e8f0; color: #475569; }

.dash-date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.dash-date-range label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.dash-date-range input[type="date"] {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  min-width: 130px;
}

.search-input {
  min-width: 200px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
}

/* ── KPI cards ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-card.highlight {
  background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 28px var(--accent-glow);
}
.kpi-card.highlight .kpi-label { color: rgba(255, 255, 255, 0.8); }
.kpi-card.highlight .kpi-unit { color: rgba(255, 255, 255, 0.65); }
.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.kpi-value {
  margin-top: 8px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.kpi-unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
}

/* ── Table card ── */
.table-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.table-card-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
}
.table-wrap.wide {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.88rem;
}
.data-table.wide-table {
  min-width: 1280px;
}
.data-table.compact {
  min-width: 0;
}
.data-table th,
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.data-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: #64748b;
}
.data-table.wide-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.data-table td.num .table-input {
  text-align: right;
}
.data-table tbody tr:hover td { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tfoot .total-row td {
  background: #f1f5f9;
  font-weight: 600;
  border-top: 2px solid var(--line);
  border-bottom: none;
}
.data-table .cell-name strong { color: var(--ink); }
td .actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: nowrap;
}
.table-input {
  width: 100%;
  max-width: 120px;
  margin-left: auto;
  display: block;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  box-sizing: border-box;
}
button.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
  white-space: nowrap;
}

/* Legacy table-wrap (accounts etc.) */
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }

/* ── Cards & forms ── */
.entry-ads-extra {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.entry-ads-extra summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  user-select: none;
}
.bulk-entry-input {
  width: 100%;
  min-width: 72px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.88rem;
  text-align: right;
}

.card-form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.card-form h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.grid2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-actions.wrap { margin-top: 12px; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 160px; }

.notice {
  border: 1px dashed #c7d2fe;
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--muted);
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--muted);
}
.status-pill.warn { background: #fff7ed; color: var(--warn); }
.status-pill.ok { background: #ecfdf5; color: var(--ok); }
.status-pill.err { background: #fef2f2; color: var(--danger); }

.chip-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip-list li {
  background: var(--accent-soft);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.chip-list button { padding: 2px 8px; font-size: 0.8rem; }

.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 260px;
  overflow: auto;
  font-size: 0.85rem;
}
.log-list li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.log-list .err { color: var(--danger); }

.empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--sidebar);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-width: min(380px, calc(100vw - 48px));
  animation: fadeIn 0.25s ease both;
}
.toast.err { background: var(--danger); }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }
  .sidebar-brand { padding-bottom: 0; }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    order: 3;
  }
  .sidebar-nav button { width: auto; padding: 8px 12px; font-size: 0.82rem; }
  .sidebar-foot { display: none; }
  .content { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; }
}
