/* ─── RedLineCAD v2 — Component Library ──────────────────────────
   Buttons, tables, badges, forms, modals, cards, tabs, toasts.
   ────────────────────────────────────────────────────────────────── */

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
  transition:
    background 140ms cubic-bezier(0.23,1,0.32,1),
    border-color 140ms cubic-bezier(0.23,1,0.32,1),
    box-shadow 140ms cubic-bezier(0.23,1,0.32,1),
    transform 100ms cubic-bezier(0.23,1,0.32,1),
    opacity 140ms;
  white-space: nowrap;
  user-select: none;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
}

/* Shimmer sweep on hover */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,0.07) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform 380ms cubic-bezier(0.23,1,0.32,1);
  pointer-events: none;
}
.btn:hover::after { transform: translateX(100%); }

.btn:active  { transform: scale(0.96); box-shadow: none !important; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* Primary — solid red with glow */
.btn-primary {
  background: var(--rlc-red);
  color: #fff;
  border-color: var(--rlc-red);
  box-shadow: 0 0 0 0 rgba(204,0,0,0);
}
.btn-primary:hover {
  background: var(--rlc-red-bright);
  border-color: var(--rlc-red-bright);
  box-shadow: 0 0 14px rgba(204,0,0,0.45), 0 2px 6px rgba(0,0,0,0.4);
}

/* Secondary — outlined panel */
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.btn-secondary:hover {
  background: var(--bg-overlay);
  border-color: rgba(255,255,255,0.22);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* Ghost — text only, no fill */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  border-color: var(--border);
}

/* Danger — red tint outline */
.btn-danger {
  background: rgba(255,32,32,0.08);
  color: var(--status-danger);
  border-color: rgba(255,32,32,0.28);
}
.btn-danger:hover {
  background: rgba(255,32,32,0.18);
  border-color: rgba(255,32,32,0.5);
  box-shadow: 0 0 10px rgba(255,32,32,0.2);
}

/* Success — green tint outline */
.btn-success {
  background: rgba(0,204,102,0.08);
  color: var(--status-available);
  border-color: rgba(0,204,102,0.28);
}
.btn-success:hover {
  background: rgba(0,204,102,0.18);
  border-color: rgba(0,204,102,0.5);
  box-shadow: 0 0 10px rgba(0,204,102,0.2);
}

/* Info — blue tint outline */
.btn-info {
  background: rgba(26,111,255,0.08);
  color: var(--blue);
  border-color: rgba(26,111,255,0.28);
}
.btn-info:hover {
  background: rgba(26,111,255,0.18);
  border-color: rgba(26,111,255,0.5);
  box-shadow: 0 0 10px rgba(26,111,255,0.2);
}

/* Warning — amber tint outline */
.btn-warning {
  background: rgba(255,170,0,0.08);
  color: var(--status-busy);
  border-color: rgba(255,170,0,0.28);
}
.btn-warning:hover {
  background: rgba(255,170,0,0.18);
  border-color: rgba(255,170,0,0.5);
  box-shadow: 0 0 10px rgba(255,170,0,0.2);
}

/* Sizes */
.btn-xs  { padding: 4px 10px;  font-size: 0.65rem;  letter-spacing: 0.8px; }
.btn-sm  { padding: 6px 14px;  font-size: 0.7rem;   letter-spacing: 1px; }
.btn-lg  { padding: 11px 26px; font-size: 0.8125rem; letter-spacing: 1.4px; }
.btn-xl  { padding: 14px 32px; font-size: 0.875rem;  letter-spacing: 1.6px; }
.btn-icon { padding: 7px; width: 32px; height: 32px; letter-spacing: 0; }

/* Full-width helper */
.btn-block { width: 100%; justify-content: center; }

/* ─── Data Table ─────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th {
  text-align: left;
  padding: var(--space-2) var(--space-4);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table td:first-child { color: var(--text-primary); font-weight: 500; }

.data-table tr { cursor: pointer; transition: background var(--transition-fast); }
.data-table tr:hover td { background: var(--bg-hover); }
.data-table tr.selected td { background: var(--bg-active); }
.data-table tr.selected td:first-child { color: var(--rlc-red); }

/* ─── Status Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-available { background: rgba(0,204,102,0.15);  color: var(--status-available); }
.badge-busy      { background: rgba(255,170,0,0.15);  color: var(--status-busy); }
.badge-offline   { background: rgba(74,85,104,0.2);   color: var(--status-offline); }
.badge-danger    { background: rgba(255,32,32,0.15);  color: var(--status-danger); }
.badge-info      { background: rgba(26,111,255,0.15); color: var(--status-info); }
.badge-leo       { background: rgba(26,111,255,0.15); color: var(--dept-leo); }
.badge-ems       { background: rgba(0,204,102,0.15);  color: var(--dept-ems); }
.badge-fire      { background: rgba(255,102,0,0.15);  color: var(--dept-fire); }
.badge-dispatch  { background: rgba(155,89,182,0.15); color: var(--dept-dispatch); }
.badge-admin     { background: rgba(204,0,0,0.15);    color: var(--dept-admin); }
.badge-swat      { background: rgba(44,62,80,0.3);    color: #7f8c8d; }

/* Priority badges */
.badge-high   { background: rgba(255,32,32,0.2);  color: #ff4444; }
.badge-medium { background: rgba(255,170,0,0.2);  color: #ffaa00; }
.badge-low    { background: rgba(74,85,104,0.2);  color: #8b95a8; }

/* ─── Form Elements ──────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--space-1); }

.form-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.form-input,
.form-select,
.form-textarea {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast);
  width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--border-accent);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b95a8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

.form-select option { background: var(--bg-elevated); }

.form-textarea { resize: vertical; min-height: 80px; }

.form-hint { font-size: 0.6875rem; color: var(--text-muted); }
.form-error { font-size: 0.6875rem; color: var(--status-danger); }

/* ─── Form Card ──────────────────────────────────────────────────── */
.form-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.form-card-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }

/* ─── Detail Panel ───────────────────────────────────────────────── */
.detail-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.detail-panel-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.detail-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.detail-panel-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ─── Vitals Grid ────────────────────────────────────────────────── */
.vitals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

.vital-cell {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
}

.vital-label {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.vital-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.vital-unit { font-size: 0.6875rem; color: var(--text-muted); margin-top: 2px; }

/* ─── Tabs ───────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  overflow-x: auto;
}

.tab-btn {
  padding: var(--space-3) var(--space-5);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-sans);
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--text-primary); border-bottom-color: var(--rlc-red); }

/* ─── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  animation: fadeIn 150ms ease;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 200ms cubic-bezier(0.23, 1, 0.32, 1);
}

.modal-header {
  display: flex;
  align-items: center;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 4px;
  line-height: 1;
  transition: color var(--transition-fast);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
}

.modal-footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
}

/* ─── Toast Notifications ────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--space-5) + var(--safe-area-bottom));
  right: var(--space-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: 0.8125rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  animation: slideInRight 200ms cubic-bezier(0.23, 1, 0.32, 1);
}

.toast.success { border-left: 3px solid var(--status-available); }
.toast.error   { border-left: 3px solid var(--status-danger); }
.toast.warning { border-left: 3px solid var(--status-busy); }
.toast.info    { border-left: 3px solid var(--status-info); }

/* ─── Connection indicator ───────────────────────────────────────── */
#connection-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
}

#connection-indicator.online  { color: var(--status-available); }
#connection-indicator.offline { color: var(--status-danger); }

#connection-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ─── Animations ─────────────────────────────────────────────────── */
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp   { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes pulse     { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
