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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f6fa;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: #1a1a2e;
  color: #fff;
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
header h1 { font-size: 1.4rem; font-weight: 600; letter-spacing: 0.02em; }
.header-back {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.header-back:hover { background: rgba(255,255,255,0.25); }

/* ── Upload screen ── */
#upload-screen main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 68px);
  padding: 2rem;
}
.upload-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.09);
  padding: 3rem 3.5rem;
  text-align: center;
  max-width: 480px;
  width: 100%;
}
.upload-card h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.5rem; }
.upload-card p  { font-size: 0.9rem; color: #666; margin-bottom: 2rem; line-height: 1.5; }
.dropzone {
  border: 2px dashed #c8ccd8;
  border-radius: 10px;
  padding: 2.5rem 1.5rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 1rem;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: #4f6ef7;
  background: #f0f3ff;
}
.dropzone-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.dropzone-text { font-size: 0.9rem; color: #555; }
.dropzone-text strong { color: #4f6ef7; }
.upload-btn {
  display: inline-block;
  background: #1a1a2e;
  color: #fff;
  padding: 0.65rem 1.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background 0.15s;
}
.upload-btn:hover { background: #2d2d4e; }
#file-input { display: none; }
.upload-error {
  margin-top: 1rem;
  color: #e53e3e;
  font-size: 0.85rem;
  display: none;
}
.privacy-note {
  margin-top: 1.5rem;
  font-size: 0.78rem;
  color: #aaa;
  line-height: 1.5;
}

/* ── Report screen ── */
#report-screen { display: none; }
#report-screen main { padding: 2rem; max-width: 1400px; margin: 0 auto; }

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 1.75rem;
  border-bottom: 2px solid #e0e0e0;
}
.tab-btn {
  padding: 0.7rem 1.5rem;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  font-family: inherit;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: #555; }
.tab-btn.active { color: #1a1a2e; border-bottom-color: #4f6ef7; }

/* ── Date range row ── */
.date-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.date-row label { font-size: 0.9rem; font-weight: 500; color: #555; }
.date-row input[type="date"] {
  border: 1px solid #d0d3de;
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: #1a1a2e;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.date-row input[type="date"]:focus { border-color: #4f6ef7; }

/* ── KPI cards ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.kpi-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  border-top: 4px solid transparent;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.kpi-card.red   { border-top-color: #e53e3e; }
.kpi-card.orange{ border-top-color: #dd6b20; }
.kpi-card.green { border-top-color: #38a169; }
.kpi-card.blue  { border-top-color: #4f6ef7; }
.kpi-label { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: #888; margin-bottom: 0.4rem; }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.kpi-card.red   .kpi-value { color: #e53e3e; }
.kpi-card.orange .kpi-value { color: #dd6b20; }
.kpi-card.green .kpi-value { color: #38a169; }
.kpi-card.blue  .kpi-value { color: #4f6ef7; }
.kpi-pct { font-size: 0.85rem; color: #aaa; margin-top: 0.3rem; }

/* ── Filter buttons ── */
.filter-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 0.45rem 1.1rem;
  border: 2px solid transparent;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  background: #fff;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.filter-btn.all    { color: #4f6ef7; border-color: #4f6ef7; }
.filter-btn.red    { color: #e53e3e; border-color: #e53e3e; }
.filter-btn.orange { color: #dd6b20; border-color: #dd6b20; }
.filter-btn.green  { color: #38a169; border-color: #38a169; }
.filter-btn.all.active    { background: #4f6ef7; color: #fff; }
.filter-btn.red.active    { background: #e53e3e; color: #fff; }
.filter-btn.orange.active { background: #dd6b20; color: #fff; }
.filter-btn.green.active  { background: #38a169; color: #fff; }

/* ── Search input ── */
.search-input {
  border: 1px solid #d0d3de;
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: #1a1a2e;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  max-width: 400px;
  margin-bottom: 1.25rem;
}
.search-input:focus { border-color: #4f6ef7; }
.search-input::placeholder { color: #aaa; }

/* ── Export button ── */
.export-btn {
  padding: 0.45rem 1.1rem;
  border: 2px solid #888;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  background: #fff;
  color: #555;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  margin-left: auto;
}
.export-btn:hover { background: #f0f1f5; border-color: #555; color: #333; }
.export-btn + .export-btn { margin-left: 0.5rem; }

/* ── Category color dot ── */
.cat-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.5rem;
  vertical-align: middle;
}
.cat-dot.red    { background: #e53e3e; }
.cat-dot.orange { background: #dd6b20; }
.cat-dot.green  { background: #38a169; }

/* ── Chart wrap ── */
.chart-wrap {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.75rem;
  display: none;
}
.chart-wrap.visible { display: block; }
.chart-wrap h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.75rem;
}
.chart-toggle {
  padding: 0.45rem 1.1rem;
  border: 2px solid #aaa;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  background: #fff;
  color: #666;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  margin-left: 0.6rem;
}
.chart-toggle:hover { border-color: #666; color: #333; }
.chart-toggle.active { background: #555; color: #fff; border-color: #555; }

/* ── Chart controls ── */
.chart-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}
.chart-controls-group {
  display: flex;
  gap: 0;
  border: 1px solid #d0d3de;
  border-radius: 6px;
  overflow: hidden;
  margin-right: 1rem;
}
.chart-ctrl-btn {
  padding: 0.35rem 0.85rem;
  border: none;
  background: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: #666;
  transition: background 0.15s, color 0.15s;
  border-right: 1px solid #d0d3de;
}
.chart-ctrl-btn:last-child { border-right: none; }
.chart-ctrl-btn:hover { background: #f0f1f5; }
.chart-ctrl-btn.active { background: #4f6ef7; color: #fff; }
.chart-selection-label {
  font-size: 0.8rem;
  color: #888;
  font-style: italic;
  margin-left: auto;
}

/* ── Content area ── */
.content-area {
  display: block;
}

/* ── Tables ── */
.table-wrap {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  overflow: hidden;
}
.table-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #eee;
  font-weight: 600;
  font-size: 0.9rem;
  color: #555;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  background: #f9f9fb;
  padding: 0.7rem 1rem;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:first-child { text-align: center; }
thead th:nth-child(2) { text-align: left; }
.sort-icon { display: inline-block; width: 1em; text-align: center; opacity: 0.4; font-style: normal; }
thead th.sorted .sort-icon { opacity: 1; }
tbody tr { cursor: pointer; transition: background 0.1s; border-bottom: 1px solid #f0f0f4; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f5f6fa; }
tbody tr.selected { background: #eef1ff; }
tbody td { padding: 0.75rem 1rem; font-size: 0.9rem; text-align: center; }
tbody td:first-child { text-align: center; }
tbody td:nth-child(2) { font-weight: 500; text-align: left; }
.empty-msg { padding: 2.5rem 1rem; text-align: center; color: #aaa; font-size: 0.9rem; }

/* ── Checkbox column ── */
.chart-cb {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #4f6ef7;
}
thead th.cb-col {
  width: 40px;
  min-width: 40px;
  cursor: default;
}

/* ── Modal overlay ── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.modal-overlay.visible {
  display: flex;
}
.modal-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  max-width: 800px;
  width: 95%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; line-height: 1.3; color: #1a1a2e; }
.modal-close {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: #aaa; flex-shrink: 0; line-height: 1; padding: 0 0.2rem;
}
.modal-close:hover { color: #555; }
.modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 0;
}
.modal-table-wrap { padding: 0 0 1rem 0; }
.modal-table-wrap table { font-size: 0.9rem; }
.modal-table-wrap thead th { font-size: 0.78rem; cursor: pointer; }
.modal-table-wrap tbody td { padding: 0.65rem 1rem; font-size: 0.9rem; }
.modal-table-wrap thead th:first-child { text-align: left; }
.modal-table-wrap tbody td:first-child { text-align: left; }
.no-appts { padding: 2rem 1.25rem; color: #aaa; font-size: 0.9rem; text-align: center; }

/* ── Tab content visibility ── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Print / PDF export ── */
@media print {
  #upload-screen,
  .tab-bar,
  .filter-row,
  .search-input,
  .chart-wrap,
  .date-row,
  .modal-overlay,
  .header-back,
  .cb-col,
  thead th.cb-col,
  tbody td.cb-cell {
    display: none !important;
  }
  #report-screen { display: block !important; }
  body { background: #fff; }
  .table-wrap { box-shadow: none; }
  .kpi-row { margin-bottom: 1rem; }
  .tab-content { display: none !important; }
  .tab-content.active { display: block !important; }
  header { background: #1a1a2e; color: #fff; }
  .print-header {
    display: block !important;
    padding: 1rem 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid #1a1a2e;
    font-size: 0.9rem;
    color: #555;
  }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
}
.print-header { display: none; }

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