/* Claude design style (docs/ui-spec.md "Visual language"). */

:root {
  --bg: #FAF9F5;
  --surface: #FFFFFF;
  --surface-2: #F0EEE6;
  --border: #E8E6DC;
  --text: #141413;
  --text-muted: #5E5D59;
  --text-faint: #87867F;
  --accent: #D97757;
  --accent-hover: #C6613F;
  --accent-soft: #F5E6DF;
  --success: #5B8C5A;
  --warning: #C4933F;
  --danger: #BF4D43;
  --chart-1: #D97757;
  --chart-2: #6A9BCC;
  --chart-3: #8E7CC3;
  --chart-4: #5B8C5A;
  --chart-5: #C4933F;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F1E1D;
    --surface: #262624;
    --surface-2: #30302E;
    --border: #3D3D3A;
    --text: #F5F4EE;
    --text-muted: #B7B5A9;
    --text-faint: #8A8880;
  }
}

:root[data-theme="dark"] {
  --bg: #1F1E1D;
  --surface: #262624;
  --surface-2: #30302E;
  --border: #3D3D3A;
  --text: #F5F4EE;
  --text-muted: #B7B5A9;
  --text-faint: #8A8880;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
}

body { display: flex; min-height: 100vh; }

h1, h2, h3, .serif { font-family: "Source Serif 4", Georgia, serif; }

.num { font-variant-numeric: tabular-nums; }

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

/* ---- layout ---- */

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand { font-family: "Source Serif 4", serif; font-size: 20px; font-weight: 600; }

.sidebar select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

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

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.nav a:hover { background: var(--surface); color: var(--text); }

.nav a.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 500; }

.nav svg { flex: 0 0 auto; }

.sidebar-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  width: fit-content;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px;
}

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

.page-title { font-size: 28px; margin: 0 0 4px 0; }
.page-subtitle { color: var(--text-muted); margin: 0; font-size: 14px; }

.period-picker { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.period-picker select, .period-picker input {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

/* ---- cards / grid ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-2col { grid-template-columns: 1fr 1fr; }

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

@media (max-width: 480px) {
  .grid-kpi { grid-template-columns: 1fr; }
}

.kpi-label { color: var(--text-muted); font-size: 12px; display: flex; align-items: center; gap: 4px; }
.kpi-value { font-family: "Source Serif 4", serif; font-size: 32px; margin: 6px 0 4px; }
.kpi-delta { font-size: 12px; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--text-faint); }

.tooltip-wrap { position: relative; display: inline-flex; cursor: help; }
.tooltip-wrap .tooltip-bubble {
  display: none;
  position: absolute;
  bottom: 130%;
  left: 0;
  width: 220px;
  background: var(--text);
  color: var(--bg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 5;
  line-height: 1.4;
}
.tooltip-wrap:hover .tooltip-bubble { display: block; }

/* ---- tables ---- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-scroll { overflow-x: auto; }

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th { background: var(--surface-2); color: var(--text-muted); font-weight: 500; font-size: 12px; }
tr.totals td { font-weight: 600; background: var(--surface-2); }

td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; margin-right: 6px; }
.status-dot.ok { background: var(--success); }
.status-dot.warn { background: var(--warning); }
.status-dot.error { background: var(--danger); }
.status-dot.none { background: var(--text-faint); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- buttons / forms ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--surface-2); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}
.field .errorlist { color: var(--danger); font-size: 12px; margin: 0; padding: 0; list-style: none; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---- drawer ---- */

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 10;
}
.drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px;
  z-index: 11;
  overflow-y: auto;
}
[data-drawer-open] .drawer-backdrop,
[data-drawer-open] .drawer { display: block; }

.drawer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}
.copy-row code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

/* ---- empty state ---- */

.empty-state { text-align: center; padding: 48px 24px; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); margin-bottom: 24px; }
.empty-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---- login ---- */

.login-page {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card { width: 320px; }
.login-card h1 { text-align: center; margin-bottom: 24px; }

/* ---- responsive sidebar ---- */

@media (max-width: 900px) {
  html, body { max-width: 100vw; overflow-x: hidden; }
  body { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-width: 100%;
    flex: none;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
  }
  .sidebar .brand { font-size: 16px; }
  .sidebar select { max-width: 140px; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav a span { display: none; }
  .sidebar-bottom {
    margin-top: 0; flex-direction: row; flex-wrap: wrap; border-top: none; padding-top: 0;
  }
  .sidebar-bottom form { width: auto; }
  .sidebar-bottom .btn { width: auto !important; }
  .main { padding: 16px; max-width: 100%; }
  .page-header { flex-direction: column; }
}

/* ---- connectors ---- */

.connector-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.connector-card h3 { margin: 0 0 4px 0; font-size: 15px; }
.connector-card .env-vars { font-size: 12px; color: var(--text-faint); margin: 6px 0; }

/* ---- upload cards ---- */

.upload-card { display: flex; flex-direction: column; gap: 10px; }
.upload-card .dropzone {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.result-panel { margin-top: 16px; }
.result-panel.ok { border-color: var(--success); }
.result-panel.warn { border-color: var(--warning); }
