/* ----------------------------------------------------------------------
 * Theme tokens
 *
 * Light is the default. The `[data-theme="dark"]` selector on <html>
 * flips the page colors while keeping the sidebar dark in both themes
 * (it was always dark in this design).
 *
 * Status/priority badges use their own colors and stay readable on top
 * of either page background — those are not theme-tokenized.
 * ---------------------------------------------------------------------- */
:root {
  --sw: 230px;
  --pr: #2563eb;
  --pr-hover: #1d4ed8;

  /* Page surfaces */
  --bg-page:        #f1f5f9;
  --bg-card:        #fff;
  --bg-card-header: #f8fafc;
  --bg-input:       #fff;

  /* Text */
  --text-strong: #0f172a;
  --text-muted:  #64748b;

  /* Borders / dividers */
  --border-soft: #f1f5f9;

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(0, 0, 0, .07);
}

[data-theme="dark"] {
  --bg-page:        #0b1220;
  --bg-card:        #1e293b;
  --bg-card-header: #0f172a;
  --bg-input:       #0f172a;

  --text-strong: #f1f5f9;
  --text-muted:  #94a3b8;

  --border-soft: #334155;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, .5);
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text-strong);
}

/* Sidebar — stays dark in both themes (it's the design) */
/* ── Sidebar (editorial style — theme-aware via Bootstrap CSS vars) ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sw);
  height: 100vh;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border-right: 1px solid var(--bs-border-color);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  padding: 16px;
  border-bottom: 1px solid var(--bs-border-color);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar .brand-pill {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bs-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar .brand-text {
  min-width: 0;
}

.sidebar .brand-overline {
  text-transform: uppercase;
  font-size: .65rem;
  letter-spacing: .15em;
  color: var(--bs-secondary-color);
  line-height: 1.1;
  margin-bottom: 2px;
}

.sidebar .brand-name {
  font-weight: 600;
  font-size: .9rem;
  color: var(--bs-body-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section {
  padding: 14px 16px 4px;
  font-size: .65rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  letter-spacing: .15em;
  text-transform: uppercase;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--bs-body-color);
  text-decoration: none;
  font-size: .85rem;
  border-left: 3px solid transparent;
  transition: background-color .12s, color .12s;
}

.sidebar a:hover {
  background: var(--bs-tertiary-bg);
}

.sidebar a.active {
  background: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
  border-left-color: var(--bs-primary);
  font-weight: 600;
}

.sidebar a i {
  font-size: 1rem;
  width: 18px;
  flex-shrink: 0;
}

/* Main content */
.main {
  margin-left: var(--sw);
  padding: 24px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.topbar h4 {
  margin: 0;
  font-weight: 700;
  color: var(--text-strong);
}

.topbar .date {
  color: var(--text-muted);
  font-size: .85rem;
}

/* Cards */
.stat-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.stat-card .icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.stat-card h3 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 8px 0 2px;
  color: var(--text-strong);
}

.stat-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: .8rem;
}

/* Tables */
.table-card {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-top: 20px;
}

.table-card .card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-card .card-header h6 {
  margin: 0;
  font-weight: 700;
  color: var(--text-strong);
}

.table th {
  font-size: .78rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-color: var(--border-soft) !important;
  background: var(--bg-card-header);
}

.table td {
  font-size: .87rem;
  vertical-align: middle;
  border-color: var(--border-soft) !important;
}

/* Status badges */
.badge-status,
.badge-priority {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  display: inline-block;
}

.status-new-order { background: #f0fdf4; color: #166534; }
.status-give-estimate { background: #fef3c7; color: #b45309; }
.status-waiting-for-approval { background: #fef9c3; color: #a16207; }
.status-order-part { background: #ede9fe; color: #6d28d9; }
.status-waiting-for-part { background: #fce7f3; color: #be185d; }
.status-waiting-for-repair { background: #ffedd5; color: #c2410c; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-in-progress { background: #dbeafe; color: #1e40af; }
.status-waiting-for-delivery { background: #e0f2fe; color: #0369a1; }
.status-ready { background: #d1fae5; color: #065f46; }
.status-complete { background: #bbf7d0; color: #14532d; }
.status-delivered { background: #e0e7ff; color: #3730a3; }
.status-cancelled { background: #fee2e2; color: #991b1b; }
.status-draft { background: #f1f5f9; color: #475569; }
.status-sent { background: #dbeafe; color: #1e40af; }
.status-approved { background: #d1fae5; color: #065f46; }
.status-rejected { background: #fee2e2; color: #991b1b; }
.status-expired { background: #fef3c7; color: #92400e; }
.status-converted { background: #e0e7ff; color: #3730a3; }
.status-received { background: #d1fae5; color: #065f46; }

/* Priority badges */
.priority-high { background: #fee2e2; color: #991b1b; }
.priority-normal { background: #f0fdf4; color: #166534; }
.priority-low { background: #f8fafc; color: #475569; }

/* Forms */
.btn-primary { background: var(--pr); border-color: var(--pr); }
.btn-primary:hover { background: var(--pr-hover); border-color: var(--pr-hover); }
.form-control:focus,
.form-select:focus { border-color: var(--pr); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }

/* Flash messages */
.flash-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  min-width: 280px;
}

/* User footer in sidebar — theme-aware */
.sidebar-user {
  border-top: 1px solid var(--bs-border-color);
  padding: 12px 16px;
}

.sidebar-user .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}

.sidebar-user .name {
  color: var(--bs-body-color);
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .role {
  color: var(--bs-secondary-color);
  font-size: .7rem;
}

/* Theme toggle button (in sidebar footer above Sign Out) */
.sidebar-theme-toggle {
  background: transparent;
  border: 0;
  color: #94a3b8;
  font-size: .8rem;
  text-decoration: none;
  padding: 5px 8px !important;
  border-radius: 6px;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.sidebar-theme-toggle:hover {
  background: #1e3a5f;
  color: #fff;
}

/* Print */
@media print {
  .sidebar, .topbar, .no-print, .flash-container { display: none !important; }
  .main { margin-left: 0 !important; padding: 0 !important; }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .3s; }
  .sidebar.show { transform: translateX(0); }
  .main { margin-left: 0; padding: 16px; }
}

/* Turbo progress bar */
.turbo-progress-bar {
  background: var(--pr);
  height: 3px;
}

/* Calendar live-van dot: gentle pulse when the van is on the road */
@keyframes pulse-dot {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.4); opacity: 0.65; }
}

/* WO form "Advanced fields" disclosure block — native <details> styled
   as a Bootstrap button. Hides the default browser triangle marker
   (varies by engine) and replaces it with a chevron that rotates on
   open. Purely cosmetic; the form-disclosure Stimulus controller
   drives the open/close logic. */
.wo-advanced__summary { list-style: none; cursor: pointer; }
.wo-advanced__summary::-webkit-details-marker { display: none; }
.wo-advanced__summary::marker { display: none; content: ""; }
.wo-advanced__chevron { transition: transform .15s ease; }
.wo-advanced[open] .wo-advanced__chevron { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) {
  .wo-advanced__chevron { transition: none; }
}

/* ─── Command palette (Cmd+K) ───────────────────────────────────────
   Mounted once in the layout. Hidden by default; .is-open flips it.
   Sits above Bootstrap modals (z-index 1055) at 1080. Uses Bootstrap
   CSS variables so dark mode tracks automatically. */
.cmdk { position: fixed; inset: 0; z-index: 1080; display: none; }
.cmdk.is-open { display: block; }
.cmdk-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
.cmdk-dialog {
  position: relative;
  width: min(640px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  margin: 10vh auto 0;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column;
  overflow: hidden;
  outline: none;
}
.cmdk-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bs-border-color);
}
.cmdk-icon { font-size: 1.1rem; color: var(--bs-secondary-color); }
.cmdk-input {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--bs-body-color); font-size: 1rem;
}
.cmdk-kbd {
  font-size: 0.7rem; padding: 2px 6px;
  border-radius: 4px;
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  color: var(--bs-secondary-color);
}
.cmdk-list {
  list-style: none; margin: 0; padding: 4px 0;
  overflow-y: auto; flex: 1; min-height: 0;
}
.cmdk-group {
  padding: 10px 16px 4px;
  font-size: 0.7rem; letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}
.cmdk-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
  min-height: 40px;
}
.cmdk-item.is-active {
  background: var(--bs-tertiary-bg);
  border-left-color: var(--bs-primary);
}
.cmdk-item .bi { color: var(--bs-secondary-color); }
.cmdk-item.is-active .bi { color: var(--bs-primary); }
.cmdk-title { flex: 0 1 auto; font-weight: 500; }
.cmdk-meta {
  flex: 1; margin-left: 8px;
  color: var(--bs-secondary-color); font-size: 0.85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmdk-go {
  font-size: 0.7rem; padding: 2px 6px;
  border-radius: 4px;
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  color: var(--bs-secondary-color);
  opacity: 0; transition: opacity .1s ease;
}
.cmdk-item.is-active .cmdk-go { opacity: 1; }
.cmdk-empty {
  padding: 20px 16px;
  color: var(--bs-secondary-color);
  text-align: center;
}
.cmdk-hint {
  display: flex; gap: 14px; align-items: center;
  padding: 8px 16px;
  border-top: 1px solid var(--bs-border-color);
  font-size: 0.75rem; color: var(--bs-secondary-color);
  background: var(--bs-tertiary-bg);
}
.cmdk-hint kbd {
  display: inline-block; padding: 0 5px; margin-right: 3px;
  border-radius: 3px;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  color: var(--bs-body-color);
}
.cmdk-status { margin-left: auto; }
body.cmdk-lock { overflow: hidden; }

@media (max-width: 640px) {
  .cmdk-dialog { width: calc(100vw - 16px); margin: 6vh auto 0; }
  .cmdk-meta { display: none; }  /* keep titles readable on narrow screens */
}
