/* ============================================================
   PowerShare Analytics Dashboard
   People's Powerhouse - Teal #1A7A6E | Slate #2C3E50
   ============================================================ */

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

:root {
  --teal:       #1A7A6E;
  --teal-dark:  #145f55;
  --teal-light: #e8f4f2;
  --slate:      #2C3E50;
  --slate-mid:  #4a6070;
  --grey-bg:    #EAF6EE;
  --grey-border:#d8dde1;
  --white:      #ffffff;
  --text:       #1a2630;
  --text-muted: #596570;
  --error:      #c0392b;
  --success:    #27ae60;
  --radius:     8px;
  --radius-sm:  5px;
  --shadow:     0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html { font-size: 15px; }
body { font-family: var(--font); color: var(--text); background: var(--grey-bg); line-height: 1.5; }
a { color: var(--teal); }

/* ── Screens ─────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* ── Login ───────────────────────────────────────────────────────────── */
#screen-login {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--grey-bg);
}
#screen-login.active { display: flex; }

.login-wrap {
  width: 100%;
  max-width: 420px;
  padding: 2rem 1rem;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.pp-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  background: var(--teal-light);
  padding: 0.25rem 0.7rem;
  border-radius: 100px;
  margin-bottom: 0.75rem;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--slate);
  margin-bottom: 0.35rem;
}

.login-title span { color: var(--teal); }

.login-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate);
  margin-bottom: 0.3rem;
}

.field input {
  width: 100%;
  border: 1.5px solid var(--grey-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(26,122,110,0.12);
}

.login-error {
  color: var(--error);
  font-size: 0.83rem;
  margin-bottom: 0.75rem;
}

.btn-primary {
  display: block;
  width: 100%;
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--teal-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Dashboard header ────────────────────────────────────────────────── */
.dash-header {
  background: var(--slate);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.dash-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  flex-wrap: wrap;
}

.dash-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.dash-logo-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.dash-logo {
  height: 36px;
  width: auto;
  display: block;
}

.dash-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -0.01em;
}

.dash-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.date-filter-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
}

.date-input {
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: var(--white);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  font-family: var(--font);
}

.date-input:focus { outline: none; border-color: var(--teal); }

.btn-sm {
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}

.btn-sm:hover { background: var(--teal-dark); }

.btn-sm.btn-ghost {
  background: transparent;
  color: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.2);
}

.btn-sm.btn-ghost:hover { background: rgba(255,255,255,0.1); color: var(--white); }

.btn-sm.btn-outline {
  background: transparent;
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.35);
}

.btn-sm.btn-outline:hover { background: rgba(255,255,255,0.1); }

.btn-ghost-sm {
  background: transparent;
  color: rgba(255,255,255,0.6);
  border: none;
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: var(--font);
}

.btn-ghost-sm:hover { color: var(--white); }

/* ── Tabs ────────────────────────────────────────────────────────────── */
.dash-tabs {
  display: flex;
  background: var(--white);
  border-bottom: 1px solid var(--grey-border);
  padding: 0 1.5rem;
  gap: 0;
}

.dash-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.8rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.12s, border-color 0.12s;
  margin-bottom: -1px;
}

.dash-tab:hover { color: var(--slate); }
.dash-tab.active { color: var(--teal); border-bottom-color: var(--teal); }

/* ── Body / panels ───────────────────────────────────────────────────── */
.dash-body {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

.dash-panel { display: block; }
.dash-panel[hidden] { display: none; }

/* ── Loading / error ─────────────────────────────────────────────────── */
.dash-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

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

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

.dash-error {
  background: #fdf2f2;
  border: 1px solid #f5c6cb;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
  color: var(--error);
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ── Stat grid ───────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--teal);
}

.stat-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--slate);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Overview grid ───────────────────────────────────────────────────── */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 800px) {
  .overview-grid { grid-template-columns: 1fr; }
}

/* ── Cards ───────────────────────────────────────────────────────────── */
.dash-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1rem;
}

.dash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--grey-border);
}

.dash-card-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--slate);
}

.dash-card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dash-card-body {
  overflow-x: auto;
}

/* ── Toolbar ─────────────────────────────────────────────────────────── */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  border: 1.5px solid var(--grey-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  font-size: 0.875rem;
  font-family: var(--font);
}

.search-input:focus { outline: none; border-color: var(--teal); }

.select-input {
  border: 1.5px solid var(--grey-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font);
  background: var(--white);
  color: var(--text);
}

.select-input:focus { outline: none; border-color: var(--teal); }

/* ── Tables ──────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.data-table th {
  background: var(--grey-bg);
  padding: 0.6rem 1rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--grey-border);
}

.data-table th.sort-active { color: var(--teal); }

.data-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--grey-bg);
  vertical-align: top;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover { background: #fafbfc; }

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.mini-table th {
  padding: 0.5rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--grey-border);
}

.mini-table td {
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--grey-bg);
}

.mini-table tbody tr:last-child td { border-bottom: none; }

.topics-cell { max-width: 320px; }
.subject-cell { max-width: 220px; }

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem !important;
  font-style: italic;
}

/* ── Badges / tags ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  background: var(--teal-light);
  color: var(--teal-dark);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 100px;
}

.badge--green { background: #d4edda; color: #155724; }
.badge--blue  { background: #d1ecf1; color: #0c5460; }

.tag {
  display: inline-block;
  background: var(--grey-bg);
  color: var(--slate-mid);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 100px;
  margin: 0.1rem 0.1rem 0.1rem 0;
}

.type-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.type-badge--mp       { background: #fce4ec; color: #880e4f; }
.type-badge--unitary  { background: var(--teal-light); color: var(--teal-dark); }
.type-badge--district { background: #e8f5e9; color: #1b5e20; }
.type-badge--county   { background: #e3f2fd; color: #0d47a1; }
.type-badge--combined { background: #fff3e0; color: #bf360c; }
.type-badge--central  { background: #ede7f6; color: #4527a0; }

/* ── Misc ────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.mono  { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.8rem; }

.hint-text {
  font-size: 0.83rem;
  color: var(--text-muted);
  padding: 1rem;
  line-height: 1.5;
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}

.btn-link {
  background: none;
  border: none;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  padding: 0;
  white-space: nowrap;
}

.btn-link:hover { text-decoration: underline; }

/* ── Topics bar chart ────────────────────────────────────────────────── */
.bar-cell { min-width: 120px; }

.bar {
  height: 10px;
  background: var(--teal);
  border-radius: 100px;
  min-width: 2px;
  transition: width 0.3s;
}

.topic-row { cursor: pointer; }
.topic-row.selected { background: var(--teal-light) !important; }
.topic-row.selected td { color: var(--teal-dark); }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.modal-backdrop[hidden] { display: none; }

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 600px;
  animation: slide-up 0.15s ease;
}

@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--grey-border);
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--slate);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
}

.modal-close:hover { color: var(--slate); }

.modal-body {
  padding: 1.25rem;
}

.modal-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
}

.modal-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.83rem;
  margin-bottom: 1.25rem;
}

.modal-dl dt {
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.modal-section {
  margin-bottom: 1.1rem;
}

.modal-section h4 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.modal-section p {
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.6;
}

.letter-text {
  white-space: pre-wrap;
  background: var(--grey-bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.83rem !important;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .dash-header-inner { flex-direction: column; align-items: flex-start; }
  .date-filter-wrap { flex-wrap: wrap; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-body { padding: 1rem; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
}
