/* ── Reset & custom properties ─────────────────────────────── */

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

:root {
  --sidebar-w: 280px;
  --header-h: 56px;

  --clr-bg: #f5f6f8;
  --clr-surface: #ffffff;
  --clr-border: #dfe3e8;
  --clr-text: #1e1e2e;
  --clr-text-muted: #636578;
  --clr-accent: #2e5cb8;
  --clr-accent-hover: #1d4196;
  --clr-accent-light: #e8eef8;
  --clr-error: #c53030;
  --clr-error-bg: #fff5f5;
  --clr-info: #2b6cb0;
  --clr-info-bg: #ebf4ff;

  --radius: 6px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
  --transition: 150ms ease;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--clr-text);
  background: var(--clr-bg);
}


/* ── Global hidden fix ─────────────────────────────────────── */

[hidden] {
  display: none !important;
}

/* ── Header ────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
}

.site-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
}

.header-sub {
  font-size: 0.8rem;
  color: var(--clr-text-muted);
}


.header-product {
  margin: .15rem 0 0;
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent, #f0c040);
  opacity: .9;
}

/* Hamburger */
.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--clr-text);
  border-radius: 1px;
  transition: var(--transition);
}


/* ── Layout ────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}


/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 16px;
  background: var(--clr-surface);
  border-right: 1px solid var(--clr-border);
  display: flex;
  flex-direction: column;
}

.sidebar form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar fieldset {
  border: none;
  padding: 0;
}

.sidebar legend {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--clr-text-muted);
  margin-bottom: 6px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  font-size: 0.78rem;
  color: var(--clr-text-muted);
}

.sidebar-footer a {
  color: var(--clr-accent);
}

.footer-sep {
  margin: 0 .25rem;
  opacity: .5;
}


/* ── FAQ modal ─────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
}

.modal {
  position: relative;
  width: min(36rem, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface, #1e1e2e);
  border: 1px solid var(--border, #333);
  border-radius: .75rem;
  padding: 2rem 2rem 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.modal h2 {
  margin: 0 0 1.25rem;
  font-size: 1.3rem;
}

.modal-close {
  position: absolute;
  top: .75rem;
  right: .75rem;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  opacity: .6;
}
.modal-close:hover { opacity: 1; }

.modal details {
  margin-bottom: .75rem;
  border: 1px solid var(--border, #333);
  border-radius: .4rem;
  padding: .5rem .75rem;
}

.modal summary {
  cursor: pointer;
  font-weight: 600;
  padding: .25rem 0;
}

.modal details[open] summary {
  margin-bottom: .5rem;
}

.modal ol {
  padding-left: 1.25rem;
  margin: .5rem 0;
}

/* ── Form controls ─────────────────────────────────────────── */

input[type="text"],
input[type="month"],
select {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.9rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  background: var(--clr-surface);
  color: var(--clr-text);
  transition: border-color var(--transition);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--clr-accent);
  box-shadow: 0 0 0 3px var(--clr-accent-light);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-row input[type="month"] {
  flex: 1;
  min-width: 0;
}

.input-sep {
  color: var(--clr-text-muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.field-hint {
  margin-top: 6px;
  padding: 8px 10px;
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--clr-accent-light);
  border-radius: var(--radius);
  color: var(--clr-text);
}

.field-hint.error {
  background: var(--clr-error-bg);
  color: var(--clr-error);
}


/* ── Buttons ───────────────────────────────────────────────── */

.btn-small {
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  background: var(--clr-surface);
  color: var(--clr-text);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.btn-small:hover {
  background: var(--clr-bg);
}

.btn-apply {
  width: 100%;
  padding: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  background: var(--clr-accent);
  color: #fff;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-apply:hover {
  background: var(--clr-accent-hover);
}

.btn-apply:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


.btn-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border-radius: 50%;
  font-weight: 700;
  font-size: .85rem;
  text-decoration: none;
  text-align: center;
  flex-shrink: 0;
}


/* ── Toggle group (frequency) ──────────────────────────────── */

.toggle-group {
  display: flex;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.toggle-group button {
  flex: 1;
  padding: 7px 0;
  font-size: 0.82rem;
  font-weight: 500;
  border: none;
  background: var(--clr-surface);
  color: var(--clr-text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.toggle-group button:not(:last-child) {
  border-right: 1px solid var(--clr-border);
}

.toggle-group button.active {
  background: var(--clr-accent);
  color: #fff;
  font-weight: 700;
}

.toggle-group button:hover:not(.active) {
  background: var(--clr-bg);
}


/* ── Custom partner selector ───────────────────────────────── */

.partner-custom {
  margin-top: 8px;
}

.search-input {
  margin-bottom: 6px;
}

.partner-checklist {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.partner-checklist label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  font-size: 0.82rem;
  border-radius: 3px;
  cursor: pointer;
}

.partner-checklist label:hover {
  background: var(--clr-bg);
}

.partner-checklist label.hidden {
  display: none;
}


/* ── Main content ──────────────────────────────────────────── */

.main {
  padding: 20px 24px;
  position: relative;
  min-height: 400px;
}


/* ── Welcome state ─────────────────────────────────────────── */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 50vh;
  gap: 10px;
  color: var(--clr-text-muted);
}

.welcome h2 {
  font-size: 1.5rem;
  color: var(--clr-text);
}

.welcome code {
  background: var(--clr-accent-light);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}

.hint {
  font-size: 0.88rem;
}


/* ── Loading overlay ───────────────────────────────────────── */

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(245, 246, 248, 0.85);
  z-index: 50;
  border-radius: var(--radius);
}

.loading[hidden] {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--clr-border);
  border-top-color: var(--clr-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading p {
  font-size: 0.9rem;
  color: var(--clr-text-muted);
  text-align: center;
  max-width: 320px;
}


/* ── Error banner ──────────────────────────────────────────── */

.error-banner {
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--clr-error-bg);
  color: var(--clr-error);
  border: 1px solid #feb2b2;
  border-radius: var(--radius);
  font-size: 0.88rem;
}


/* ── Info banner (reporter tab) ────────────────────────────── */

.info-banner {
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--clr-info-bg);
  color: var(--clr-info);
  border: 1px solid #bee3f8;
  border-radius: var(--radius);
  font-size: 0.88rem;
}


/* ── Tabs ──────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--clr-border);
}

.tab {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--clr-text-muted);
  cursor: pointer;
  position: relative;
  transition: color var(--transition);
}

.tab::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  transition: background var(--transition);
}

.tab:hover {
  color: var(--clr-text);
}

.tab.active {
  color: var(--clr-accent);
}

.tab.active::after {
  background: var(--clr-accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}


/* ── Chart grid ────────────────────────────────────────────── */

.chart-grid {
  display: grid;
  gap: 20px;
}

.grid-2x2 {
  grid-template-columns: 1fr 1fr;
}

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

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

.chart-header h3 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--clr-text);
}

.btn-csv {
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--clr-border);
  border-radius: 3px;
  background: var(--clr-surface);
  color: var(--clr-text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.btn-csv:hover {
  background: var(--clr-bg);
  color: var(--clr-text);
}

.chart-card canvas {
  width: 100% !important;
  height: auto !important;
  max-height: 300px;
}

/* ── Chart export buttons ──────────────────────────────────── */

.chart-actions {
  display: flex;
  gap: 4px;
}

.btn-export {
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--clr-border);
  border-radius: 3px;
  background: var(--clr-surface);
  color: var(--clr-text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.btn-export:hover {
  background: var(--clr-bg);
  color: var(--clr-text);
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .grid-2x2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar-toggle {
    display: flex;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 300px;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow-md);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Backdrop */
  .sidebar.open::after {
    content: "";
    position: fixed;
    top: 0;
    left: 300px;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.3);
  }
  
  .main {
    padding: 16px 12px;
  }
}

/* ── Editable chart titles ─────────────────────────────────── */

.chart-header h3 {
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color var(--transition), color var(--transition);
}

.chart-header h3:hover {
  border-bottom-color: var(--clr-text-muted);
  color: var(--clr-accent);
}

.chart-header h3.has-custom {
  font-style: italic;
}

.chart-header:has(.chart-title-edit) {
  flex-wrap: wrap;
}

.chart-title-edit {
  width: 100%;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--clr-text);
  padding: 4px 8px;
  border: 1px solid var(--clr-accent);
  border-radius: var(--radius);
  background: var(--clr-surface);
  box-shadow: 0 0 0 3px var(--clr-accent-light);
  resize: vertical;
  min-height: 2.4em;
  max-height: 6em;
  line-height: 1.4;
}

.chart-title-edit:focus {
  outline: none;
}

.welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 1rem 0;
}

.example-btn {
  background: #f0f1f5;
  border: 1px solid #d0d3dc;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
