:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e0e2e7;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --info-bg: #eff6ff;
  --success: #15803d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1c1f26;
    --surface-2: #23262e;
    --border: #2d313b;
    --text: #e7e9ee;
    --text-muted: #9aa1ac;
    --accent: #5b8def;
    --accent-contrast: #0b1220;
    --danger: #f87171;
    --danger-bg: #2a1414;
    --warning: #fbbf24;
    --warning-bg: #2a2314;
    --info-bg: #142032;
    --success: #4ade80;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }

.muted { color: var(--text-muted); }

/* --- Login --- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 { font-size: 20px; margin: 0; }

.login-card input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
}

.login-card button {
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: pointer;
}

.error { color: var(--danger); font-size: 13px; margin: 0; }

/* --- Shell --- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 16px; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}
.link-btn:hover { color: var(--text); }

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 53px;
  z-index: 9;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.content {
  flex: 1;
  padding: 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* --- Cards / grid --- */

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

.card h2 { margin: 0 0 12px; font-size: 15px; color: var(--text-muted); font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 14px;
}

.stat .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.stat .value { font-size: 20px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.currencies { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* --- Progress bar --- */

.progress-track {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-fill { height: 100%; background: var(--accent); }
.progress-fill.over { background: var(--danger); }

/* --- Table --- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: var(--surface-2); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.large { background: var(--danger-bg); color: var(--danger); }
.badge.marketplace { background: var(--warning-bg); color: var(--warning); }
.badge.guessed { background: var(--info-bg); color: var(--accent); }

select, input[type="text"], input[type="number"], input[type="date"] {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-sm { padding: 2px 8px; font-size: 14px; }
.btn:hover { filter: brightness(0.97); }

/* --- Flags / recommendations lists --- */

.flag-item, .rec-item {
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
}
.flag-item.critical { background: var(--danger-bg); border-left: 3px solid var(--danger); }
.flag-item.warning { background: var(--warning-bg); border-left: 3px solid var(--warning); }
.flag-item.info { background: var(--info-bg); border-left: 3px solid var(--accent); }
.rec-item { background: var(--surface-2); border-left: 3px solid var(--accent); }

.empty-state { color: var(--text-muted); font-size: 14px; padding: 24px; text-align: center; }

.chart-wrap { position: relative; height: 260px; }

.settings-form { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.settings-form label { font-size: 13px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }

.marketplace-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mp-tag {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border-radius: 999px; padding: 4px 10px; font-size: 13px;
}
.mp-tag button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; line-height: 1; }

@media (max-width: 600px) {
  .content { padding: 10px; }
  th, td { padding: 6px 8px; }
}
