/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */
:root {
  --blue: #00449e;
  --dark-green: #00794c;
  --gold: #ffb700;
  --gray: #777;
  --orange: #e25600;
  --red: #e7040f;

  /* Light mode colors */
  --bg-color: white;
  --bg-alt: #f9f9f9;
  --bg-hover: #e6f3ff;
  --text-color: #000;
  --text-secondary: #333;
  --text-tertiary: #666;
  --border-color: #ccc;
  --border-strong: #999;
  --header-bg: #f5f5f5;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark mode colors */
    --bg-color: #1a1a1a;
    --bg-alt: #242424;
    --bg-hover: #2a4a5a;
    --text-color: #e0e0e0;
    --text-secondary: #c0c0c0;
    --text-tertiary: #a0a0a0;
    --border-color: #444;
    --border-strong: #666;
    --header-bg: #2a2a2a;
  }
}

/* Apply background color to body */
body {
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
}

/* Narratives Table Styling */
#main {
  width: 100%;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  font-weight: bold;
}

#main table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background-color: var(--bg-color);
}

#main th,
#main td {
  text-align: left;
  vertical-align: top;
  padding: 8px 4px;
  border: 1px solid var(--border-color);
  white-space: nowrap;
  overflow: hidden;
}

#main th {
  background-color: var(--header-bg);
  color: var(--text-color);
  font-weight: bold;
  font-size: 12px;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border-strong);
}

/* Fixed width columns for first 3 columns */
#main th:nth-child(1),
#main td:nth-child(1) {
  width: 60px;
  font-weight: bold;
}

#main th:nth-child(2),
#main td:nth-child(2) {
  width: 80px;
  font-weight: bold;
}

#main th:nth-child(3),
#main td:nth-child(3) {
  width: 380px;
  font-weight: bold;
}

#main th:nth-child(4),
#main td:nth-child(4) {
  width: 320px;
  font-weight: bold;
}

/* Text column takes remaining space */
#main th:nth-child(5),
#main td:nth-child(5) {
  width: auto;
  min-width: 300px;
}

/* Text column with horizontal scroll */
#main td:nth-child(5) {
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  text-overflow: initial;
  max-width: 400px;
}

/* Zebra striping for better readability */
#main tbody tr:nth-child(even) {
  background-color: var(--bg-alt);
}

#main tbody tr:hover {
  background-color: var(--bg-hover);
}

/* Make text easily readable from distance */
#main td {
  font-size: 20px;
  color: var(--text-color);
  font-weight: bold;
  line-height: 1.6;
  padding: 8px 4px;
}

/* Ensure district and quadrant are clearly formatted */
#main td:nth-child(1),
#main td:nth-child(2) {
  color: var(--text-color);
}

/* Location styling */
#main td:nth-child(3) {
  color: var(--text-secondary);
}

/* Text column styling for maximum readability */
#main td:nth-child(4) {
  color: var(--text-color);
  letter-spacing: 0.5px;
}

/* Page title styling */
h1 {
  font-size: 24px;
  margin-bottom: 20px;
  color: var(--text-secondary);
  text-align: left;
}

/* Custom scrollbar styling for text column */
#main td:nth-child(5) {
  scrollbar-width: thin;
}

.bg-pattern-red {
  background: repeating-linear-gradient(-45deg, #e7040f, #e7040f .5rem, transparent .5rem, transparent 1rem), transparent;
}

.bg-pattern-gray {
  background: repeating-linear-gradient(-45deg, #777, #777 .5rem, transparent .5rem, transparent 1rem), transparent;
}

.bg-clipped {
  background-clip: content-box, border-box;
}

/* Call Wrapper Styles (promoted from alpha) */
.call-wrapper {
  margin-bottom: 0;
}

.call-header {
  display: grid;
  grid-template-columns: 60px 80px 380px 1fr auto;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-color);
  background-color: var(--header-bg);
  position: relative;
}

.call-wrapper+.call-wrapper .call-header {
  border-top: 2px solid var(--text-secondary);
}

.call-header>div {
  padding: 8px 4px;
  font-size: 20px;
  font-weight: bold;
  border-right: 1px solid var(--border-color);
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  z-index: 1;
  color: var(--text-color);
}

.call-header>div:last-child {
  border-right: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
}

.print-link {
  font-size: 14px;
  color: var(--text-color);
  text-decoration: none;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-color);
  cursor: pointer;
  white-space: nowrap;
}

.print-link:hover {
  background-color: var(--bg-hover);
}

.print-link.printing {
  opacity: 0.6;
  pointer-events: none;
}

/* Hide print button when in no-printing mode */
body.printer-mode-no-printing .print-link {
  display: none;
}

/* Hide separator when print button is hidden */
body.printer-mode-no-printing .button-separator {
  display: none;
}

.call-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.button-separator {
  color: var(--text-tertiary);
  font-size: 14px;
  font-weight: normal;
}

.preview-link {
  font-size: 14px;
  color: var(--text-color);
  text-decoration: none;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-color);
  cursor: pointer;
  white-space: nowrap;
}

.preview-link:hover {
  background-color: var(--bg-hover);
}

.preview-link.printing {
  opacity: 0.6;
  pointer-events: none;
}

.call-subheader {
  padding: 4px 8px;
  background-color: var(--bg-alt);
  border-left: 1px solid var(--border-strong);
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-color);
  font-size: 16px;
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
  align-items: center;
}

.subheader-label {
  font-weight: bold;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: 0.5px;
}

.subheader-value {
  font-weight: bold;
  color: var(--text-secondary);
}

.narratives-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border-strong);
  border-top: none;
  position: relative;
}

.narratives-table::before {
  content: '';
  position: absolute;
  left: 0;
  top: 1px;
  bottom: 0;
  width: 60px;
  pointer-events: none;
}

.narratives-table.pattern-red::before {
  background: repeating-linear-gradient(-45deg, #e7040f, #e7040f .5rem, var(--bg-color) .5rem, var(--bg-color) 1rem);
}

.narratives-table.pattern-red.dispatched::before {
  background: repeating-linear-gradient(-45deg, #b44545, #b44545 .5rem, var(--bg-color) .5rem, var(--bg-color) 1rem);
}

#main .narratives-table td {
  padding: 6px 4px;
  padding-left: 64px;
  border: 1px solid var(--border-color);
  vertical-align: top;
  width: auto;
  white-space: nowrap;
  overflow-x: auto;
}

.narratives-table tr {
  background-color: var(--bg-color);
}

.narratives-table tr:nth-child(even) {
  background-color: var(--bg-alt);
}

.narratives-table tr:hover {
  background-color: var(--bg-hover);
}

/* Keyboard Input Footer - Terminal Style */
.keyboard-input {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  font-family: monospace;
  font-size: 16px;
  color: var(--text-secondary);
  background-color: var(--header-bg);
  border-top: 1px solid var(--border-color);
  pointer-events: none;
  z-index: 1000;
  user-select: none;
  box-sizing: border-box;
}

.keyboard-input-text {
  display: flex;
  align-items: center;
}

.keyboard-input-text::before {
  content: '> ';
  color: var(--text-tertiary);
}

.keyboard-input .cursor-blink {
  display: inline-block;
  width: 8px;
  height: 18px;
  background-color: var(--text-secondary);
  margin-left: 2px;
  animation: blink 1s step-end infinite;
}

.keyboard-input.printing {
  color: var(--dark-green);
  font-weight: bold;
}

.keyboard-input.printing .cursor-blink {
  display: none;
}

.keyboard-input.error {
  color: var(--red);
  font-weight: bold;
}

.keyboard-input.error .cursor-blink {
  display: none;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Pulse Animation for Matched Calls */
@keyframes printing-pulse {
  0% {
    opacity: 0;
  }

  40% {
    opacity: 0.7;
  }

  60% {
    opacity: 0.7;
  }

  100% {
    opacity: 0;
  }
}

.call-wrapper.printing .call-header::before,
.call-card.printing .card-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(-45deg,
      var(--dark-green),
      var(--dark-green) .5rem,
      transparent .5rem,
      transparent 1rem);
  pointer-events: none;
  animation: printing-pulse 0.8s ease-in-out;
  opacity: 0;
  z-index: 0;
}

/* Footer Config Button */
.footer-config-btn {
  pointer-events: auto;
  background: var(--bg-alt);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 4px 12px;
  font-family: monospace;
  font-size: 12px;
  cursor: pointer;
  text-transform: uppercase;
}

.footer-config-btn:hover {
  background: var(--bg-hover);
}

/* Printer Configuration Modal - Utilitarian */
.printer-config-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.printer-config-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1;
}

.printer-config-content {
  position: relative;
  z-index: 2;
  background: var(--bg-color);
  border: 2px solid var(--border-color);
  padding: 20px;
  max-width: 500px;
  width: 90%;
  font-family: monospace;
}

.printer-config-content h2 {
  margin: 0 0 20px 0;
  color: var(--text-color);
  font-size: 16px;
  font-weight: bold;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.config-section {
  margin-bottom: 20px;
}

.config-label {
  display: block;
  font-weight: bold;
  color: var(--text-color);
  margin-bottom: 5px;
  font-size: 14px;
}

.config-value {
  padding: 8px;
  background: var(--bg-alt);
  border: 1px solid var(--border-color);
  font-family: monospace;
  color: var(--text-secondary);
  word-break: break-all;
  font-size: 12px;
}

.config-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: bold;
  color: var(--text-color);
  font-size: 14px;
  margin-bottom: 5px;
}

.config-radio input[type="radio"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.config-help {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.3;
  font-weight: normal;
}

.config-status {
  min-height: 20px;
  margin-bottom: 10px;
  padding: 8px;
  font-weight: bold;
  font-size: 12px;
}

.config-status.success {
  background: var(--dark-green);
  color: white;
}

.config-status.error {
  background: var(--red);
  color: white;
}

.config-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.config-btn {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  font-family: monospace;
  text-transform: uppercase;
}

.config-btn-primary {
  background: var(--text-color);
  color: var(--bg-color);
  border-color: var(--text-color);
}

.config-btn-primary:hover {
  background: var(--text-secondary);
  border-color: var(--text-secondary);
}

.config-btn-secondary {
  background: var(--bg-color);
  color: var(--text-color);
}

.config-btn-secondary:hover {
  background: var(--bg-alt);
}

/* Riprun Preview Modal */
.riprun-preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.riprun-preview-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1;
}

.riprun-preview-content {
  position: relative;
  z-index: 2;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  max-width: 1000px;
  width: 90%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.preview-header {
  background: var(--text-color);
  color: var(--bg-color);
  padding: 6px 12px;
  position: relative;
  border-bottom: 1px solid var(--border-color);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-right: 40px;
}

.header-text {
  flex: 1;
}

.preview-address {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 2px;
}

.preview-call-type {
  font-size: 16px;
  opacity: 0.9;
}

.header-badges {
  display: flex;
  flex-direction: row;
  gap: 4px;
  flex-shrink: 0;
}

.badge-header {
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  line-height: 1;
}

.preview-close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: 1px solid var(--bg-color);
  color: var(--bg-color);
  font-size: 20px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.preview-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Body */
.preview-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
}

.preview-section {
  border: 1px solid var(--border-color);
  padding: 6px;
  background: var(--bg-alt);
}

.preview-section h3 {
  display: none;
}

/* Location */
.preview-section:first-child {
  grid-column: 1;
}

.location-line {
  display: block;
}

.location-address {
  font-size: 16px;
  font-weight: bold;
  color: var(--text-color);
}

.location-common-name {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Directions */
.preview-section:nth-child(2) {
  grid-column: 2;
}

.directions-list {
  font-size: 13px;
  line-height: 1.5;
  text-align: right;
}

.directions-list div {
  padding: 3px 0;
  border-bottom: 1px solid var(--border-color);
}

.directions-list div:last-child {
  border-bottom: none;
}

/* Travel Times */
.preview-section:nth-child(3) {
  grid-column: 1 / -1;
  border: none;
  background: transparent;
  padding: 6px 0;
}

.travel-times-grid {
  display: flex;
  justify-content: space-evenly;
  ;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
}

.tt-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.tt-station {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 1px;
}

.tt-apparatus {
  font-size: 11px;
  font-weight: normal;
  color: var(--text-tertiary);
  margin-bottom: 2px;
  white-space: nowrap;
}

.tt-time {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Narratives */
.preview-section:nth-child(4) {
  grid-column: 1 / -1;
  overflow-y: auto;
}

.narratives-list {
  font-size: 13px;
  line-height: 1.4;
}

.narrative-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.narrative-item:last-child {
  border-bottom: none;
}

/* Map */
.preview-map-section {
  grid-column: 1 / -1;
}

.preview-map-section img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 752 / 450;
  background: #1a1a1a;
}

/* Login Page */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-box {
  width: 100%;
  max-width: 360px;
  font-family: monospace;
}

.login-box h2 {
  margin: 0 0 20px 0;
  font-size: 16px;
  text-transform: uppercase;
  color: var(--text-color);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.login-alert {
  background: var(--red);
  color: white;
  padding: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: bold;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.login-field input {
  width: 100%;
  padding: 8px;
  font-family: monospace;
  font-size: 16px;
  box-sizing: border-box;
}

.login-submit {
  width: 100%;
  padding: 10px;
  background: var(--text-color);
  color: var(--bg-color);
  border: 1px solid var(--text-color);
  font-family: monospace;
  font-size: 13px;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
}

.login-submit:hover {
  background: var(--text-secondary);
  border-color: var(--text-secondary);
}

/* Form inputs - dark mode support */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  background-color: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 4px 8px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: 1px solid var(--text-secondary);
  border-color: var(--text-secondary);
}

/* ========== Mobile Responsive ========== */
@media (max-width: 600px) {

  /* Stronger visual separation between calls */
  .call-wrapper+.call-wrapper {
    margin-top: 12px;
  }

  .call-wrapper+.call-wrapper .call-header {
    border-top: 3px solid var(--text-secondary);
  }

  .call-header {
    background-color: #e0e0e0;
    border: 1px solid var(--border-strong);
    border-bottom: 2px solid var(--border-strong);
  }

  /* Narratives table: distinct background from header */
  .narratives-table {
    background-color: var(--bg-color);
  }

  .narratives-table tr {
    background-color: var(--bg-color);
  }

  .narratives-table tr:nth-child(even) {
    background-color: var(--bg-alt);
  }

  /* Call subheader: match header distinction */
  .call-subheader {
    background-color: #ebebeb;
    border-bottom: 1px solid var(--border-strong);
  }

  /* Call header: district + quadrant on row 1, location + type on row 2 */
  .call-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  .call-header>div {
    padding: 4px 6px;
    font-size: 16px;
    border-right: none;
    border-bottom: none;
  }

  /* District */
  .call-header>div:nth-child(1) {
    font-size: 18px;
  }

  /* Quadrant */
  .call-header>div:nth-child(2) {
    font-size: 18px;
  }

  /* Location - full width on its own row */
  .call-header>div:nth-child(3) {
    order: 5;
    flex-basis: 100%;
    font-size: 14px;
    white-space: normal;
    word-break: break-word;
    border-top: 1px solid var(--border-color);
    padding: 3px 6px;
  }

  /* Call type - same row as district/quadrant, takes remaining space */
  .call-header>div:nth-child(4) {
    order: 2;
    flex: 1;
    font-size: 14px;
    white-space: normal;
    padding: 4px 6px;
    color: var(--text-secondary);
  }

  /* Actions - push to right on row 1 */
  .call-header>div:last-child {
    margin-left: auto;
    order: 3;
  }

  /* Hide empty location/type rows */
  .call-header>div:nth-child(3):empty,
  .call-header>div:nth-child(4):empty {
    display: none;
  }

  /* Narrative text: allow wrapping */
  #main .narratives-table td {
    white-space: normal;
    word-break: break-word;
    overflow-x: visible;
    padding-left: 10px;
    font-size: 14px;
  }

  /* Narrower color stripe on mobile */
  .narratives-table::before {
    width: 6px;
  }

  /* Subheader */
  .call-subheader {
    font-size: 13px;
    flex-wrap: wrap;
  }

  /* Footer: hide keyboard input, just show buttons */
  .keyboard-input {
    height: auto;
    padding: 6px 10px;
  }

  .keyboard-input-text {
    display: none;
  }

  .keyboard-input>div {
    flex-wrap: wrap;
  }

  /* Preview modal: single column */
  .preview-body {
    grid-template-columns: 1fr;
  }

  .preview-section:first-child,
  .preview-section:nth-child(2),
  .preview-section:nth-child(3),
  .preview-section:nth-child(4) {
    grid-column: 1;
  }

  .preview-address {
    font-size: 18px;
  }

  .preview-call-type {
    font-size: 14px;
  }

  .badge-header {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  .header-content {
    padding-right: 30px;
  }

  .directions-list {
    text-align: left;
  }

  /* Main text sizing */
  #main {
    font-size: 14px;
  }

  #main td {
    font-size: 14px;
    padding: 4px 2px;
  }

  /* Printer config modal */
  .printer-config-content {
    max-width: 100%;
    width: 95%;
    padding: 12px;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Call actions - smaller buttons */
  .print-link,
  .preview-link {
    font-size: 12px;
    padding: 3px 6px;
  }

  /* Travel times grid */
  .travel-times-grid {
    justify-content: flex-start;
  }

  /* Preview map */
  .preview-map-section {
    grid-column: 1;
  }
}

/* Dark mode overrides for mobile header distinction */
@media (max-width: 600px) and (prefers-color-scheme: dark) {
  .call-header {
    background-color: #383838;
  }

  .call-subheader {
    background-color: #333;
  }
}