/* Clearbrook Shuttle - Apple-like Minimalist Design */

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

/* Design Tokens */
:root {
  /* Colors */
  --background: #FFFFFF;
  --background-secondary: #F5F5F7;
  --background-tertiary: #E8E8ED;
  --text-primary: #1D1D1F;
  --text-secondary: #86868B;
  --text-tertiary: #AEAEB2;
  --accent: #0071E3;
  --accent-hover: #0077ED;
  --success: #30D158;
  --warning: #FF9F0A;
  --error: #FF3B30;
  --border: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Safe Area */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);

  /* Bottom Nav Height */
  --bottom-nav-height: 64px;
}

/* Typography */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.47059;
  color: var(--text-primary);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  touch-action: manipulation;
}

h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.022em;
}

h1 { font-size: 28px; line-height: 1.14286; }
h2 { font-size: 22px; line-height: 1.27273; }
h3 { font-size: 17px; line-height: 1.29412; }
h4 { font-size: 15px; line-height: 1.33333; }

/* App Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* Views Container */
.views-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
}

.view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view.active {
  opacity: 1;
  visibility: visible;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  background: var(--background);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  z-index: 1000;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.nav-item {
  flex: 1;
  height: var(--bottom-nav-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
  color: var(--accent);
}

.nav-icon {
  width: 24px;
  height: 24px;
}

/* Map View */
#map-view {
  background: var(--background-secondary);
  padding-top: var(--safe-area-top);
}

.map-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.map-header {
  padding: 0 var(--space-md);
}

.map-header .view-header-bar {
  padding: var(--space-md) 0;
}

#map {
  width: 100%;
  flex: 1;
}

/* Info Panel */
.info-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--background);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-lg);
  max-height: 50vh;
  overflow-y: auto;
  padding: var(--space-lg);
  padding-top: var(--space-md);
  transform: translateY(0);
  transition: transform 0.3s ease;
  z-index: 100;
}

.info-panel.hidden {
  transform: translateY(100%);
}

.info-panel::before {
  content: '';
  display: block;
  width: 36px;
  height: 5px;
  background: var(--background-tertiary);
  border-radius: 3px;
  margin: 0 auto var(--space-md);
}

.info-panel h3 {
  margin-bottom: var(--space-md);
}

.info-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child {
  border-bottom: none;
}

.info-row .label {
  color: var(--text-secondary);
}

.info-row .value {
  font-weight: 500;
}

.close-btn {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--background-secondary);
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.close-btn:hover {
  background: var(--background-tertiary);
}

/* Status View */
#status-view {
  background: var(--background-secondary);
  padding-top: var(--safe-area-top);
}

.status-container {
  padding: var(--space-md);
  padding-top: 0;
  max-width: 600px;
  margin: 0 auto;
}

/* Status View */
.view-header-bar {
  position: sticky;
  top: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) 0;
  background: var(--background-secondary);
}

.view-header-bar h2 {
  margin: 0;
}

.view-header-bar.header-centered {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.view-header-bar.header-centered h2 {
  justify-self: center;
  white-space: nowrap;
}

.view-header-bar.header-centered::after {
  content: '';
  min-width: 72px;
}

.header-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  min-width: 72px;
  text-align: left;
}

.status-panel {
  margin-bottom: var(--space-lg);
}

.status-panel .section-card + .section-card {
  margin-top: var(--space-lg);
}

.section-card {
  background: var(--background);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.section-header h3 {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.section-header.with-action {
  margin-bottom: var(--space-lg);
}

.settings-panel {
  margin-bottom: var(--space-lg);
}

.nav-row {
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: var(--space-md) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.nav-row:last-child {
  border-bottom: none;
}

.nav-row-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-row-title {
  font-weight: 600;
}

.nav-row-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.nav-row-chevron {
  color: var(--text-tertiary);
  font-size: 18px;
}

.readonly-field {
  padding: var(--space-sm) var(--space-md);
  background: var(--background-secondary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.poi-map {
  height: 200px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.poi-map-wrap {
  position: relative;
  z-index: 0;
}

.detail-panel {
  padding-top: var(--space-lg);
}

.radius-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}

.radius-group label {
  margin-bottom: 0;
}

.radius-row input[type="range"] {
  flex: 1;
}

.radius-unit {
  color: var(--text-secondary);
}

.radius-value {
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-input {
  width: 44px;
  height: 24px;
}

.ios-table {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.ios-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
}

.ios-row:last-child {
  border-bottom: none;
}

.ios-label {
  color: var(--text-secondary);
}

.ios-value {
  font-weight: 500;
  text-align: right;
}

.status-row {
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: var(--space-md) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.status-row:last-child {
  border-bottom: none;
}

.status-row-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-row-title {
  font-weight: 600;
}

.status-row-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.status-row-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.status-light {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-in-service {
  background: var(--success);
}

.status-issue {
  background: var(--warning);
}

.status-inactive {
  background: var(--error);
}

.status-true {
  background: var(--success);
}

.status-false {
  background: var(--error);
}

.row-chevron {
  color: var(--text-tertiary);
  font-size: 22px;
  font-weight: 600;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
}

.detail-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

.debug-status {
  font-family: 'SFMono-Regular', ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  background: var(--background);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-lg);
}

.status-row-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}

.status-row-value {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}

.ios-row.collapsible {
  cursor: pointer;
}

.ios-row-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.ios-row-group.hidden {
  display: none;
}

.ios-row.sub-row {
  padding-left: var(--space-md);
  color: var(--text-secondary);
  font-size: 13px;
}

/* Settings View */
#settings-view {
  background: var(--background-secondary);
  padding-top: var(--safe-area-top);
}

.settings-container {
  padding: var(--space-md);
  padding-top: 0;
  max-width: 600px;
  margin: 0 auto;
}

.settings-container > h2 {
  margin-bottom: var(--space-lg);
}

.settings-section {
  background: var(--background);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
}

.settings-section h3 {
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.setting-group {
  margin-bottom: var(--space-lg);
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-group h4 {
  margin-bottom: var(--space-md);
}

/* Forms */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-xs);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group select,
.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 17px;
  background: var(--background);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: var(--space-md);
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
}

.btn-loading {
  opacity: 0.7;
  cursor: default;
}

.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  padding: var(--space-sm) var(--space-md);
  background: var(--background-secondary);
  color: var(--text-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: var(--background-tertiary);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--background-secondary);
  color: var(--accent);
  font-size: 20px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--background-tertiary);
}

.btn-danger {
  width: 100%;
  padding: var(--space-md);
  background: var(--error);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  margin-top: var(--space-md);
}

.btn-neutral {
  width: 100%;
  padding: var(--space-md);
  background: var(--background-secondary);
  color: var(--text-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  margin-top: var(--space-md);
}

/* Subscriptions List */
.subscriptions-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.subscription-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  background: var(--background-secondary);
  border-radius: var(--radius-sm);
}

.subscription-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.subscription-type {
  font-size: 13px;
  color: var(--text-secondary);
}

.subscription-stop {
  font-weight: 500;
}

.subscription-eta {
  font-size: 13px;
  color: var(--accent);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.poi-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.poi-name {
  font-weight: 500;
}

.poi-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

.delete-btn {
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}

.delete-btn:hover {
  background: var(--background-tertiary);
  color: var(--error);
}

/* Alerts List */
.alerts-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-height: 300px;
  overflow-y: auto;
}

.alert-item {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--background-secondary);
  border-radius: var(--radius-sm);
}

.alert-icon {
  font-size: 20px;
}

.alert-content {
  flex: 1;
}

.alert-message {
  font-size: 15px;
  margin-bottom: 2px;
}

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

/* Connection Info */
.connection-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.connection-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
}

.connection-status {
  font-weight: 500;
}

.connection-status.connected {
  color: var(--success);
}

.connection-status.disconnected {
  color: var(--error);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-secondary);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 500px;
  background: var(--background);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-lg) + var(--safe-area-bottom));
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
}

.modal-header h3 {
  margin: 0;
}

.modal-actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.modal-actions button {
  flex: 1;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: calc(var(--safe-area-top) + var(--space-md));
  left: var(--space-md);
  right: var(--space-md);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  background: var(--text-primary);
  color: var(--background);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: fadeInDown 0.3s ease;
  pointer-events: auto;
}

.toast.fade-out {
  animation: fadeOutUp 0.3s ease forwards;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOutUp {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Map Markers */
.vehicle-marker {
  background: none !important;
  border: none !important;
}

.stop-marker {
  background: none !important;
  border: none !important;
}

.map-marker {
  display: inline-block;
  position: relative;
  width: 20px;
  height: 20px;
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
}

.map-marker-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.map-marker-label {
  position: absolute;
  left: 26px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 6px;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.map-marker-stop .map-marker-dot {
  background: var(--success);
}

.map-marker-stop.custom .map-marker-dot {
  background: var(--warning);
}

.map-marker-vehicle .map-marker-dot {
  background: var(--accent);
}

/* Leaflet Overrides */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  background: var(--background) !important;
  color: var(--text-primary) !important;
  border: none !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
}

/* Hidden utility */
.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

/* Safe area utilities */
@supports (padding: max(0px)) {
  #status-view,
  #settings-view,
  #map-view {
    padding-top: max(var(--safe-area-top), 0px);
  }
}
