:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #e1e4e9;
  --border-strong: #cdd2da;
  --text: #16181d;
  --text-muted: #666d78;
  --text-faint: #9198a3;
  --primary: #4552e0;
  --primary-hover: #363fc4;
  --primary-contrast: #ffffff;
  --secondary-accent: #16a34a;
  --focus-ring: rgba(69, 82, 224, 0.35);
  --success-bg: #e4f6ea;
  --success-text: #1c7a37;
  --error-bg: #fdecec;
  --error-text: #c22a2f;
  --warning-bg: #fdf1dc;
  --warning-text: #96650a;
  --shadow-sm: 0 1px 2px rgba(20, 22, 26, 0.06);
  --shadow-md: 0 10px 30px rgba(20, 22, 26, 0.10);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f13;
    --surface: #16191f;
    --surface-2: #1c2028;
    --border: #282d37;
    --border-strong: #363c48;
    --text: #edeef2;
    --text-muted: #a2a9b4;
    --text-faint: #6b7280;
    --primary: #8b96ff;
    --primary-hover: #a3adff;
    --primary-contrast: #11131a;
    --focus-ring: rgba(139, 150, 255, 0.4);
    --success-bg: #123322;
    --success-text: #5fd88a;
    --error-bg: #3a1418;
    --error-text: #ff8f93;
    --warning-bg: #3a2a10;
    --warning-text: #f0b849;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 14px 34px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #0d0f13;
  --surface: #16191f;
  --surface-2: #1c2028;
  --border: #282d37;
  --border-strong: #363c48;
  --text: #edeef2;
  --text-muted: #a2a9b4;
  --text-faint: #6b7280;
  --primary: #8b96ff;
  --primary-hover: #a3adff;
  --primary-contrast: #11131a;
  --focus-ring: rgba(139, 150, 255, 0.4);
  --success-bg: #123322;
  --success-text: #5fd88a;
  --error-bg: #3a1418;
  --error-text: #ff8f93;
  --warning-bg: #3a2a10;
  --warning-text: #f0b849;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 14px 34px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.15s ease, color 0.15s ease;
}

h1, h2, h3 { letter-spacing: -0.01em; font-weight: 600; }

a { color: var(--primary); text-decoration-color: color-mix(in srgb, var(--primary) 40%, transparent); }
a:hover { color: var(--primary-hover); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* Icon buttons (theme toggle, password visibility) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; display: none; }

.theme-toggle[data-current="light"] .icon-moon { display: block; }
.theme-toggle[data-current="dark"] .icon-sun { display: block; }

.password-toggle[data-visible="false"] .icon-eye { display: block; }
.password-toggle[data-visible="true"] .icon-eye-off { display: block; }

/* Navbar */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--primary);
}
.navbar-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}
.brand-mark {
  display: inline-flex;
  color: var(--primary);
}
.brand-mark svg { width: 22px; height: 22px; }
.nav-toggle-checkbox { display: none; }
.nav-toggle-btn {
  display: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  color: var(--text);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
}
.nav-links a:hover { color: var(--primary); }
.nav-links a.active { color: var(--primary); font-weight: 600; }
.nav-user { color: var(--text-faint); font-size: 0.9rem; }
.nav-logout { margin: 0; display: flex; align-items: center; }

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0;
  text-decoration: underline;
}

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error   { background: var(--error-bg);   color: var(--error-text); }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Tab toggle */
.tab-toggle {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.tab-toggle a {
  padding: 0.5rem 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-toggle a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* Item repeater */
.item-repeater { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 0.75rem; }
.item-row {
  display: grid;
  grid-template-columns: 2fr 2fr 0.8fr 0.8fr 1fr auto;
  gap: 0.6rem;
  align-items: end;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.item-row label { gap: 0.25rem; }
@media (max-width: 800px) {
  .item-row { grid-template-columns: 1fr 1fr; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.1s ease;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: var(--primary-contrast); border-color: transparent; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; }

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
}
.card h3 { margin: 0 0 0.25rem; }
.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}
.card-link:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }

/* School hero + module preview */
.school-hero {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.school-hero-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.4rem;
}
.school-hero-text { flex: 1; min-width: 200px; }
.module-card { display: flex; flex-direction: column; gap: 0.35rem; }
.module-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--focus-ring);
  color: var(--primary);
  margin-bottom: 0.25rem;
}
.module-icon svg { width: 20px; height: 20px; }
.module-card h3 { margin: 0; }
.module-card p { margin: 0; font-size: 0.9rem; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius-md); border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; min-width: 480px; }
.table th, .table td {
  text-align: left;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
.table tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-active, .badge-approved, .badge-completed { background: var(--success-bg); color: var(--success-text); }
.badge-suspended, .badge-disabled, .badge-rejected, .badge-cancelled { background: var(--error-bg); color: var(--error-text); }
.badge-pending, .badge-pending_quotes, .badge-pending_approval, .badge-revision_requested { background: var(--warning-bg); color: var(--warning-text); }
.badge-draft, .badge-po_issued { background: var(--surface-2); color: var(--text-muted); }

/* Invite link */
.invite-link-box {
  display: flex;
  gap: 0.5rem;
  max-width: 520px;
  margin-bottom: 1rem;
}
.invite-link-box input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

/* Forms */
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.form-narrow { max-width: 420px; }
label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
input, select, textarea {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.field-error { color: var(--error-text); font-size: 0.85rem; margin: -0.6rem 0 0; }

.field-with-action { position: relative; display: flex; }
.field-with-action input { padding-right: 2.75rem; }
.field-with-action .icon-btn {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
}

/* Branding settings */
.color-field { display: flex; align-items: center; gap: 0.6rem; }
.color-field input[type="color"] {
  width: 44px;
  min-height: 44px;
  padding: 3px;
  cursor: pointer;
}
.color-hex-mirror { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.logo-preview {
  display: block;
  max-width: 160px;
  max-height: 80px;
  object-fit: contain;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: var(--surface);
}

/* Auth page */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}
.auth-topbar {
  position: fixed;
  top: 1rem;
  right: 1rem;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1.5rem;
}
.auth-brand .brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  align-items: center;
  justify-content: center;
}
.auth-brand .brand-mark svg { width: 22px; height: 22px; }
.auth-brand-text h1 { margin: 0; font-size: 1.25rem; }
.auth-brand-text p { margin: 0.1rem 0 0; }
.muted { color: var(--text-muted); font-size: 0.9rem; }

/* Mobile */
@media (max-width: 640px) {
  .nav-toggle-btn { display: block; }
  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.75rem;
    padding-top: 0.75rem;
  }
  .nav-toggle-checkbox:checked ~ .nav-links { display: flex; }
  .navbar-inner { position: relative; }
}
