/* ── Reset & Base ─────────────────────────────────────── */
:root {
  /* Neutral palette (Enhanced Services Figma) */
  --bg: #F8F9FB;
  --surface: #ffffff;
  --border: #E1E4EA;
  --border-light: #E9ECF2;
  --text: #262B36;
  --text-secondary: #545F78;
  --text-muted: #8792AB;
  --text-faint: #C3C9D5;

  /* Primary / CTA (red) */
  --cta: #E7585B;
  --cta-hover: #D23033;
  --cta-light: #FDF3F3;

  /* Secondary (blue) */
  --accent: #4458B1;
  --accent-light: #EAEFFA;
  --accent-lighter: #E2E9F7;
  --accent-hover: #3D4A92;

  /* Status */
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;

  /* Radii */
  --radius: 8px;
  --radius-sm: 6px;

  /* Shadows (Figma elevation system) */
  --shadow-sm: 0px 1px 2px rgba(40, 47, 62, 0.05);
  --shadow: 0px 1px 3px rgba(40, 47, 62, 0.1), 0px 1px 2px rgba(40, 47, 62, 0.06);
  --shadow-md: 0px 4px 8px -2px rgba(40, 47, 62, 0.1), 0px 2px 4px -2px rgba(40, 47, 62, 0.06);
  --shadow-lg: 0px 12px 16px -4px rgba(40, 47, 62, 0.08), 0px 4px 6px -2px rgba(40, 47, 62, 0.03);

  --surface-hover: #F8F9FB;
  --transition: 150ms cubic-bezier(.4, 0, .2, 1);

  /* Layout */
  --sidebar-width: 200px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  margin: 0;
  padding: 0;
}

/* ── App Layout ──────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
}
.sidebar-top {
  padding: 1.25rem 1.25rem 1rem;
}
.sidebar-brand {
  display: block;
  text-decoration: none;
}
.sidebar-brand img {
  display: block;
  height: 22px;
}

.sidebar-nav {
  flex: 1;
  padding: .5rem .75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
}
.sidebar-link:hover {
  background: var(--bg);
  color: var(--text);
}
.sidebar-link.active {
  background: var(--accent-light);
  color: var(--accent);
}
.sidebar-link svg {
  flex-shrink: 0;
}

.sidebar-bottom {
  padding: .75rem;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem;
  margin-bottom: .25rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.sidebar-user:hover {
  background: var(--bg);
}
.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-user-name {
  font-size: .8rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user-email {
  font-size: .675rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-signout {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .375rem .5rem;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: all var(--transition);
}
.sidebar-signout:hover {
  background: var(--cta-light);
  color: var(--cta);
}

/* ── Mobile Header ───────────────────────────────────── */
.mobile-header {
  display: none;
}
.sidebar-backdrop {
  display: none;
}

/* ── Main Content ────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem 2.5rem;
  min-height: 100vh;
  background: var(--bg);
}

/* ── Icon Buttons (edit/delete) ──────────────────────── */
.btn-icon-sm {
  background: none;
  border: none;
  padding: .25rem;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
}
.btn-icon-sm:hover {
  background: var(--bg);
  color: var(--accent);
}
.btn-icon-danger:hover {
  background: var(--cta-light);
  color: var(--cta);
}

/* ── Modal refinements ───────────────────────────────── */
.modal-backdrop.show { opacity: .3; }
.modal-content {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
}
.modal-header .modal-title {
  font-size: 1rem;
  font-weight: 600;
}
.modal-body { padding: 1.25rem; }
.modal-footer {
  border-top: 1px solid var(--border);
  padding: .75rem 1.25rem;
}
.schedule-edit-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .375rem 0;
  border-bottom: 1px solid var(--border-light);
}
.schedule-edit-row:last-child { border-bottom: none; }
.schedule-edit-row .form-input {
  width: auto;
  padding: .375rem .5rem;
  font-size: .8125rem;
}
.schedule-edit-row select.form-input { width: 130px; }
.schedule-edit-row input[type="time"] { width: 120px; }

/* ── Page Layout ─────────────────────────────────────── */
.page-header {
  margin-bottom: 2rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.01em;
}
.page-header p {
  color: var(--text-secondary);
  margin: .25rem 0 0;
  font-size: .9rem;
}

/* ── Cards ───────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.school-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: box-shadow 200ms ease, border-color 200ms ease, transform 200ms ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}
.school-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-lighter);
  transform: translateY(-2px);
}
.school-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: .75rem;
}
.school-name {
  font-weight: 600;
  font-size: 1rem;
  margin: 0;
  line-height: 1.3;
}
.school-id {
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: .15rem .5rem;
  border-radius: 4px;
  font-weight: 500;
  white-space: nowrap;
}
.school-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  padding: .5rem .75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.school-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-gray { background: var(--text-muted); }
.dot-blue { background: var(--accent); }

.school-status-detail {
  display: flex;
  align-items: center;
  gap: .375rem;
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: -.5rem;
  margin-bottom: 1rem;
  padding: 0 .75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.school-actions {
  display: flex;
  gap: .5rem;
  margin-top: auto;
  padding-top: .75rem;
}
.school-actions > a,
.school-actions > form,
.school-actions-row > a,
.school-actions-row > form { flex: 1; display: flex; }
.school-actions .btn-primary-custom,
.school-actions .btn-secondary-custom,
.school-actions .btn-success-custom,
.school-actions-row .btn-primary-custom,
.school-actions-row .btn-secondary-custom,
.school-actions-row .btn-success-custom { flex: 1; justify-content: center; }

.school-actions-stacked {
  flex-direction: column;
  gap: .375rem;
}
.school-actions-row {
  display: flex;
  gap: .5rem;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn-primary-custom {
  background: var(--cta);
  color: #fff;
  border: none;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  line-height: 1.4;
}
.btn-primary-custom:hover { background: var(--cta-hover); color: #fff; }

.btn-secondary-custom {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  line-height: 1.4;
}
.btn-secondary-custom:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-faint);
}

.btn-success-custom {
  background: var(--success);
  color: #fff;
  border: none;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  line-height: 1.4;
}
.btn-success-custom:hover { background: #047857; color: #fff; }

.btn-sm-custom {
  padding: .375rem .75rem;
  font-size: .75rem;
}

.btn-block { width: 100%; justify-content: center; }

/* ── Alerts ──────────────────────────────────────────── */
.alert-custom {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
}
.alert-success-custom {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid #a7f3d0;
}
.alert-error-custom {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.alert-warning-custom {
  background: var(--warning-light);
  color: var(--warning);
  border: 1px solid #fde68a;
}

/* ── Form Controls ───────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .375rem;
}
.form-input {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(68, 88, 177, .12);
}
select.form-input { cursor: pointer; }

/* ── Upload Drop Zone ────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg);
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-zone svg {
  color: var(--text-muted);
  margin-bottom: .5rem;
}
.upload-zone p {
  margin: 0;
  font-size: .85rem;
  color: var(--text-secondary);
}
.upload-zone .file-name {
  font-weight: 600;
  color: var(--accent);
  margin-top: .5rem;
}

/* ── Schedule Table ──────────────────────────────────── */
.schedule-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .8125rem;
  table-layout: fixed;
}
.schedule-table th {
  text-align: left;
  padding: .625rem 1rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: transparent;
  border-bottom: 1px solid var(--border);
}
.schedule-table td {
  padding: .625rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}
.schedule-table tr:last-child td { border-bottom: none; }
.schedule-table tr:hover td { background: var(--bg); }
.schedule-table .no-schedule { color: var(--text-muted); }

/* ── Teacher Cards ───────────────────────────────────── */
.teacher-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-lighter);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: .75rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 200ms ease, border-left-color 200ms ease;
}
.teacher-card:hover {
  box-shadow: var(--shadow);
  border-left-color: var(--accent);
}
.teacher-card-header {
  padding: .75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.teacher-card-header:hover { background: var(--bg); }
.teacher-name {
  font-weight: 600;
  font-size: .875rem;
}
.teacher-id-badge {
  font-size: .675rem;
  color: var(--accent);
  background: var(--accent-light);
  padding: .15rem .5rem;
  border-radius: 999px;
  margin-left: .5rem;
  font-weight: 500;
}
.teacher-card-body {
  padding: 0 1rem 1rem;
}

/* ── Section Surface ─────────────────────────────────── */
.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.surface-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.surface-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

/* ── Copy Bar ────────────────────────────────────────── */
.copy-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.25rem;
  background: var(--accent-light);
  border: 1px solid var(--accent-lighter);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.copy-bar label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}
.copy-bar select,
.copy-bar input[type="number"] {
  padding: .375rem .5rem;
  border: 1px solid var(--accent-lighter);
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-secondary);
}
.empty-state svg {
  color: var(--accent);
  margin-bottom: 1.25rem;
  background: var(--accent-light);
  padding: 1rem;
  border-radius: 50%;
  width: 56px;
  height: 56px;
}
.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 .375rem;
  color: var(--text);
}
.empty-state p {
  font-size: .875rem;
  margin: 0 0 1.25rem;
  color: var(--text-muted);
}

/* ── Modal ───────────────────────────────────────────── */
.modal-content { border-radius: var(--radius); border: none; }
.modal-header { border-bottom: 1px solid var(--border); padding: 1rem 1.25rem; }
.modal-header .modal-title { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-footer { border-top: 1px solid var(--border); padding: .75rem 1.25rem; }

/* ── Misc ────────────────────────────────────────────── */
.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 .4rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  background: var(--accent-light);
  color: var(--accent);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

/* ── Tool Launcher Grid ─────────────────────────────── */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  max-width: 800px;
  margin: 0 auto;
}
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none;
  color: var(--text);
  transition: all 200ms ease;
  border-left: 4px solid var(--tool-color, var(--accent));
  box-shadow: var(--shadow-sm);
}
.tool-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-lighter);
  border-left-color: var(--tool-color, var(--accent));
  transform: translateY(-2px);
  color: var(--text);
}
.tool-card-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--tool-color, var(--accent));
}
.tool-card-content {
  flex: 1;
  min-width: 0;
}
.tool-card-content h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 .25rem;
}
.tool-card-content p {
  font-size: .8rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}
.tool-card-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--transition);
}
.tool-card:hover .tool-card-arrow {
  transform: translateX(3px);
  color: var(--accent);
}

/* ── Login Page ─────────────────────────────────────── */
.login-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.login-logo {
  margin-bottom: 1.25rem;
}
.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 .375rem;
}
.login-subtitle {
  font-size: .875rem;
  color: var(--text-secondary);
  margin: 0 0 2rem;
}
.login-btn-microsoft {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.5rem;
  background: var(--cta);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  width: 100%;
  justify-content: center;
}
.login-btn-microsoft:hover {
  background: var(--cta-hover);
  box-shadow: var(--shadow-sm);
  color: #fff;
}
.login-footer {
  font-size: .75rem;
  color: var(--text-muted);
  margin: 1.5rem 0 0;
}

/* ── Loading spinner (inline) ────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.btn-loading {
  pointer-events: none;
  opacity: .65;
}
.btn-loading .btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* ── Responsive table wrapper ───────────────────────── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 250ms ease;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(9, 11, 17, .3);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .mobile-menu-btn {
    background: none;
    border: none;
    padding: .25rem;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
  }

  .main-content {
    margin-left: 0;
    padding: 1.25rem 1rem;
  }

  .card-grid { grid-template-columns: 1fr; }
  .tool-grid { grid-template-columns: 1fr; max-width: none; }
  .copy-bar { flex-direction: column; align-items: stretch; }
  .login-container { padding: 2rem 1.5rem; }
  .school-actions { flex-wrap: wrap; }
  .hide-mobile { display: none !important; }
}
