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

:root {
  --orange: #ee4d2d;
  --orange-dark: #c73d20;
  --orange-light: #fff3f0;
  --green: #00b96b;
  --green-light: #f0faf5;
  --red: #e53935;
  --red-light: #fdecea;
  --blue: #1976d2;
  --blue-light: #e3f0fb;
  --text: #1a1a1a;
  --text-2: #555;
  --text-3: #999;
  --border: #e8e8e8;
  --bg: #f5f5f5;
  --white: #fff;
  --sidebar-w: 220px;
  --topbar-h: 56px;
}

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 16px;
}

.logo-icon {
  font-size: 22px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  transition:
    background 0.15s,
    color 0.15s;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.active {
  background: var(--orange-light);
  color: var(--orange);
  font-weight: 600;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* ── MAIN CONTENT ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  height: 100vh;
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-size: 17px;
  font-weight: 700;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-range {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  cursor: pointer;
}
.date-input:focus {
  outline: none;
  border-color: var(--orange);
}

.date-sep {
  color: var(--text-3);
  font-size: 12px;
}

/* ── PAGES ── */
.page {
  display: none;
  padding: 20px 24px 40px;
}
.page.active {
  display: block;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.97);
}

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

.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover {
  background: #009659;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.btn-ghost:hover {
  background: var(--bg);
}

/* ── KPI ROW ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-family: "DM Mono", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value.orange {
  color: var(--orange);
}
.kpi-value.green {
  color: var(--green);
}
.kpi-value.small {
  font-size: 14px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── CARDS ── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}

.card-title {
  font-weight: 600;
  font-size: 14px;
}

.card-body {
  padding: 16px;
}

/* ── GRIDS ── */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

/* ── TABLES ── */
.table-wrap {
  overflow-x: auto;
}
.pagination-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 4px 4px;
  font-size: 13px;
  color: var(--text-2);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  background: var(--bg);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: #fafafa;
}

.td-right {
  text-align: right;
  font-family: "DM Mono", monospace;
}
.td-center {
  text-align: center;
}

/* ── BADGES / STATUS CHIPS ── */
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-2);
}

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  white-space: nowrap;
}
.chip-green {
  background: var(--green-light);
  color: var(--green);
}
.chip-orange {
  background: var(--orange-light);
  color: var(--orange);
}
.chip-red {
  background: var(--red-light);
  color: var(--red);
}
.chip-blue {
  background: var(--blue-light);
  color: var(--blue);
}
.chip-gray {
  background: var(--bg);
  color: var(--text-3);
}

/* ── LOG BOX ── */
.log-box {
  background: #1a1a1a;
  border-radius: 4px;
  padding: 10px 12px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
  max-height: 120px;
  overflow-y: auto;
  color: #aaa;
  display: none;
}
.log-box.active {
  display: block;
}
.log-ok {
  color: #4caf50;
}
.log-err {
  color: #f44336;
}
.log-warn {
  color: #ff9800;
}
.log-info {
  color: #64b5f6;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  color: var(--text-3);
  padding: 32px 16px;
  font-size: 13px;
}

/* ── HINT TEXT ── */
.hint-text {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 10px;
  line-height: 1.6;
}

/* ── FILTER ROW ── */
.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.select-input,
.text-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
}
.select-input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--orange);
}

/* ── SETTINGS GRID ── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
}

.setting-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: "DM Mono", monospace;
  background: var(--white);
  color: var(--text);
  width: 100%;
}
.setting-input:focus {
  outline: none;
  border-color: var(--orange);
}

/* ── BUDGET SUMMARY BAR ── */
.budget-summary-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.bsb-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bsb-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
}

.bsb-value {
  font-size: 18px;
  font-weight: 700;
  font-family: "DM Mono", monospace;
  color: var(--text);
}
.bsb-value.orange {
  color: var(--orange);
}
.bsb-value.green {
  color: var(--green);
}

/* ── BUDGET TABLE OVERRIDE COLUMN ── */
.override-select {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 11px;
  font-family: inherit;
  background: var(--white);
  cursor: pointer;
}
.override-select:focus {
  outline: none;
  border-color: var(--orange);
}

/* ── ANALYTICS: SPARKLINE TABLE ── */
.sparkline-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sparkline-fill {
  height: 6px;
  border-radius: 3px;
  background: var(--orange);
  min-width: 2px;
  transition: width 0.3s;
}

/* ── STATUS TOAST ── */
.status-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #222;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: opacity 0.2s;
}
.status-toast.hidden {
  opacity: 0;
  pointer-events: none;
}
.status-toast.ok {
  background: #2e7d32;
}
.status-toast.err {
  background: #c62828;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb {
  background: #bbb;
  border-radius: 4px;
  border: 2px solid #f0f0f0;
}
::-webkit-scrollbar-thumb:hover {
  background: #888;
}

/* ── AI ANALYST ── */
.ai-topic-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 4px;
  transition: background 0.12s;
}
.ai-topic-item:hover {
  background: var(--bg);
}
.ai-topic-item input[type="radio"] {
  accent-color: var(--orange);
  width: 14px;
  height: 14px;
}

.ai-result-content {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-result-content h2,
.ai-result-content h3 {
  margin: 14px 0 6px;
  color: var(--text);
}
.ai-result-content h2 {
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.ai-result-content h3 {
  font-size: 13px;
  color: var(--orange);
}
.ai-result-content strong {
  color: var(--text);
}
.ai-result-content ul,
.ai-result-content ol {
  padding-left: 20px;
  margin: 6px 0;
}
.ai-result-content li {
  margin: 3px 0;
}
.ai-result-content code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
}
.ai-result-content blockquote {
  border-left: 3px solid var(--orange);
  margin: 8px 0;
  padding: 6px 12px;
  background: var(--orange-light);
  border-radius: 0 4px 4px 0;
  color: var(--text-2);
}
.ai-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 13px;
  padding: 16px 0;
}
.ai-thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange);
  animation: ai-pulse 1.2s ease-in-out infinite;
}
.ai-thinking-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.ai-thinking-dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes ai-pulse {
  0%,
  80%,
  100% {
    opacity: 0.2;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── RESPONSIVE ── */
@media (max-width: 1200px) {
  .kpi-row {
    grid-template-columns: repeat(3, 1fr);
  }
  .settings-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .budget-summary-bar {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-w: 56px;
  }
  .logo-text,
  .nav-item span:not(.nav-icon) {
    display: none;
  }
  .sidebar-logo {
    justify-content: center;
    padding: 0;
  }
  .nav-item {
    justify-content: center;
    padding: 10px;
  }
  .two-col-grid {
    grid-template-columns: 1fr;
  }
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
}
