@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=Space+Grotesk:wght@500;600&display=swap');

:root {
  /* Neutrals */
  --bg: #F5F4F1;
  --surface: #FFFFFF;
  --border: #DEDCD3;
  --text: #201F2B;
  --text-muted: #625F73;

  /* Brand: indigo/violet (nav, headings, links, secondary buttons) */
  --brand: #534AB7;
  --brand-dark: #3C3489;
  --brand-darker: #26215C;
  --brand-tint: #EEEDFE;
  --brand-tint-border: #AFA9EC;

  /* Accent: coral, reserved for the one primary action per page */
  --accent: #D85A30;
  --accent-dark: #993C1D;
  --accent-tint: #FAECE7;

  --danger: #A32D2D;
  --danger-tint: #FCEBEB;

  /* Status badges */
  --status-open: #0C447C;         --status-open-tint: #E6F1FB;
  --status-assigned: #633806;     --status-assigned-tint: #FAEEDA;
  --status-progress: #3C3489;     --status-progress-tint: #EEEDFE;
  --status-resolved: #173404;     --status-resolved-tint: #EAF3DE;
  --status-closed: #444441;       --status-closed-tint: #F1EFE8;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand-dark); }

h1, h2, .brand, .stat-number {
  font-family: 'Space Grotesk', 'IBM Plex Sans', sans-serif;
}

/* ---------- Top navigation ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.topbar .brand {
  font-weight: 600;
  font-size: 17px;
  color: var(--brand-darker);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-toggle { display: none; }
.nav-toggle-label { display: none; }

.topbar nav {
  display: flex;
  align-items: center;
}

.topbar nav a, .topbar nav .link-button {
  margin-left: 18px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.topbar nav a:hover { color: var(--brand-dark); }

.topbar .who {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 18px;
}

.logout-form { display: inline; margin-left: 0; }
.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.link-button:hover { color: var(--brand-dark); }

/* ---------- Layout ---------- */

.page {
  max-width: 840px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

h1 { font-size: 24px; font-weight: 600; margin: 0 0 6px; color: var(--brand-darker); }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }

.subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 28px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
}

.center-card { max-width: 380px; margin: 60px auto; }

.login-brand {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--brand-tint);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

/* ---------- Forms ---------- */

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.field .help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.field input[type="text"], .field input[type="password"], .field input[type="number"],
.field input[type="email"], .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}

.field textarea { min-height: 90px; resize: vertical; }

.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.pin-input { letter-spacing: 4px; font-size: 18px !important; }

.errorlist { list-style: none; padding: 0; margin: 6px 0 0; color: var(--danger); font-size: 13px; }
.form-error-banner { background: var(--danger-tint); color: var(--danger); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 18px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
}
.btn:hover { background: var(--accent-dark); }

.btn-secondary {
  background: transparent;
  color: var(--brand-dark);
  border: 1px solid var(--brand-tint-border);
}
.btn-secondary:hover { background: var(--brand-tint); }

.btn-small { padding: 7px 14px; font-size: 13px; min-height: 36px; }
.full-width { width: 100%; }

/* ---------- Ticket rows & badges ---------- */

.ticket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover .ticket-title { color: var(--brand-dark); }

.ticket-title { font-weight: 500; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.ticket-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-open { background: var(--status-open-tint); color: var(--status-open); }
.badge-assigned { background: var(--status-assigned-tint); color: var(--status-assigned); }
.badge-in_progress { background: var(--status-progress-tint); color: var(--status-progress); }
.badge-resolved { background: var(--status-resolved-tint); color: var(--status-resolved); }
.badge-closed { background: var(--status-closed-tint); color: var(--status-closed); }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { color: var(--brand-tint-border); margin-bottom: 10px; display: block; margin-left: auto; margin-right: auto; }

/* ---------- Multi-student rows ---------- */

.student-row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}
.student-row .field { margin-bottom: 0; }

.remove-student {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--danger);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  min-height: 44px;
}

/* ---------- Comments ---------- */

.comment { padding: 12px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }

.actions-row { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.back-link { font-size: 13px; color: var(--text-muted); text-decoration: none; display: inline-block; margin-bottom: 16px; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ---------- Stats & tabs (dashboards) ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--brand-tint); border: 1px solid var(--brand-tint-border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-card .icon { color: var(--brand); margin-bottom: 6px; }
.stat-number { font-size: 26px; font-weight: 600; color: var(--brand-darker); }
.stat-label { font-size: 12px; color: var(--brand-dark); margin-top: 2px; }

.section-heading-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; flex-wrap: wrap; }
.section-heading-row.tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.section-heading-row.tabs a { flex-shrink: 0; }

.pill { display: inline-block; font-size: 11px; font-weight: 500; padding: 3px 10px; border-radius: 20px; background: var(--brand-tint); color: var(--brand-darker); text-transform: capitalize; }
.pill-inactive { background: var(--danger-tint); color: var(--danger); }

.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; min-height: auto; }
.checkbox-field label { margin: 0; }

/* ---------- Data table (desktop) / stacked cards (mobile via media query) ---------- */

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }

/* ---------- Icons ---------- */

.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.icon-brand { color: var(--brand); }

/* =========================================================
   Mobile (<= 640px)
   ========================================================= */
@media (max-width: 640px) {
  .page { padding: 20px 16px 48px; }

  .topbar { padding: 12px 16px; flex-wrap: wrap; }

  .nav-toggle-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    cursor: pointer;
    color: var(--brand-dark);
  }

  .topbar nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 3;
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
  }

  .topbar nav a, .topbar nav .who, .topbar nav .logout-form {
    margin-left: 0;
    padding: 10px 4px;
    width: 100%;
  }
  .topbar nav .who { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 14px; }

  .nav-toggle:checked ~ nav { display: flex; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .student-row { grid-template-columns: 1fr; gap: 8px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
  .remove-student { width: 100%; }

  .ticket-row { flex-wrap: wrap; }

  /* Tables become stacked cards: each row is a card, each cell shows its column label */
  .data-table, .data-table thead, .data-table tbody, .data-table th, .data-table td, .data-table tr { display: block; }
  .data-table thead { display: none; }
  .data-table tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; padding: 4px 12px; }
  .data-table td { border-bottom: none; padding: 8px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .data-table td:not(:last-child) { border-bottom: 1px solid var(--border); }
  .data-table td::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
}

/* =========================================================
   Admin sidebar shell (dashboard, user management)
   ========================================================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--brand-darker); color: #C9C7E0;
  display: flex; flex-direction: column; padding: 20px 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px 20px; margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.sidebar-brand .name { font-weight: 600; font-size: 14px; color: #fff; line-height: 1.3; }
.sidebar-profile { display: flex; align-items: center; gap: 10px; padding: 10px 20px 20px; margin-bottom: 8px; }
.sidebar-profile .role { font-size: 11px; color: #9C99C4; text-transform: uppercase; letter-spacing: 0.04em; }
.sidebar-profile .uname { font-size: 13px; font-weight: 500; color: #fff; }
.sidebar-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #9C99C4; padding: 14px 20px 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; color: #C9C7E0; text-decoration: none;
  font-size: 14px; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,0.07); color: #fff; border-left-color: var(--accent); font-weight: 500; }
.sidebar-footer { margin-top: auto; padding: 14px 20px 4px; font-size: 11px; color: #9C99C4; }

.admin-main { flex: 1; min-width: 0; }
.admin-topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
}
.breadcrumb { font-size: 13px; color: var(--text-muted); }
.breadcrumb .current { color: var(--text); font-weight: 500; }
.admin-topbar .actions { display: flex; align-items: center; gap: 16px; }
.admin-topbar .actions form { margin: 0; }

.sidebar-toggle-check { display: none; }
.sidebar-toggle-label { display: none; cursor: pointer; }

/* ---------- Avatars ---------- */
.avatar {
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff; flex-shrink: 0;
}
.avatar-placeholder { border-radius: 50%; border: 1.5px dashed var(--border); display: inline-block; flex-shrink: 0; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card {
  border-radius: var(--radius-lg); padding: 18px 18px 14px; color: #fff;
  position: relative; overflow: hidden; display: flex; flex-direction: column;
  min-height: 118px; text-decoration: none;
}
.kpi-card .icon { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,0.18); display: flex; align-items: center; justify-content: center; color: #fff; }
.kpi-card .kpi-number { font-size: 28px; font-weight: 700; line-height: 1; margin-top: 4px; font-family: 'Space Grotesk', sans-serif; }
.kpi-card .kpi-label { font-size: 13px; margin-top: 6px; opacity: 0.92; }
.kpi-card .more-info { margin-top: auto; padding-top: 12px; font-size: 12px; font-weight: 500; color: rgba(255,255,255,0.9); }

.kpi-total { background: var(--brand-darker); }
.kpi-open { background: var(--status-open); }
.kpi-progress { background: var(--status-progress); }
.kpi-resolved { background: var(--status-resolved); }
.kpi-attention { background: var(--danger); }
.kpi-users { background: #4A5561; }
.kpi-time { background: #0F7B8A; }

/* ---------- Recent tickets w/ tech chips ---------- */
.tech-chip { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.tech-chip .tech-name { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.unassigned-chip { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); font-style: italic; }

/* ---------- Technician performance table ---------- */
.perf-table { width: 100%; border-collapse: collapse; }
.perf-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; padding: 0 12px 10px; border-bottom: 1px solid var(--border); }
.perf-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.perf-table tr:last-child td { border-bottom: none; }
.perf-table .tech-cell { display: flex; align-items: center; gap: 10px; }

.time-bar-track { background: var(--border); border-radius: 20px; height: 6px; width: 100%; overflow: hidden; }
.time-bar-fill { background: #0F7B8A; height: 100%; border-radius: 20px; }
.time-value { font-weight: 600; white-space: nowrap; }
.time-cell { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.time-cell .time-bar-track { width: 70px; }
.fastest-tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--status-resolved); background: var(--status-resolved-tint); padding: 2px 7px; border-radius: 10px; margin-left: 8px; }

@media (max-width: 900px) {
  .sidebar-toggle-label { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; color: var(--brand-dark); }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar-toggle-check:checked ~ .app-shell .sidebar { transform: translateX(0); }
  .admin-main { width: 100%; }
}

@media (max-width: 640px) {
  .admin-topbar { padding: 12px 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .time-cell { min-width: 0; flex-wrap: wrap; }
}

/* ---------- Additions: notifications, filters, internal notes, success banner ---------- */

/* Notification bell (base.html nav) */
.nav-bell { position: relative; display: inline-flex; align-items: center; color: var(--text); }
.nav-bell:hover { color: var(--brand-dark); }
.notification-badge {
  position: absolute; top: -6px; right: -8px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 600; line-height: 1;
  border-radius: 9px; padding: 2px 5px; min-width: 15px; text-align: center;
}

/* Success banner (mirrors .form-error-banner, using status-resolved green) */
.form-success-banner {
  background: var(--status-resolved-tint); color: var(--status-resolved);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 18px;
}

/* Notification list page */
.notification-list { list-style: none; margin: 0; padding: 0; }
.notification-row { border-bottom: 1px solid var(--border); padding: 12px 0; }
.notification-row:last-child { border-bottom: none; }
.notification-row a { display: block; color: var(--text); }
.notification-row.unread .notification-message { font-weight: 600; }
.notification-message { font-size: 14px; }
.notification-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* Ticket list search/filter bar */
.filter-bar { padding-bottom: 8px; margin-bottom: 20px; }
.filter-bar-fields {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px 14px;
}
.filter-bar-fields .field { margin-bottom: 8px; }
.filter-bar-actions { display: flex; gap: 10px; margin-top: 4px; }

/* Internal (staff-only) notes on ticket detail */
.comment-internal { background: var(--accent-tint); border-left: 3px solid var(--accent-dark); padding-left: 10px; margin-left: -10px; }
.pill-internal { background: var(--accent-dark); color: #fff; margin-left: 6px; }

/* ---------- Additions: ticket delete (single + bulk) ---------- */
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #7a2323; }

.ticket-row-wrap { display: flex; align-items: center; gap: 10px; }
.ticket-row-wrap .ticket-row { flex: 1; }
.ticket-select { flex-shrink: 0; width: auto; min-height: auto; }

.bulk-delete-actions { padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--border); }
