/* Ceres Liner Bus Management - Modern, Elderly-Friendly UI (HCI) */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --primary: #0ea5e9;
  --primary-hover: #38bdf8;
  --accent: #f59e0b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --success: #22c55e;
  --danger: #ef4444;
  --border: #334155;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.25);
  --font-sans: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
  --font-size-base: 18px;
  --touch-min: 48px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Blurred terminal background - all dashboards (Admin, Manager, Dispatcher, User Dashboard) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background: url('../images/ceres-terminal-bg.png') center/cover no-repeat;
  filter: blur(6px);
  -webkit-filter: blur(6px);
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(15, 23, 42, 0.72);
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* Layout */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.app-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.app-header .nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex: 1;
  justify-content: flex-end;
}
.app-header .nav .text-muted { white-space: nowrap; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  box-sizing: border-box;
  width: 100%;
}

/* Buttons - large touch targets (HCI) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--touch-min);
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
}
.btn-secondary:hover { background: #475569; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.card h2, .card h3 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Forms - large inputs for readability */
label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 1rem;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 1rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25);
}
textarea {
  min-height: 100px;
  resize: vertical;
}

.form-group { margin-bottom: 1rem; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}
th, td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface-hover);
  font-weight: 600;
}
tr:hover td { background: rgba(255,255,255,0.03); }

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 1rem;
}
.alert-success { background: rgba(34, 197, 94, 0.2); border: 1px solid var(--success); color: #86efac; }
.alert-error { background: rgba(239, 68, 68, 0.2); border: 1px solid var(--danger); color: #fca5a5; }
.alert-info { background: rgba(14, 165, 233, 0.2); border: 1px solid var(--primary); color: #7dd3fc; }

/* Login / Landing */
.landing-hero {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}
.landing-hero h1 {
  font-size: 2.25rem;
  margin-bottom: 0.5rem;
}
.landing-hero p {
  color: var(--text-muted);
  font-size: 1.15rem;
  margin-bottom: 2rem;
  max-width: 480px;
}
.login-box {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem;
}
.login-box .btn { width: 100%; margin-top: 0.5rem; }

/* Role cards on landing */
.role-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 2rem;
}
.role-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.2s, transform 0.1s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}
.role-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  text-decoration: none;
  color: inherit;
}
.role-card h3 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.role-card p { color: var(--text-muted); font-size: 0.95rem; }

/* Dashboard grids */
.page-title {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  font-weight: 700;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-card .num { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-card .label { color: var(--text-muted); font-size: 0.9rem; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 6px;
}
.badge-success { background: rgba(34,197,94,0.3); color: #86efac; }
.badge-warning { background: rgba(245,158,11,0.3); color: #fcd34d; }
.badge-danger { background: rgba(239,68,68,0.3); color: #fca5a5; }
.badge-info { background: rgba(14,165,233,0.3); color: #7dd3fc; }

/* Utility */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.flex { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Bus list on user dashboard - MOBILE FIRST: 1 column default, 2 cols only on large desktop */
.bus-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}
.bus-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.2s;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.bus-card:hover { border-color: var(--primary); }
.bus-card .bus-number { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.bus-card .destination { font-size: 1.05rem; margin: 0.35rem 0; }
.bus-card .meta { color: var(--text-muted); font-size: 0.95rem; }
.bus-card .seats { font-size: 1.1rem; font-weight: 600; margin-top: 0.5rem; }

/* Large desktop only: 2 columns for bus list */
@media (min-width: 1024px) {
  .bus-list {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
}

/* Time highlight - make departure/arrival times stand out */
.time-highlight {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.bus-card .schedule-times {
  margin: 0.5rem 0;
  padding: 0.6rem 0.75rem;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  min-width: 0;
}
.bus-card .schedule-times .time-highlight { font-size: 1.15rem; }
td.time-cell {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

/* Search bar - responsive: full width on small screens */
.search-bar {
  max-width: 720px;
  margin: 0 auto 1.5rem;
  width: 100%;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.search-bar input { margin-bottom: 0; }
.search-bar .btn { min-height: var(--touch-min); }
.search-bar .form-group { flex: 1; margin-bottom: 0; min-width: 0; }

/* Staff dashboard - stat cards with icons */
.dashboard-hero {
  margin-bottom: 2rem;
}
.dashboard-hero .page-title {
  margin-bottom: 0.35rem;
}
.dashboard-hero .dashboard-subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
}
.stats-grid-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0 2rem;
}
.stat-card-dash {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.1s;
}
.stat-card-dash:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}
.stat-card-dash .stat-icon {
  font-size: 2.25rem;
  margin-bottom: 0.5rem;
  line-height: 1;
}
.stat-card-dash .stat-num {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.stat-card-dash .stat-label {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

/* Action cards - like user dashboard bus cards */
.dashboard-section-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}
.action-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: border-color 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.action-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  text-decoration: none;
  color: inherit;
}
.action-card .action-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  line-height: 1;
}
.action-card .action-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.35rem;
}
.action-card .action-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Recent list cards (admin accounts) */
.recent-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.recent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.2s;
}
.recent-card:hover { border-color: var(--border); }
.recent-card .recent-name { font-weight: 600; font-size: 1.05rem; }
.recent-card .recent-meta { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }
.recent-card .recent-badge { margin-top: 0.5rem; }

/* Modal popup for passable municipalities */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.is-open {
  display: flex;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-box .modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.modal-box .modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.modal-box .modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  min-width: 36px;
  min-height: 36px;
}
.modal-box .modal-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.modal-box .modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}
.modal-municipality-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.modal-municipality-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1rem;
}
.modal-municipality-list li:last-child {
  border-bottom: none;
}
.modal-municipality-list .muni-num {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}
.modal-municipality-list li:last-child .muni-num {
  background: var(--success);
}
.btn-passable {
  margin-top: 0.5rem;
  font-size: 0.95rem;
  padding: 0.4rem 0.75rem;
  min-height: 36px;
}

/* ========== Responsive: tablet, phone, small devices ========== */

/* Blurred background: slightly less blur on mobile for performance */
@media (max-width: 768px) {
  body::before {
    filter: blur(5px);
    -webkit-filter: blur(5px);
  }
}
@media (max-width: 480px) {
  body::before {
    filter: blur(4px);
    -webkit-filter: blur(4px);
  }
}

/* Tablet and below - keep bus list single column so cards don't get cut off */
@media (max-width: 992px) {
  .container {
    padding: 1rem;
  }
  .page-title {
    font-size: 1.5rem;
  }
  .landing-hero h1 {
    font-size: 1.75rem;
  }
  .landing-hero p {
    font-size: 1rem;
  }
  .stats-grid,
  .stats-grid-dashboard {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
  .action-cards {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
  .bus-list {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .bus-card {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* Large phone / small tablet (e.g. iPhone 13, narrow tablets) - single column, full-width bars */
@media (max-width: 640px) {
  .container {
    padding: 0.75rem 1rem;
  }
  .bus-list {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .bus-card {
    padding: 1.125rem;
    width: 100%;
    box-sizing: border-box;
  }
  .search-bar {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 1.25rem;
  }
  .search-bar .form-group {
    flex: 1 1 auto;
    min-width: 0;
    margin-bottom: 0;
  }
  .search-bar input {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
  }
  .search-bar .btn {
    width: 100%;
    min-height: 48px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }
}

/* Mobile and small tablet */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
  }
  .app-header h1 {
    font-size: 1.25rem;
  }
  .app-header .nav {
    width: 100%;
  }
  .app-header .nav .text-muted {
    flex: 0 0 100%;
    white-space: normal;
    text-align: left;
  }
  .app-header .nav a,
  .app-header .nav .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }
  .container {
    padding: 0.75rem 1rem;
  }
  .page-title {
    font-size: 1.35rem;
    margin-bottom: 1rem;
  }
  .landing-hero {
    min-height: 60vh;
    padding: 1.5rem 1rem;
  }
  .landing-hero h1 {
    font-size: 1.5rem;
  }
  .landing-hero .btn {
    width: 100%;
    max-width: 280px;
  }
  .role-cards {
    grid-template-columns: 1fr;
    margin-top: 1.5rem;
  }
  .bus-list {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .search-bar {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    flex-direction: column;
    align-items: stretch;
  }
  .search-bar label {
    display: block;
    width: 100%;
    text-align: center;
  }
  .search-bar .form-group {
    flex: 1;
    min-width: 0;
  }
  .search-bar input {
    min-height: 48px;
    font-size: 16px;
    box-sizing: border-box;
  }
  .search-bar .btn {
    width: 100%;
    min-height: 48px;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .table-wrap {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap table {
    font-size: 0.9rem;
  }
  th, td {
    padding: 0.6rem 0.5rem;
    white-space: nowrap;
  }
  .stats-grid,
  .stats-grid-dashboard {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  .stat-card-dash .stat-num {
    font-size: 1.5rem;
  }
  .action-cards {
    grid-template-columns: 1fr;
  }
  .recent-cards {
    grid-template-columns: 1fr;
  }
  .modal-box {
    max-width: calc(100% - 2rem);
    max-height: 90vh;
  }
  .card {
    padding: 1rem;
  }
}

/* Small phones (e.g. iPhone 13 portrait, narrow devices) */
@media (max-width: 480px) {
  html {
    font-size: 16px;
  }
  .app-header {
    padding: 0.75rem 1rem;
  }
  .app-header h1 {
    font-size: 1.1rem;
    line-height: 1.3;
  }
  .container {
    padding: 0.5rem 0.75rem;
  }
  .page-title {
    font-size: 1.2rem;
  }
  .landing-hero h1 {
    font-size: 1.35rem;
  }
  .bus-list {
    gap: 0.875rem;
  }
  .bus-card {
    padding: 1rem;
  }
  .bus-card .bus-number {
    font-size: 1.1rem;
  }
  .bus-card .schedule-times {
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem 0.6rem;
  }
  .time-highlight {
    font-size: 1.05rem;
  }
  .bus-card .btn-passable {
    width: 100%;
    min-height: 48px;
    margin-top: 0.75rem;
  }
  .btn {
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
  }
  .search-bar input,
  .search-bar .btn {
    min-height: 48px;
  }
  .stats-grid,
  .stats-grid-dashboard {
    grid-template-columns: 1fr;
  }
  .stat-card .num,
  .stat-card-dash .stat-num {
    font-size: 1.5rem;
  }
  .login-box {
    padding: 1.5rem 1rem;
  }
}

/* Safe area for notched devices (e.g. iPhone X+) */
@supports (padding: env(safe-area-inset-left)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .app-header {
    padding-left: max(1rem, env(safe-area-inset-left));
  }
}
