/* STV Triggers — base styles */

:root {
  --bg: #f4f5f7;
  --fg: #1e1e1e;
  --accent: #0063b1;
  --accent-hover: #004a8c;
  --danger: #c0392b;
  --success: #27ae60;
  --warning: #e67e22;
  --border: #ccc;
  --radius: 4px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

/* Nav */
nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--accent);
  padding: 0.5rem 1rem;
  flex-wrap: wrap;
}
nav a, nav .nav-user {
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
}
nav a:hover { text-decoration: underline; }
.nav-spacer { flex: 1; }
.nav-user { opacity: 0.8; }
.nav-links { display: contents; }
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0;
}

/* Main */
main {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1rem;
}

h1 { margin-bottom: 1rem; }
h2 { margin: 1.5rem 0 0.5rem; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  margin-right: 0.25rem;
}
.btn:hover { background: var(--accent-hover); }
.btn-trigger { background: var(--success); }
.btn-trigger:hover { background: #1e8e4e; }
.btn-edit { background: var(--warning); }
.btn-edit:hover { background: #cf6c10; }
.btn-delete { background: var(--danger); }
.btn-delete:hover { background: #962d22; }
.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  margin-right: 0.15rem;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}
.page-info {
  font-size: 0.9rem;
  color: var(--text);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  background: #fff;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th { background: #e8eaed; font-weight: 600; }

.actions { display: flex; gap: 0.25rem; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* Forms */
label {
  display: block;
  margin-top: 0.75rem;
  font-weight: 600;
  font-size: 0.9rem;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select {
  width: 100%;
  max-width: 400px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.schedule-form { margin-bottom: 1.5rem; }

/* Status badges */
.status-ok { color: #2e7d32; font-weight: bold; }
.status-error { color: #c62828; font-weight: bold; }

/* Countdown timer */
.countdown {
  font-family: 'Courier New', monospace;
  font-weight: bold;
  color: #1565c0;
}

/* Filter bar */
.filter-bar {
  margin: 0.75rem 0;
}
.filter-bar input[type="text"] {
  max-width: 100%;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

/* Quick route form */
.quick-route-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.quick-route-form label { margin: 0; }
.quick-route-form select { width: auto; max-width: none; margin: 0; }
.quick-route-form .arrow { font-size: 1.2rem; }

/* Video player */
.video-player-section {
  margin: 2rem 0 3rem;
  padding: 1.5rem;
  background: #f5f5f5;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.video-player-section h2 {
  margin-top: 0;
  font-size: 1.2rem;
}
.stream-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.stream-controls label {
  margin: 0;
  font-weight: 600;
}
.stream-controls select {
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.stream-status {
  font-size: 1.5rem;
  font-weight: bold;
  color: #f44336;
}

/* Labels grid */
.labels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}
.labels-grid table input[type="text"] { width: 100%; max-width: none; }

/* ------------------------------------------------------------------ */
/* Responsive / Mobile                                                */
/* ------------------------------------------------------------------ */
@media (max-width: 640px) {
  /* Nav: hamburger toggle */
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    gap: 0.25rem;
    padding-top: 0.5rem;
  }
  nav.open .nav-links {
    display: flex;
  }
  .nav-spacer { display: none; }
  .nav-user { margin-left: auto; }

  /* Main */
  main { margin: 1rem auto; }

  /* Tables: card layout */
  table, thead, tbody, th, td, tr {
    display: block;
  }
  thead { display: none; }
  tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }
  td {
    padding: 0.4rem 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
    position: relative;
    padding-left: 45%;
    min-height: 2rem;
  }
  td::before {
    content: attr(data-label);
    position: absolute;
    left: 0.75rem;
    top: 0.4rem;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
  }
  td:last-child { border-bottom: none; }

  .actions { justify-content: flex-end; }

  /* Forms */
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="datetime-local"],
  select {
    max-width: 100%;
  }

  /* Quick route form: stack vertically */
  .quick-route-form {
    flex-direction: column;
    align-items: stretch;
  }
  .quick-route-form select { width: 100%; }
  .quick-route-form .arrow { text-align: center; }

  /* Video player: responsive */
  .video-player-section {
    padding: 1rem;
    margin: 1.5rem 0 2rem;
  }
  .stream-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .stream-controls select {
    width: 100%;
  }

  /* Labels grid: single column */
  .labels-grid {
    grid-template-columns: 1fr;
  }

  /* Login box */
  .login-box { margin: 2rem auto; }

  /* Buttons: larger tap targets */
  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }
}

/* Flash messages */
.flashes { margin-bottom: 1rem; }
.flash {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.flash-success { background: #d4edda; color: #155724; }
.flash-danger  { background: #f8d7da; color: #721c24; }
.flash-warning { background: #fff3cd; color: #856404; }
.flash-info    { background: #d1ecf1; color: #0c5460; }

/* Login box */
.login-box {
  max-width: 340px;
  margin: 4rem auto;
  text-align: center;
}
.login-box h1 { margin-bottom: 1.5rem; }
.login-box form { text-align: left; }
.login-box button { margin-top: 1rem; width: 100%; padding: 0.6rem; }

/* ------------------------------------------------------------------ */
/* Schedule: view toggle + calendar                                    */
/* ------------------------------------------------------------------ */
.new-event-form-wrap {
  padding: 1rem;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  margin-bottom: 1rem;
}

.view-toggle {
  display: flex;
  gap: 0.5rem;
  margin: 1.25rem 0 0.75rem;
}
.view-toggle .btn.active {
  background: var(--accent-hover);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.cal-month-title {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: 1.1rem;
}

.cal-legend {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-day-header {
  background: #e8eaed;
  font-weight: 600;
  text-align: center;
  padding: 0.35rem 0.2rem;
  font-size: 0.78rem;
}
.cal-day {
  background: #fff;
  height: 105px;
  overflow: hidden;
  padding: 0.3rem 0.25rem;
}
.cal-day.other-month { background: #fafafa; }
.cal-day.other-month .cal-day-num { color: #bbb; }
.cal-day.today { background: #eff3fb; }
.cal-day-num {
  font-size: 0.78rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.15rem;
  width: 1.6em;
  height: 1.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.cal-day.today .cal-day-num {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
}
.cal-event {
  display: block;
  font-size: 0.7rem;
  padding: 0.1rem 0.25rem;
  border-radius: 3px;
  margin-bottom: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  cursor: pointer;
  font-weight: normal;
  text-decoration: none;
}
.cal-event-time {
  font-size: 0.65rem;
  opacity: 0.8;
}
.cal-event.status-pending  { background: #bbdefb; color: #0d47a1; }
.cal-event.status-ok       { background: #c8e6c9; color: #1b5e20; }
.cal-event.status-error    { background: #ffcdd2; color: #b71c1c; }
.cal-event.status-disabled { background: #f0f0f0; color: #9e9e9e; text-decoration: line-through; }
.cal-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: #888;
}

@media (max-width: 600px) {
  .cal-day-header { font-size: 0.65rem; padding: 0.25rem 0.1rem; }
  .cal-day { height: 60px; overflow: hidden; padding: 0.2rem 0.1rem; }
  .cal-day-num { font-size: 0.7rem; }
  .cal-event { font-size: 0.6rem; }
  .cal-event-time { display: none; }
}

/* ------------------------------------------------------------------ */
/* Calendar tooltip                                                    */
/* ------------------------------------------------------------------ */
.cal-tooltip {
  position: absolute;
  z-index: 1000;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 0.55rem 0.7rem;
  max-width: 260px;
  pointer-events: none;
  font-size: 0.82rem;
  line-height: 1.5;
}
.tt-name   { font-weight: 700; font-size: 0.88rem; margin-bottom: 0.1rem; }
.tt-desc   { color: #555; font-style: italic; margin-bottom: 0.2rem; font-size: 0.78rem; }
.tt-time   { color: #333; margin-bottom: 0.1rem; }
.tt-status { margin-bottom: 0.1rem; }
.tt-pending  { color: #1565c0; font-weight: 600; }
.tt-ok       { color: #1b5e20; font-weight: 600; }
.tt-error    { color: #b71c1c; font-weight: 600; }
.tt-disabled { color: #9e9e9e; }
.tt-hint { color: #888; font-size: 0.72rem; margin-top: 0.2rem; font-style: italic; border-top: 1px solid #f0f0f0; padding-top: 0.2rem; }

/* ------------------------------------------------------------------ */
/* Event modal                                                         */
/* ------------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  padding: 1.5rem 1.75rem 1.25rem;
  max-width: 440px;
  width: calc(100% - 2rem);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #777;
  padding: 0.1rem 0.3rem;
}
.modal-close:hover { color: var(--danger); }
.modal-title {
  margin: 0 1.5rem 0.6rem 0;
  font-size: 1.1rem;
}
.modal-desc {
  color: #555;
  font-size: 0.88rem;
  font-style: italic;
  margin-bottom: 0.75rem;
}
.modal-detail-table {
  width: 100%;
  margin-bottom: 1rem;
}
.modal-detail-table th,
.modal-detail-table td {
  background: none;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}
.modal-detail-table th {
  font-weight: 600;
  width: 90px;
  text-align: left;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.modal-check-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: normal;
  margin-top: 0.75rem;
}
.modal-check-label input[type="checkbox"] { width: auto; margin: 0; }
.modal-error {
  background: #f8d7da;
  color: #721c24;
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  margin: 0.5rem 0;
}
#modal-body label   { margin-top: 0.6rem; }
#modal-body select,
#modal-body input[type="datetime-local"] { max-width: 100%; }
