:root {
  color-scheme: light;
  --bg: #eef5f8;
  --bg-accent: radial-gradient(circle at top left, rgba(37, 99, 235, 0.16), transparent 34%), radial-gradient(circle at top right, rgba(13, 148, 136, 0.14), transparent 28%), linear-gradient(180deg, #f7fbfd 0%, #e6eef3 100%);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #f9fcff;
  --surface-ink: #1b2733;
  --muted: #5f7383;
  --line: rgba(72, 107, 132, 0.14);
  --shadow: 0 18px 36px rgba(31, 57, 78, 0.12);
  --critical: #c2414b;
  --high: #d97706;
  --moderate: #2563eb;
  --low: #0f8a6b;
  --ok: #22577a;
  --font-display: "Aptos Display", "Segoe UI", sans-serif;
  --font-body: "Aptos", "Segoe UI", sans-serif;
}

:root.dark {
  color-scheme: dark;
  --bg: #0f1720;
  --bg-accent: radial-gradient(circle at top left, rgba(37, 99, 235, 0.24), transparent 28%), radial-gradient(circle at top right, rgba(13, 148, 136, 0.22), transparent 26%), linear-gradient(180deg, #0b1218 0%, #121d26 100%);
  --surface: rgba(21, 30, 39, 0.94);
  --surface-strong: #18222b;
  --surface-ink: #edf3f6;
  --muted: #9eb1bf;
  --line: rgba(127, 158, 180, 0.16);
  --shadow: 0 22px 44px rgba(0, 0, 0, 0.32);
  --critical: #f08a92;
  --high: #f2b35b;
  --moderate: #7aa2ff;
  --low: #67d1b5;
  --ok: #8fc2dd;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg-accent);
  color: var(--surface-ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(12, 16, 19, 0.42);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.auth-panel {
  width: min(460px, 100%);
  padding: 1.8rem;
  border-radius: 1.5rem;
  background: rgba(255, 252, 247, 0.96);
  border: 1px solid rgba(61, 55, 48, 0.12);
  box-shadow: var(--shadow);
}

:root.dark .auth-panel {
  background: rgba(24, 31, 38, 0.98);
}

.auth-form,
.settings-form,
.ticket-form {
  display: grid;
  gap: 0.95rem;
  margin-top: 1rem;
}

.auth-error {
  min-height: 1.2rem;
  margin: 0;
  color: var(--critical);
}

body:not(.auth-required):not(.auth-loading) .auth-screen {
  display: none;
}

body.auth-required .app-shell,
body.auth-loading .app-shell {
  visibility: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 2rem 1.4rem;
  background: rgba(18, 33, 44, 0.97);
  color: #f6efe5;
}

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

.brand strong,
.topbar h1,
.panel h2,
.auth-panel h1 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
}

.brand small,
.label,
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 1rem;
  background: linear-gradient(145deg, rgba(13, 148, 136, 0.95), rgba(37, 99, 235, 0.92));
}

.brand-mark svg {
  width: 1.5rem;
  fill: #fff8f0;
}

.nav-list {
  display: grid;
  gap: 0.45rem;
}

.nav-item {
  padding: 0.8rem 0.95rem;
  border: 0;
  border-radius: 0.85rem;
  color: rgba(246, 239, 229, 0.84);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff7ef;
}

.sidebar-panel {
  padding: 1rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-panel p {
  margin: 0.45rem 0 0;
  color: rgba(246, 239, 229, 0.74);
  line-height: 1.45;
}

.content {
  padding: 2rem;
}

.topbar,
.panel,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.35rem 1.5rem;
  border-radius: 1.4rem;
}

.topbar h1 {
  margin: 0.25rem 0 0;
  font-size: clamp(2rem, 3vw, 3rem);
}

.topbar-actions {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.home-filter {
  min-width: 220px;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.compact-field {
  align-self: end;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border-radius: 0.95rem;
  border: 1px solid rgba(61, 55, 48, 0.14);
  background: rgba(255, 255, 255, 0.8);
  color: var(--surface-ink);
}

:root.dark .field input,
:root.dark .field select,
:root.dark .field textarea {
  background: rgba(12, 17, 21, 0.82);
  color: var(--surface-ink);
  border-color: rgba(149, 170, 181, 0.16);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.primary-button,
.secondary-button,
.theme-toggle {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.primary-button,
.secondary-button {
  padding: 0.9rem 1.2rem;
}

.primary-button {
  background: linear-gradient(145deg, #0f766e, #2563eb);
  color: #f8fcff;
}

.secondary-button {
  background: rgba(37, 99, 235, 0.1);
  color: #1f4b7d;
}

:root.dark .secondary-button {
  background: rgba(122, 162, 255, 0.14);
  color: var(--surface-ink);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.15rem;
  height: 3.15rem;
  border: 1px solid rgba(61, 55, 48, 0.14);
  background: rgba(255, 255, 255, 0.72);
  color: #1f4b7d;
}

.theme-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.theme-toggle .moon-icon {
  display: none;
}

:root.dark .theme-toggle {
  background: rgba(29, 38, 45, 0.94);
  color: #f0f5f7;
  border-color: rgba(149, 170, 181, 0.16);
}

:root.dark .theme-toggle .sun-icon {
  display: none;
}

:root.dark .theme-toggle .moon-icon {
  display: block;
}

.primary-button:hover,
.secondary-button:hover,
.theme-toggle:hover,
.inline-button:hover {
  transform: translateY(-1px);
}

.page {
  display: none;
  margin-top: 1rem;
}

.page.active {
  display: block;
}

.stats-grid,
.dashboard-grid,
.ticket-layout,
.settings-grid {
  display: grid;
  gap: 1rem;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
  padding: 1.15rem;
  border-radius: 1.2rem;
}

.stat-card strong {
  display: block;
  margin: 0.4rem 0;
  font-size: 2rem;
  font-family: var(--font-display);
}

.dashboard-grid,
.settings-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr);
  margin-top: 1rem;
}

.ticket-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.92fr);
}

.panel {
  padding: 1.3rem;
  border-radius: 1.35rem;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.panel h2 {
  margin: 0.2rem 0 0;
  font-size: 1.45rem;
}

.panel-copy {
  color: var(--muted);
  line-height: 1.5;
}

.label,
.eyebrow {
  color: var(--muted);
}

.ticket-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field-wide {
  grid-column: 1 / -1;
}

.ticket-stack,
.resource-list,
.timeline {
  display: grid;
  gap: 0.9rem;
  margin-top: 1rem;
}

.ticket-card,
.resource-card,
.detail-card {
  padding: 1rem;
  border-radius: 1rem;
  background: var(--surface-strong);
  border: 1px solid rgba(61, 55, 48, 0.08);
}

:root.dark .ticket-card,
:root.dark .resource-card,
:root.dark .detail-card {
  background: var(--surface-strong);
  border-color: rgba(149, 170, 181, 0.08);
}

.ticket-card {
  cursor: pointer;
}

.ticket-card.active {
  outline: 2px solid rgba(211, 106, 47, 0.28);
}

:root.dark .ticket-card.active {
  outline-color: rgba(241, 165, 95, 0.35);
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.ticket-card h3,
.resource-card h3,
.detail-card strong {
  margin: 0.4rem 0 0.25rem;
}

.ticket-card p,
.resource-card p,
.detail-card p,
.timeline li {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.meta-line {
  margin-top: 0.65rem;
  font-size: 0.92rem;
}

.detail-panel {
  position: sticky;
  top: 1rem;
}

.status-pill,
.priority-pill,
.role-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.38rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.status-new {
  background: rgba(45, 76, 89, 0.12);
  color: var(--ok);
}

.status-triaged {
  background: rgba(37, 99, 235, 0.12);
  color: var(--moderate);
}

.status-in_progress {
  background: rgba(217, 119, 6, 0.14);
  color: var(--high);
}

.status-resolved {
  background: rgba(53, 115, 108, 0.12);
  color: var(--low);
}

.priority-critical,
.priority-high {
  background: rgba(180, 63, 40, 0.12);
  color: var(--critical);
}

.priority-medium {
  background: rgba(37, 99, 235, 0.12);
  color: var(--moderate);
}

.priority-low {
  background: rgba(53, 115, 108, 0.12);
  color: var(--low);
}

.role-admin {
  background: rgba(180, 63, 40, 0.12);
  color: var(--critical);
}

.role-coordinator {
  background: rgba(37, 99, 235, 0.12);
  color: var(--moderate);
}

.role-reporter {
  background: rgba(53, 115, 108, 0.12);
  color: var(--low);
}

.timeline {
  padding-left: 1.1rem;
}

.timeline small {
  display: block;
  margin-top: 0.2rem;
  color: #8a7f73;
}

.ticket-update-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.7rem;
}

.checkbox-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem 0.85rem;
  border-radius: 0.95rem;
  border: 1px solid rgba(61, 55, 48, 0.12);
  background: rgba(255, 255, 255, 0.56);
}

:root.dark .checkbox-chip {
  background: rgba(12, 17, 21, 0.72);
  border-color: rgba(149, 170, 181, 0.12);
}

body.role-reporter .admin-only,
body.role-reporter .coordinator-only,
body.role-coordinator .admin-only {
  display: none !important;
}

@media (max-width: 1180px) {
  .app-shell,
  .dashboard-grid,
  .ticket-layout,
  .settings-grid,
  .stats-grid,
  .ticket-form {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 780px) {
  .sidebar {
    display: none;
  }

  .content {
    padding: 1rem;
  }

  .topbar {
    padding: 1.1rem;
  }

  .ticket-update-grid {
    grid-template-columns: 1fr;
  }
}
