/**
 * STATIONSTAT v3 Design System
 * Flat, solid colors, system font stack, responsive, zero external assets.
 */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #d8dee4;
  --border-focus: #1f5fbf;
  --text: #1f2933;
  --muted: #52606d;
  --accent: #1f5fbf;
  --accent-hover: #184c99;
  --accent-bg: #eaf1fa;

  --available: #1b7f4c;
  --available-bg: #eaf6ee;
  --available-border: #b7e4ca;

  --reserved: #b7791f;
  --reserved-bg: #fdf6ea;
  --reserved-border: #f4dfbe;

  --in-use: #1f5fbf;
  --in-use-bg: #eaf1fa;
  --in-use-border: #bed2f4;

  --maintenance: #52606d;
  --maintenance-bg: #f0f2f5;
  --maintenance-border: #cfd6de;

  --danger: #b42318;
  --danger-bg: #fdf2f2;
  --danger-border: #f8c9c7;

  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

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

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mono, .font-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Header & Navigation */
.header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
}
.header-container {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
  color: var(--text);
}
.brand-badge {
  background-color: var(--accent);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
}
.header-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: var(--muted);
  flex-wrap: wrap;
}
.clock {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}
.conn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--available);
}
.conn-dot.stale { background-color: var(--reserved); }
.conn-dot.error { background-color: var(--danger); }

/* Layout & Container */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
  flex: 1;
}

/* Tabs */
.tabs-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 4px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  min-height: 44px;
  white-space: nowrap;
  transition: color 150ms ease, border-color 150ms ease;
}
.tab-link:hover, .tab-link:focus-visible {
  color: var(--text);
  outline: none;
}
.tab-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.badge-count {
  background-color: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--in-use-border);
  font-size: 14px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}

/* Summary Bar */
.summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.stat-pill {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}
.stat-pill strong {
  font-family: var(--font-mono);
  font-size: 15px;
}

/* Filters & Search Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-chip {
  background-color: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: all 150ms ease;
}
.filter-chip:hover {
  background-color: #f8fafc;
  color: var(--text);
}
.filter-chip.active {
  background-color: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* Inputs, Selects, Buttons */
.input, .select, .textarea {
  width: 100%;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  min-height: 44px;
  transition: border-color 150ms ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  min-height: 44px;
  min-width: 44px;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}
.btn-secondary {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background-color: #f8fafc;
  border-color: #b0bac5;
}
.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background-color: #8c1b12;
}
.btn-sm {
  min-height: 36px;
  padding: 4px 10px;
  font-size: 14px;
}

/* Station Grid */
.station-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.station-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  position: relative;
}
.station-card:hover {
  border-color: var(--accent);
}
.station-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.station-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.station-name {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}
.status-available { background-color: var(--available-bg); color: var(--available); border-color: var(--available-border); }
.status-reserved { background-color: var(--reserved-bg); color: var(--reserved); border-color: var(--reserved-border); }
.status-in_use { background-color: var(--in-use-bg); color: var(--in-use); border-color: var(--in-use-border); }
.status-maintenance { background-color: var(--maintenance-bg); color: var(--maintenance); border-color: var(--maintenance-border); }
.status-offline { background-color: #f1f3f5; color: var(--muted); border-color: var(--border); }
.status-danger { background-color: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
/* Counter: two reservations of one day share a customer name (staff then check the PC and time). Neutral, not a status. */
.same-name-badge { display: inline-block; margin-left: 6px; padding: 1px 6px; font-size: 14px; font-weight: 700; color: var(--text); background-color: var(--bg); border: 1px solid #7b8794; border-radius: 4px; white-space: nowrap; vertical-align: middle; cursor: help; }

.card-banner {
  background-color: var(--reserved-bg);
  border: 1px solid var(--reserved-border);
  color: var(--reserved);
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  margin: 6px 0;
}
.card-timer {
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--text);
  margin: 6px 0;
  font-weight: 600;
}
.card-agent-line {
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  border-top: 1px solid #edf0f2;
  padding-top: 8px;
}
.agent-metrics {
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--muted);
  margin-top: 4px;
}

/* Side Drawer (Card Details) */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(31, 41, 51, 0.4);
  z-index: 100;
  display: none;
}
.drawer-backdrop.open {
  display: block;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 100vw;
  background-color: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 101;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 200ms ease, visibility 0s linear 200ms;
  overflow: hidden;
}
.drawer.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 200ms ease;
}
.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-body {
  padding: 20px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.drawer-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background-color: var(--bg);
}

/* Modals & Dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(31, 41, 51, 0.5);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open {
  display: flex;
}
.modal-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-x: hidden;
  overflow-y: auto;
}
.modal-card.modal-card-sm {
  max-width: 360px;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body {
  padding: 20px;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background-color: var(--bg);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  background-color: #f8fafc;
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td {
  border-bottom: none;
}
.table tr:hover {
  background-color: #fafbfc;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  pointer-events: none;
}
.toast {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.toast-success { border-left-color: var(--available); }
.toast-error { border-left-color: var(--danger); }

/* Banner */
.offline-banner {
  background-color: var(--danger);
  color: #ffffff;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  display: none;
  align-items: center;
  justify-content: space-between;
}
.offline-banner.visible {
  display: flex;
}

/* Toolbar fields (replace the former inline widths) */
.toolbar-grow {
  flex: 1 1 220px;
  max-width: 320px;
}
.input-auto {
  width: auto;
}
.input-compact {
  min-height: 36px;
  padding: 4px 8px;
}
.search-input {
  width: 200px;
  max-width: 100%;
}
.input-minutes {
  width: 100px;
}

/* Responsive Rules */
@media (max-width: 480px) {
  .toolbar-grow,
  .search-input {
    flex: 1 1 100%;
    max-width: none;
    width: 100%;
  }
  .toolbar-group {
    width: 100%;
  }
}
@media (max-width: 768px) {
  /* Touch targets: at least 44 x 44 px on phones and tablets */
  .btn,
  .btn-sm,
  .filter-chip,
  .stat-pill,
  .summary-tile-btn,
  .tab-link,
  .input,
  .select,
  .input-compact,
  .header button,
  a.brand {
    min-height: 44px;
  }
  .btn,
  .btn-sm,
  .filter-chip,
  .header button {
    min-width: 44px;
  }
  a.brand {
    display: inline-flex;
    align-items: center;
  }
  .drawer {
    width: 100vw;
  }
  .header-container {
    flex-direction: column;
    align-items: flex-start;
  }
  .table-stacked td {
    display: block;
    text-align: right;
  }
}

/* Phase 4 UI Enhancements: Spacing Scale & Typography */
.text-sm { font-size: 14px; }
.text-base { font-size: 16px; }
.text-lg { font-size: 20px; font-weight: 700; }
.text-xl { font-size: 28px; font-weight: 800; }

.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
}

.sticky-th {
  position: sticky;
  top: 0;
  background-color: var(--surface);
  z-index: 10;
  box-shadow: 0 1px 0 var(--border);
}

/* Desktop Sidebar Navigation (>= 1024px) */
@media (min-width: 1024px) {
  .counter-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: calc(100vh - 65px);
  }
  .counter-sidebar {
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .counter-sidebar .tab-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    border-bottom: none;
    transition: all 120ms ease;
  }
  .counter-sidebar .tab-link:hover {
    background-color: #f1f5f9;
    color: var(--text);
  }
  .counter-sidebar .tab-link.active {
    background-color: var(--accent-bg);
    color: var(--accent);
    font-weight: 700;
  }
  .counter-top-nav {
    display: none !important;
  }
}

@media (max-width: 1023px) {
  .counter-sidebar {
    display: none !important;
  }
  .counter-top-nav {
    display: flex !important;
  }
}

/* Interactive Summary Tile Buttons */
.summary-tile-btn {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: all 120ms ease;
}
.summary-tile-btn:hover {
  border-color: var(--accent);
}
.summary-tile-btn.active {
  border-color: var(--accent);
  background-color: var(--accent-bg);
  color: var(--accent);
}

/* Card Direct Start Button */
.btn-card-start {
  margin-top: 8px;
  width: 100%;
  font-size: 14px;
  font-weight: 700;
  padding: 6px 12px;
  min-height: 36px;
}
@media (max-width: 768px) {
  .btn-card-start {
    min-height: 44px;
  }
}

/* Skeleton Loading Placeholder */
.skeleton-row {
  height: 48px;
  background-color: #f1f5f9;
  border-radius: var(--radius);
  margin-bottom: 8px;
  animation: pulse-placeholder 1.5s infinite ease-in-out;
}
@keyframes pulse-placeholder {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* Fieldset Groups in Admin */
.settings-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px 20px;
  margin-bottom: 20px;
  background-color: #ffffff;
}
.settings-legend {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding: 0 8px;
}

/* Hourly Row Group Divider */
.hour-divider-row {
  background-color: #f8fafc;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.now-marker-row {
  background-color: #eff6ff !important;
  color: var(--accent) !important;
  font-weight: 700 !important;
  border-top: 2px solid var(--accent) !important;
  border-bottom: 2px solid var(--accent) !important;
}

/* Guided tour of the counter page: a flat ring around one real element and a small card */
.tour-ring {
  position: fixed;
  z-index: 240;
  display: none;
  pointer-events: none;
  border: 3px solid var(--accent);
  border-radius: var(--radius);
  outline: 2px solid var(--surface);
  box-shadow: 0 0 0 9999px rgba(31, 41, 51, 0.4);
}
.tour-ring.open {
  display: block;
}
.tour-card {
  position: fixed;
  z-index: 250;
  display: none;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
}
.tour-card.open {
  display: block;
}
.tour-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.tour-title {
  font-size: 18px;
  font-weight: 700;
  margin: 2px 0 6px;
}
.tour-body {
  font-size: 15px;
  line-height: 1.5;
}
.tour-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}
.tour-actions-right {
  display: flex;
  gap: 8px;
}
.tour-actions .btn {
  min-height: 48px;
  min-width: 48px;
}
@media (max-width: 639px) {
  /* Phones: the card is fixed at the bottom and the page can scroll clear of it */
  .tour-card {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 60vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  body.tour-open {
    padding-bottom: 60vh;
  }
  /* the sticky header takes half of a small screen: let it scroll away while the tour is open */
  body.tour-open .sticky-header {
    position: static;
  }
}

/* How to: numbered tasks, each one short steps */
@media (max-width: 768px) {
  #btn-how-to {
    min-height: 48px;
  }
}
.howto-tasks {
  margin: 0;
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 15px;
  line-height: 1.5;
}
.howto-tasks > li > strong {
  display: block;
}
.howto-tasks ul {
  margin: 4px 0 0;
  padding-left: 18px;
}
.howto-footer {
  flex-wrap: wrap;
}
.howto-footer .btn {
  min-height: 48px;
}

/* Print Stylesheet */
@media print {
  .tour-ring, .tour-card, .header, .sticky-header, .counter-sidebar, .counter-top-nav, .toolbar, .tabs-nav, .btn, .drawer, .toast-container, .offline-banner, .filter-chip, .summary-bar {
    display: none !important;
  }
  body, .container, main, .counter-layout {
    background-color: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }
  .print-header {
    display: block !important;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #000000;
  }
  .table {
    width: 100% !important;
    border-collapse: collapse !important;
  }
  .table th, .table td {
    border: 1px solid #333333 !important;
    color: #000000 !important;
    padding: 6px 10px !important;
    font-size: 11pt !important;
  }
  .table th:last-child, .table td:last-child {
    display: none !important; /* Hide actions column */
  }
}
@media screen {
  .print-header {
    display: none !important;
  }
}

/* Respect the OS/browser "reduce motion" setting (Phase 3 UI pass):
   kill the infinite skeleton-loading pulse and shrink every transition
   to effectively nothing, without removing the transition property
   itself (so nothing else breaks). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

