/* =========================================================================
   School Intake Calculator — styles
   Colour comes entirely from CSS custom properties so dark mode and color
   themes are each a single block of variable overrides, not a second copy
   of every rule.
   ========================================================================= */

:root {
  --primary-color: #1B214F;
  --secondary-color: #28BBAC;
  --accent-color: #4fc3f7;
  --background-color: #f0f4f8;
  --surface-color: #fff;
  --text-color: #1f2430;
  --text-light: #667085;
  --border-color: #e4e9f0;
  --shadow: rgba(27, 33, 79, 0.10);
  --hover-bg: #e6f8f6;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --transition: 0.2s ease;
}

/* Scoped to the "body" tag specifically (not a bare attribute selector) so this
   only ever styles the page's active theme, not the theme-picker cards below -
   each of those also carries its own data-theme attribute to identify itself to JS. */
body[data-theme="corporate"] {
  --primary-color: #2563eb;
  --secondary-color: #0ea5e9;
  --accent-color: #38bdf8;
  --background-color: #f1f5f9;
  --border-color: #dce7f5;
  --shadow: rgba(37, 99, 235, 0.14);
  --hover-bg: #e0f2fe;
}

body[data-theme="school-brand"] {
  --primary-color: var(--brand-primary, #1B214F);
  --secondary-color: var(--brand-secondary, #28BBAC);
  --accent-color: var(--brand-accent, #4fc3f7);
}

body.dark-mode {
  --background-color: #14161f;
  --surface-color: #1e2130;
  --text-color: #e7e9ef;
  --text-light: #9aa2b1;
  --border-color: #333748;
  --shadow: rgba(0, 0, 0, 0.35);
  --hover-bg: #2a2e42;
}

body.dark-mode:not([data-theme="corporate"]):not([data-theme="school-brand"]) {
  --primary-color: #5b6ee8;
  --secondary-color: #2dd4c6;
}

body.dark-mode[data-theme="corporate"] {
  --primary-color: #5b8def;
  --secondary-color: #38bdf8;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--background-color);
  margin: 0;
  padding: 0;
  color: var(--text-color);
  transition: background-color var(--transition), color var(--transition);
}

.container {
  max-width: 980px;
  margin: 32px auto;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: 0 20px 50px var(--shadow);
}

a { color: inherit; }

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.logo {
  width: 96px;
  height: 96px;
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
}

.logo img { width: 100%; height: 100%; object-fit: contain; }

.header-text { flex-grow: 1; min-width: 200px; }

header h1 {
  font-weight: 800;
  font-size: 1.9rem;
  letter-spacing: -0.01em;
  color: var(--primary-color);
  margin: 0;
}

.school-subtitle {
  color: var(--text-light);
  font-size: 1rem;
  margin: 6px 0 0 0;
  display: none;
}

.school-subtitle.show { display: block; }

/* ---------- Date + Year section ---------- */
.date-year-section {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
}

.date-input-section,
.year-display-section {
  flex: 1;
  background: var(--background-color);
  padding: 18px;
  border: 1px solid var(--border-color);
  text-align: center;
}

.date-input-section { border-radius: var(--radius-md) 0 0 var(--radius-md); border-right: none; }
.year-display-section { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-left: none; }

.quick-date-presets {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.preset-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--surface-color);
  color: var(--text-light);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.preset-btn:hover { border-color: var(--secondary-color); background: var(--secondary-color); color: #fff; }

.section-title { margin: 0 0 10px 0; color: var(--primary-color); font-size: 1.05rem; font-weight: 700; }
.section-description { margin: 0 0 12px 0; color: var(--text-light); font-size: 0.83rem; font-style: italic; }

.date-input-item { display: flex; flex-direction: column; align-items: center; }
.date-input-item label { font-weight: 600; margin-bottom: 6px; color: var(--text-light); font-size: 0.85rem; }

.year-display-row { display: flex; gap: 0; justify-content: center; }
.year-item { flex: 1; min-width: 150px; max-width: 240px; }
.year-item:first-child { background: var(--primary-color); color: #fff; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.year-item:last-child { background: var(--secondary-color); color: #fff; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.year-item label { display: block; font-size: 0.78rem; margin-bottom: 3px; opacity: 0.9; padding-top: 10px; }
.year-item .value { font-size: 1.05rem; font-weight: 700; padding: 6px 12px 10px 12px; }

.year-range-caption {
  margin: 12px 0 0 0;
  font-size: 0.78rem;
  color: var(--text-light);
}

/* ---------- Collapsible cards (DOB lookup, visibility/highlight groups) ---------- */
.collapsible-card {
  background: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  overflow: hidden;
}

.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  padding: 14px 18px;
  transition: background-color var(--transition);
}

.collapsible-header:hover { background: var(--hover-bg); }
.collapsible-header h3, .collapsible-header h4 { margin: 0; color: var(--primary-color); font-size: 1rem; font-weight: 700; }
.collapsible-header .subtext { display: block; font-weight: 400; font-size: 0.8rem; color: var(--text-light); margin-top: 2px; }

.dropdown-arrow {
  width: 24px;
  height: 24px;
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--secondary-color);
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  transition: transform var(--transition), background-color var(--transition);
}

.dropdown-arrow:hover { background: var(--primary-color); }
.dropdown-arrow.expanded { transform: rotate(180deg); }

.collapsible-content { max-height: 0; overflow: hidden; opacity: 0; transition: max-height 0.3s ease, opacity 0.3s ease; padding: 0 18px; }
.collapsible-content.expanded { max-height: 600px; opacity: 1; padding: 0 18px 18px 18px; }

.dob-lookup-grid { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.dob-lookup-grid .dropdown { flex: 1 1 180px; }
.dob-hint { font-size: 0.78rem; color: var(--text-light); margin: 0 0 12px 0; }
.dob-result-box { background: var(--surface-color); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 14px 16px; }
.dob-placeholder { margin: 0; color: var(--text-light); font-size: 0.9rem; }
.dob-result { margin: 0 0 10px 0; font-size: 0.95rem; }
.dob-result:last-child { margin-bottom: 0; }
.dob-detail-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.dob-detail-list li { display: flex; justify-content: space-between; gap: 10px; background: var(--background-color); border-radius: 6px; padding: 6px 10px; font-size: 0.85rem; }
.dob-detail-list li span { color: var(--text-light); }
.dob-detail-list li strong { color: var(--primary-color); }

/* ---------- Action buttons ---------- */
.action-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-bottom: 12px; flex-wrap: wrap; }

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--background-color);
  color: var(--text-light);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
  text-decoration: none;
}

.action-btn:hover { background: var(--secondary-color); color: #fff; border-color: var(--secondary-color); transform: translateY(-1px); box-shadow: 0 4px 10px var(--shadow); }
.action-btn.primary { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }
.action-btn.primary:hover { background: var(--secondary-color); border-color: var(--secondary-color); }

/* ---------- Settings trigger ---------- */
.settings-section { display: flex; justify-content: flex-end; margin-bottom: 14px; }

.settings-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--primary-color);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 14px var(--shadow);
  transition: all var(--transition);
}

.settings-button:hover { background: var(--secondary-color); transform: translateY(-1px); }
.settings-button .settings-icon { transition: transform var(--transition); }
.settings-button:hover .settings-icon { transform: rotate(60deg); }

/* ---------- Settings modal ---------- */
.settings-popup {
  position: fixed; inset: 0;
  background: rgba(10, 12, 20, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: 16px;
}

.settings-popup.show { display: flex; }

.settings-content {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 760px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.settings-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; padding-bottom: 14px; border-bottom: 2px solid var(--border-color); }
.settings-header h3 { margin: 0; color: var(--primary-color); font-size: 1.25rem; font-weight: 700; }

.close-button {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--background-color); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-light); transition: all var(--transition);
}

.close-button:hover { background: var(--primary-color); color: #fff; }

.settings-tabs { display: flex; gap: 4px; margin-bottom: 22px; border-bottom: 1px solid var(--border-color); flex-wrap: wrap; }

.settings-tab {
  padding: 10px 18px; background: none; border: none; color: var(--text-light);
  cursor: pointer; border-bottom: 2px solid transparent; transition: all var(--transition);
  font-weight: 600; font-size: 0.92rem;
}

.settings-tab.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.settings-tab:hover { color: var(--primary-color); background: var(--background-color); }

.settings-tab-content { display: none; }
.settings-tab-content.active { display: block; animation: fadeIn 0.25s ease; }

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

.dropdowns-grid { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.dropdown { flex: 1 1 200px; display: flex; flex-direction: column; }
.dropdown label { font-weight: 600; margin-bottom: 6px; color: var(--text-light); font-size: 0.88rem; }

input[type="date"], input[type="text"], input[type="number"], input[type="email"], select, textarea {
  padding: 11px 14px; font-size: 1rem; border-radius: var(--radius-sm);
  border: 2px solid var(--border-color); transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--surface-color); color: var(--text-color); font-family: inherit;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--secondary-color); box-shadow: 0 0 0 4px var(--hover-bg); }

body.dark-mode input[type="date"] { color-scheme: dark; }

/* ---------- Color theme picker ---------- */
.color-theme-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; margin: 15px 0; }

.theme-option {
  display: flex; flex-direction: column; align-items: center; padding: 14px;
  border: 2px solid var(--border-color); border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--transition); background: var(--surface-color);
}

.theme-option:hover { transform: translateY(-2px); box-shadow: 0 6px 14px var(--shadow); }
.theme-option.active { border-color: var(--secondary-color); background: var(--background-color); }
.theme-preview { width: 60px; height: 36px; border-radius: 8px; margin-bottom: 8px; display: flex; overflow: hidden; }
.theme-preview .color-strip { flex: 1; height: 100%; }
.theme-label { font-size: 0.8rem; font-weight: 600; color: var(--text-color); text-align: center; }

/* ---------- Settings sub-sections (branding, calendar, install) ---------- */
.settings-subsection { background: var(--background-color); padding: 20px; border-radius: var(--radius-md); margin-bottom: 18px; }
.settings-subsection h4 { margin: 0 0 14px 0; color: var(--primary-color); font-size: 1.05rem; }

.brand-colors-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 14px 0 0 0; }
.color-input-group { display: flex; flex-direction: column; }
.color-input-group label { font-size: 0.85rem; margin-bottom: 5px; color: var(--text-light); }
.color-input-wrapper { display: flex; gap: 10px; align-items: center; }

input[type="color"] { width: 44px; height: 38px; border: none; border-radius: 8px; cursor: pointer; padding: 0; }

.calendar-override-toggle { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }

.toggle-switch {
  position: relative; width: 50px; height: 26px; min-width: 50px;
  background: var(--border-color); border-radius: 13px; cursor: pointer; transition: background var(--transition);
}

.toggle-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px;
  background: #fff; border-radius: 50%; transition: transform var(--transition); box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle-switch.active { background: var(--secondary-color); }
.toggle-switch.active::after { transform: translateX(24px); }

.install-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--background-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-top: 4px;
}

.install-row p { margin: 0; font-size: 0.9rem; color: var(--text-color); }
.install-row .action-btn.primary { white-space: nowrap; }

/* ---------- Visibility / highlight toggle groups ---------- */
.controls-section { padding-top: 20px; border-top: 1px solid var(--border-color); margin-top: 20px; }
.controls-section:first-child { padding-top: 0; border-top: none; margin-top: 0; }

.toggle-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.toggle-btn {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 2px solid var(--border-color); border-radius: var(--radius-sm);
  background: var(--surface-color); color: var(--text-light);
  font-size: 0.88rem; font-weight: 500; cursor: pointer; transition: all var(--transition);
}

.toggle-btn:hover { border-color: var(--secondary-color); background: var(--hover-bg); }
.toggle-btn.active { border-color: var(--secondary-color); background: var(--secondary-color); color: #fff; }
.toggle-indicator { width: 10px; height: 10px; border-radius: 50%; background: #ccc; transition: background-color var(--transition); }
.toggle-btn.active .toggle-indicator { background: #fff; }

.warning-message {
  display: none; padding: 10px 15px; margin-top: 12px;
  background: #fff3cd; border: 1px solid #ffeaa7; border-radius: var(--radius-sm);
  color: #856404; font-size: 0.88rem; font-weight: 500;
}

.warning-message.show { display: block; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0 10px; font-size: 0.95rem; table-layout: fixed; }
thead th { background: var(--primary-color); color: #fff; font-weight: 700; padding: 13px 10px; text-align: center; }
thead th:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
thead th:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

tbody tr { background: var(--background-color); box-shadow: 0 2px 6px var(--shadow); transition: background-color var(--transition); }
tbody tr:hover { background: var(--hover-bg); }
tbody td { padding: 13px 10px; text-align: center; vertical-align: middle; color: var(--text-color); font-weight: 600; }
tbody td:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
tbody td:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.year-label { color: var(--primary-color); font-weight: 700; }

.highlight-intake { background-color: var(--primary-color) !important; color: #fff !important; font-weight: 700; border-radius: 8px; box-shadow: 0 0 0 2px var(--shadow); }
.highlight-exit { background-color: var(--secondary-color) !important; color: #fff !important; font-weight: 700; border-radius: 8px; box-shadow: 0 0 0 2px var(--shadow); }

/* ---------- Mobile cards ---------- */
.mobile-cards { display: none; }

.mobile-card { background: var(--background-color); border-radius: var(--radius-md); padding: 18px; margin-bottom: 14px; box-shadow: 0 2px 8px var(--shadow); }
.mobile-card-header { background: var(--primary-color); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); margin: -18px -18px 14px -18px; font-weight: 700; font-size: 1.05rem; text-align: center; }
.mobile-card-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-color); gap: 10px; }
.mobile-card-row:last-child { border-bottom: none; }
.mobile-card-label { font-weight: 600; color: var(--text-light); font-size: 0.88rem; flex: 1; }
.mobile-card-value { font-weight: 700; color: var(--text-color); font-size: 0.98rem; text-align: right; padding: 6px 12px; border-radius: 6px; min-width: 60px; }
.mobile-card-value.empty { color: var(--text-light); font-weight: 500; }

/* ---------- Mobile FAB ---------- */
.fab-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: none; }
.fab { width: 56px; height: 56px; border-radius: 50%; background: var(--primary-color); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 20px; box-shadow: 0 8px 20px var(--shadow); transition: all var(--transition); }
.fab:hover { background: var(--secondary-color); transform: scale(1.08); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .container { margin: 10px; padding: 16px; }
  header { flex-direction: column; gap: 10px; margin-bottom: 18px; }
  .logo { width: 60px; height: 60px; }
  header h1 { font-size: 1.3rem; }
  .school-subtitle { font-size: 0.9rem; }

  .settings-content { padding: 16px; max-height: 88vh; border-radius: var(--radius-md); }
  .settings-tab { padding: 8px 12px; font-size: 0.8rem; flex: 1; min-width: 78px; text-align: center; }

  .date-year-section { flex-direction: column; gap: 0; }
  .date-input-section { border-radius: var(--radius-md) var(--radius-md) 0 0; border-right: 1px solid var(--border-color); border-bottom: none; }
  .year-display-section { border-radius: 0 0 var(--radius-md) var(--radius-md); border-left: 1px solid var(--border-color); border-top: none; }
  .year-display-row { flex-direction: column; gap: 0; }
  .year-item { min-width: auto; max-width: none; padding: 8px 0; }
  .year-item:first-child { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
  .year-item:last-child { border-radius: 0 0 var(--radius-sm) var(--radius-sm); }

  .dropdowns-grid { flex-direction: column; gap: 12px; margin-bottom: 16px; }
  .dropdown { flex: none; width: 100%; }

  .color-theme-grid { grid-template-columns: 1fr 1fr; }
  .brand-colors-grid { grid-template-columns: 1fr; }

  /* Table -> cards on small screens */
  #intakeTable { display: none; }
  .mobile-cards { display: block; }

  .settings-section { display: none; }
  .fab-container { display: block; }

  .action-buttons { justify-content: center; gap: 6px; }
  .action-btn { padding: 6px 10px; font-size: 11px; }

  input[type="text"], input[type="email"], input[type="number"], select, textarea { font-size: 16px; } /* prevents iOS zoom */
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .container { box-shadow: none; margin: 0; padding: 0; max-width: 100%; }
  .settings-section, .fab-container, .action-buttons, .quick-date-presets,
  .settings-popup, .collapsible-card, #intakeTable thead th:empty { display: none !important; }
  .date-year-section { border: none; }
  .date-input-section, .year-display-section { border: 1px solid #ccc; background: #fff; }
  table { border-spacing: 0; }
  thead th, tbody td { border: 1px solid #ccc; }
  .highlight-intake, .highlight-exit { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .mobile-cards { display: none !important; }
  #intakeTable { display: table !important; }
}
