:root {
  --bg: #0f1117;
  --bg-elevated: #171a21;
  --bg-soft: #1f2430;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f6fb;
  --text-muted: #9aa3b5;
  --accent: #6750a4;
  --accent-soft: rgba(103, 80, 164, 0.18);
  --accent-strong: #8b6fd0;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --radius: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Manrope", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(103, 80, 164, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.12), transparent 24%),
    var(--bg);
  color: var(--text);
}

button, input {
  font: inherit;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 420px);
  padding: 32px;
  border-radius: 28px;
  background: rgba(23, 26, 33, 0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: rise 0.6s ease;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--accent-soft);
  font-size: 32px;
}

.login-brand h1,
.header h1,
.chart-header h2,
.table-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.login-brand p,
.header p,
.chart-header p,
.table-header p {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 8px;
}

.login-form span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: var(--bg-soft);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  animation: rise 0.5s ease;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white;
  box-shadow: 0 12px 30px rgba(103, 80, 164, 0.35);
}

.logo-mark svg {
  width: 28px;
  height: 28px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5b47b8);
  color: white;
  box-shadow: 0 10px 24px rgba(103, 80, 164, 0.35);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.filters-panel,
.kpi-card,
.chart-card,
.table-section {
  background: rgba(23, 26, 33, 0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.filters-panel {
  padding: 22px;
  margin-bottom: 24px;
  animation: rise 0.55s ease;
}

.filters-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
  align-items: end;
}

.filter-group label {
  display: block;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.period-controls {
  display: grid;
  gap: 10px;
}

.quick-ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.chip.active,
.chip:hover {
  color: white;
  background: var(--accent-soft);
  border-color: rgba(103, 80, 164, 0.45);
}

#date-range,
.filter-select {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: var(--bg-soft);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-select {
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) calc(50% - 3px),
    calc(100% - 16px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 42px;
}

#date-range:focus,
.filter-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.filter-select option {
  background: var(--bg-elevated);
  color: var(--text);
}

.multi-select {
  min-height: 48px;
  padding: 8px;
  border-radius: 14px;
  background: var(--bg-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.multi-select button.option {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}

.multi-select button.option.selected {
  background: var(--accent-soft);
  color: white;
  border-color: rgba(103, 80, 164, 0.5);
}

.multi-select-scroll {
  max-height: 220px;
  overflow-y: auto;
  align-content: flex-start;
}

.filters-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.loading-state,
.empty-state {
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
}

/* Author display:grid overrides the UA [hidden] rule — force hide when attribute is set */
.loading-state[hidden],
.empty-state[hidden],
.dashboard[hidden] {
  display: none !important;
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent-strong);
  animation: spin 0.8s linear infinite;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.kpi-card {
  padding: 22px;
  position: relative;
  overflow: hidden;
  animation: rise 0.55s ease backwards;
  animation-delay: var(--delay);
}

.kpi-card::after {
  content: "";
  position: absolute;
  inset: auto -30px -30px auto;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(103, 80, 164, 0.22), transparent 70%);
}

.kpi-label {
  display: block;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.kpi-value {
  font-size: 2rem;
  line-height: 1;
}

.kpi-unit {
  display: inline-block;
  margin-left: 8px;
  color: var(--text-muted);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.chart-card {
  padding: 20px;
  animation: rise 0.6s ease backwards;
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.chart {
  width: 100%;
  height: 320px;
}

.table-section {
  padding: 20px;
  animation: rise 0.65s ease backwards;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.table-actions {
  display: flex;
  flex-shrink: 0;
  gap: 10px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn-icon.is-loading svg {
  opacity: 0.35;
}

.table-wrap {
  overflow: auto;
  margin-top: 16px;
}

.table-footer {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.table-footer .btn[hidden] {
  display: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
}

tbody tr {
  animation: fadeIn 0.35s ease backwards;
}

tbody tr:hover {
  background: var(--surface-hover);
}

.empty-icon {
  font-size: 48px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1100px) {
  .filters-grid,
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app {
    padding: 16px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .table-header {
    flex-direction: column;
  }

  .filters-grid,
  .kpi-grid,
  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart {
    height: 280px;
  }
}
