:root {
  --navy: #0f1e36;
  --navy-700: #16294a;
  --navy-600: #1f3a63;
  --sidebar-bg: #3d5270;
  --sidebar-accent: #7eb0dc;
  --sidebar-accent-muted: #6a9bc8;
  --primary: #6a9bc8;
  --primary-600: #5a8ab8;
  --accent: #0d9488;
  --accent-600: #0f766e;
  --warning: #d97706;
  --danger: #dc2626;
  --success: #059669;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e6eaf1;
  --sidebar-w: 256px;
  --topbar-h: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15,30,54,.06);
  --shadow: 0 4px 16px rgba(15,30,54,.08);
  --shadow-lg: 0 12px 32px rgba(15,30,54,.16);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
svg { width: 20px; height: 20px; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ============ APP SHELL ============ */
.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #dbe7f3;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  overflow: hidden;
}
.site-logo-link {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  max-width: 100%;
  overflow: hidden;
}
.site-logo {
  display: block;
  object-fit: contain;
  object-position: left center;
}
.site-logo-sidebar {
  height: 36px;
  width: auto;
  max-width: 100%;
  aspect-ratio: 644 / 200;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--sidebar-accent);
  color: #fff;
  font-weight: 800;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
}
.brand-text { display: flex; flex-direction: column; font-weight: 700; color: #fff; letter-spacing: .02em; }
.brand-text small { font-weight: 500; font-size: .7rem; color: #a8bdd4; letter-spacing: .08em; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: 1rem .75rem; overflow-y: auto; }
.sidebar-section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #8fa8c4;
  padding: 1.25rem .75rem .5rem;
  font-weight: 600;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .7rem .85rem;
  margin-bottom: .15rem;
  border-radius: var(--radius-sm);
  color: #dbe7f3;
  font-weight: 500;
  font-size: .92rem;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: rgba(126, 176, 220, .2); color: #fff; box-shadow: inset 3px 0 0 var(--sidebar-accent); }
.sidebar-nav a svg { width: 19px; height: 19px; }
.sidebar-footer { padding: 1rem 1.25rem; font-size: .75rem; color: #8fa8c4; border-top: 1px solid rgba(255,255,255,.08); }

.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(61, 82, 112, .45);
  z-index: 55;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s;
}
.sidebar.open { transform: translateX(0); }
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

.app-main { display: flex; flex-direction: column; min-height: 100vh; }

/* ============ TOPBAR ============ */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  z-index: 50;
}
.topbar-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: none; background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: #eef1f7; }

/* ============ PROFILE MENU ============ */
.profile-menu { position: relative; }
.profile-trigger {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .3rem .5rem .3rem .35rem;
  cursor: pointer;
  font: inherit;
}
.profile-trigger:hover { background: #eef1f7; }
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--sidebar-accent-muted);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  display: grid; place-items: center;
}
.profile-info { display: none; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.profile-name { font-weight: 600; font-size: .88rem; color: var(--text); }
.profile-role { font-size: .72rem; color: var(--muted); }
.chevron { width: 16px; height: 16px; color: var(--muted); display: none; }

.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 240px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .4rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .15s, transform .15s;
}
.profile-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0); }
.profile-dropdown-head { padding: .65rem .75rem; border-bottom: 1px solid var(--line); margin-bottom: .35rem; display: flex; flex-direction: column; }
.profile-dropdown-head .profile-email { font-size: .78rem; color: var(--muted); }
.profile-dropdown a, .dropdown-logout {
  display: block;
  width: 100%;
  text-align: left;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .9rem;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
}
.profile-dropdown a:hover, .dropdown-logout:hover { background: #f1f4f9; text-decoration: none; }
.dropdown-logout { color: var(--danger); border-top: 1px solid var(--line); margin-top: .35rem; }

/* ============ CONTENT ============ */
.content { flex: 1; padding: 1.25rem; width: 100%; }

@media (min-width: 1024px) {
  .sidebar { transform: translateX(0); }
  .sidebar-backdrop { display: none; }
  .app-main { margin-left: var(--sidebar-w); }
  .menu-btn { display: none; }
  .content { padding: 2rem; }
  .profile-info { display: flex; }
  .chevron { display: block; }
}

/* ============ AUTH PAGES ============ */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at top left, var(--navy-600), var(--navy) 55%, #0a1422); padding: 1rem; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card { background: var(--card); border-radius: 18px; padding: 2rem 2.25rem; box-shadow: 0 20px 48px rgba(10,20,34,.35), 0 0 0 1px rgba(255,255,255,.06); }
.auth-brand {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.site-logo-auth {
  width: 100%;
  max-width: 220px;
  height: auto;
  aspect-ratio: 644 / 200;
  object-fit: contain;
}
.auth-card .form label { color: var(--muted); }
.auth-links { text-align: center; margin-top: 1rem; font-size: .88rem; color: var(--muted); }

/* ============ HEADINGS / PAGE HEADER ============ */
h1 { font-size: 1.4rem; margin: 0 0 1.25rem; font-weight: 700; }
.content > h1:first-child, .page-header { margin-top: 0; }
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0; }
.page-header > .btn:only-child, .page-header > a:only-child { margin-left: auto; }
.page-header-job { align-items: flex-start; }
.page-header-job .page-header-main { flex: 1; min-width: 0; }
.page-header-job .page-header-end {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
  flex-shrink: 0;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 38px; padding: .5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .05s;
  text-decoration: none; font-family: inherit; letter-spacing: .01em;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(106,155,200,.35); }
.btn-primary:hover { background: var(--primary-600); box-shadow: 0 2px 6px rgba(106,155,200,.4); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn-secondary:hover { background: #f1f4f9; border-color: #c8d4e8; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { min-height: 32px; padding: .32rem .8rem; font-size: .82rem; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; padding: .5rem; font-family: inherit; }

/* ============ FORMS ============ */
.form label {
  display: block;
  margin-bottom: .7rem;
  font-weight: 600;
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .055em;
}
.form input, .form select, .form textarea {
  width: 100%; margin-top: .25rem;
  padding: .5rem .75rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: .9rem; min-height: 38px;
  background: #f8fafd; color: var(--text);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.form input:hover, .form select:hover, .form textarea:hover {
  border-color: #c8d4e8;
}
.form input:focus, .form textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(106, 155, 200, .18);
}
.form label.has-error input,
.form label.has-error select,
.form label.has-error textarea {
  border-color: #dc2626;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}
.field-error {
  display: block;
  margin-top: .35rem;
  font-size: .8rem;
  font-weight: 500;
  color: #991b1b;
  text-transform: none;
  letter-spacing: normal;
}
.form select:focus {
  outline: none;
  border-color: var(--primary);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(106, 155, 200, .18);
}
.form input::placeholder, .form textarea::placeholder { color: #b0bccf; font-weight: 400; }
.form textarea { min-height: 88px; resize: vertical; }
.form select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.2rem;
  cursor: pointer;
  background-image: none;
}
.form label:has(> select) { position: relative; }
.form label:has(> select)::after {
  content: '';
  position: absolute;
  right: .75rem;
  bottom: 13px;
  width: 12px;
  height: 12px;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat center / contain;
}
.form label:has(> select:focus)::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236a9bc8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .88rem; margin-bottom: .6rem; text-transform: none; letter-spacing: 0; }
.checkbox input { width: 15px; height: 15px; min-height: auto; margin: 0; accent-color: var(--primary); cursor: pointer; }
.checkbox-group { margin-bottom: 1rem; }
.checkbox-group.full { grid-column: 1 / -1; }
.checkbox-group-label {
  display: block;
  font-weight: 600;
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .055em;
  margin-bottom: .35rem;
}
.checkbox-group-help { margin: 0 0 .65rem; font-size: .85rem; color: var(--muted); }
.checkbox-group .checkbox { margin-bottom: .45rem; }

.customer-picker { position: relative; z-index: 5; margin-bottom: 1rem; }
.customer-picker-pills {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  min-height: .25rem;
  margin-bottom: .65rem;
}
.customer-pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  max-width: 100%;
  padding: .28rem .45rem .28rem .65rem;
  border-radius: 999px;
  background: #eef4fb;
  border: 1px solid #c8d9ec;
  color: var(--text);
  font-size: .82rem;
  font-weight: 500;
}
.customer-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.customer-pill-remove {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.customer-pill-remove:hover {
  background: rgba(15, 30, 54, .08);
  color: var(--danger);
}
.customer-picker-input-wrap { position: relative; z-index: 2; }
.customer-picker-search {
  width: 100%;
  margin-top: 0;
  padding: .5rem .75rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  min-height: 38px;
  background: #f8fafd;
  color: var(--text);
  font-family: inherit;
}
.customer-picker-search:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(106, 155, 200, .18);
}
.customer-picker-dropdown {
  position: absolute;
  top: calc(100% + .35rem);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding: .35rem 0;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.customer-picker-dropdown.customer-picker-dropdown--floating {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  z-index: 1000;
  max-height: min(280px, calc(100vh - 1rem));
}
.customer-picker-option,
.customer-picker-empty {
  padding: .55rem .85rem;
  font-size: .88rem;
  color: var(--text);
}
.customer-picker-option {
  cursor: pointer;
}
.customer-picker-option:hover,
.customer-picker-option.is-active {
  background: #eef4fb;
}
.customer-picker-empty {
  color: var(--muted);
}

.picker-option-name { display: block; font-weight: 600; }
.picker-option-meta { display: block; font-size: .78rem; color: var(--muted); margin-top: .12rem; word-break: break-word; }

@media (max-width: 899px) {
  .customer-picker {
    z-index: 30;
    position: relative;
  }
  .customer-picker-input-wrap {
    overflow: visible;
  }
  .customer-picker-dropdown:not(.customer-picker-dropdown--floating) {
    z-index: 200;
    max-height: min(50vh, 280px);
    -webkit-overflow-scrolling: touch;
  }
  .customer-picker-option {
    line-height: 1.35;
    word-break: break-word;
  }
}

.form-grid { display: grid; gap: 0 1rem; }
.form-grid .form-grid-checkbox { align-self: end; margin-bottom: .7rem; min-height: 38px; }
.form-grid .full { grid-column: 1 / -1; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-actions, .sticky-actions { margin-top: 1rem; display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; position: relative; z-index: 1; }
.form-actions.full, .sticky-actions.full { grid-column: 1 / -1; }
.form-actions-end { margin-left: auto; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: .85rem 0; }

/* ============ ALERTS (inline, legacy) ============ */
.alert { padding: .8rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; font-size: .92rem; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ============ TOAST NOTIFICATIONS ============ */
.notifications {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: .75rem;
  max-width: min(360px, calc(100vw - 2.5rem));
  pointer-events: none;
}
.notification {
  pointer-events: auto;
  padding: .85rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-weight: 500;
  border: 1px solid transparent;
  box-shadow: var(--shadow-lg);
  transform: translateY(calc(100% + 1.25rem));
  opacity: 0;
  transition: transform .35s ease, opacity .35s ease;
}
.notification.is-visible {
  transform: translateY(0);
  opacity: 1;
}
.notification.is-leaving {
  transform: translateY(calc(100% + 1.25rem));
  opacity: 0;
}
.notification-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.notification-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ============ STAT CARDS ============ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--card); padding: 1.4rem; border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.stat-card.highlight { border-left: 3px solid var(--warning); }
.stat-value { display: block; font-size: 2.1rem; font-weight: 800; color: var(--navy); letter-spacing: -.02em; }
.stat-label { font-size: .82rem; color: var(--muted); font-weight: 500; }

/* ============ JOB CARDS ============ */
.job-cards { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .job-cards {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}
.job-card { display: block; background: var(--card); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow-sm); border: 1px solid var(--line); border-left: 3px solid transparent; transition: box-shadow .15s, transform .1s; text-decoration: none; color: inherit; cursor: pointer; }
.job-card:hover, .job-card:focus-visible { box-shadow: var(--shadow); transform: translateY(-2px); text-decoration: none; }
.job-card:hover .job-title { color: var(--primary); }
.job-card.customer-updated { border-left-color: var(--warning); }
.job-card.priority-urgent { border-left-color: var(--danger); }
.job-card.priority-high { border-left-color: var(--warning); }
.job-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .55rem; }
.job-number { font-weight: 600; font-size: .78rem; color: var(--muted); letter-spacing: .02em; }
.job-title { margin: 0 0 .5rem; font-size: 1.05rem; color: var(--text); transition: color .15s; }
.job-meta { font-size: .85rem; color: var(--muted); margin: 0 0 .75rem; }
.job-card-footer { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .78rem; color: var(--muted); }
.job-card-footer time { margin-left: auto; }

/* ============ BADGES ============ */
.badge { display: inline-flex; align-items: center; padding: .25rem .6rem; border-radius: 999px; font-size: .73rem; font-weight: 600; background: #eef1f7; color: #475569; }
.priority-urgent { background: #fee2e2; color: #991b1b; }
.priority-high { background: #ffedd5; color: #9a3412; }
.priority-normal { background: #e0edff; color: #1e40af; }
.priority-low { background: #f1f5f9; color: var(--muted); }
.status-new { background: #dbeafe; color: #1e40af; }
.status-assigned { background: #e0f2fe; color: #0369a1; }
.status-in-progress { background: #e0e7ff; color: #3730a3; }
.status-scheduled { background: #ede9fe; color: #5b21b6; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-waiting-on-customer, .status-waiting-on-parts { background: #fef3c7; color: #92400e; }
.status-cancelled, .status-archived { background: #f1f5f9; color: var(--muted); }

/* ============ DASHBOARD STATUS PILLS ============ */
.status-filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1.25rem;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .85rem;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.status-pill:hover { border-color: var(--primary); }
.status-pill.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(106, 155, 200, .2);
}
.status-pill .pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  padding: .1rem .4rem;
  border-radius: 999px;
  background: rgba(15, 30, 54, .08);
  font-size: .72rem;
  font-weight: 700;
}
.status-pill.is-active .pill-count { background: rgba(106, 155, 200, .25); }
.dashboard-status-section .job-card-slot { display: contents; }
.dashboard-status-section .job-card-slot.is-hidden { display: none; }
.dashboard-status-more { margin: .75rem 0 0; font-size: .9rem; }

/* ============ FILTERS ============ */
.filters-form { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; background: var(--card); padding: .75rem; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.filters-form input, .filters-form select {
  flex: 1 1 140px; min-height: 36px; padding: .42rem .7rem;
  border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  font-size: .88rem; background: #f8fafd; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.filters-form input:focus, .filters-form select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(106,155,200,.18); background: #fff;
}
.filters-form select {
  appearance: auto;
  -webkit-appearance: menulist;
  padding-right: .7rem;
  cursor: pointer;
  background-image: none;
}

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th, .data-table td { padding: .85rem 1rem; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { background: #f8fafc; font-weight: 600; color: #475569; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table .table-actions { text-align: right; width: 1%; white-space: nowrap; }
a.icon-btn.table-action-btn { text-decoration: none; color: var(--muted); }
a.icon-btn.table-action-btn:hover { color: var(--text); }
a.icon-btn.table-action-btn svg { width: 18px; height: 18px; }
.table-action-group { display: inline-flex; align-items: center; gap: .15rem; }
.inline-form { display: inline; margin: 0; }
button.icon-btn.table-action-btn { padding: 0; font: inherit; }
.table-action-danger { color: var(--muted); }
.table-action-danger:hover { color: var(--danger); background: #fef2f2; }
.page-intro { margin: 0 0 1.25rem; color: var(--muted); font-size: .92rem; }
.row-highlight { background: #fffbeb; }
.row-highlight:hover { background: #fef3c7 !important; }

@media (max-width: 899px) {
  .filters-form { flex-direction: column; align-items: stretch; }
  .filters-form input,
  .filters-form select,
  .filters-form .btn { flex: 1 1 auto; width: 100%; min-width: 0; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn { width: 100%; }
  .page-header-job .page-header-end { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .page-header-job .page-header-end .btn { width: 100%; }

  /* Tables collapse into stacked cards */
  .table-wrap {
    overflow: visible;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }
  .data-table { font-size: .92rem; }
  .data-table thead { display: none; }
  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td { display: block; width: 100%; }
  .data-table tbody tr {
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }
  .data-table tbody tr:last-child { margin-bottom: 0; }
  .data-table tbody tr:hover { background: var(--card); }
  .data-table tbody tr.row-highlight { background: #fffbeb; border-left: 3px solid var(--warning); }

  .data-table td {
    display: grid;
    grid-template-columns: 38% 1fr;
    gap: .15rem 1rem;
    align-items: baseline;
    padding: .6rem 1rem;
    border: none;
    border-bottom: 1px solid var(--line);
    text-align: left;
    word-break: break-word;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .7rem;
    line-height: 1.5;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
  }

  /* Primary cell becomes the card title bar */
  .data-table td.cell-primary {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    padding: .85rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
  }
  .data-table td.cell-primary::before { display: none; }
  .data-table td.cell-primary a { color: var(--primary); }

  /* Action cell becomes a footer row with comfortable tap targets */
  .data-table td.table-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: .5rem;
    padding: .65rem 1rem;
    background: #fbfcfe;
    border-top: 1px solid var(--line);
    border-bottom: none;
  }
  .data-table td.table-actions:empty { display: none; }
  .data-table td.table-actions::before { display: none; }
  .data-table td.table-actions .table-action-group {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
  }
  .data-table td.table-actions .icon-btn.table-action-btn {
    width: auto;
    min-width: 40px;
    height: 40px;
    display: inline-grid;
    grid-auto-flow: column;
    place-items: center;
    gap: .35rem;
    padding: 0 .75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font-size: .82rem;
    font-weight: 600;
  }
  .data-table td.table-actions .icon-btn.table-action-btn::after {
    content: attr(aria-label);
  }
  .data-table td.table-actions .table-action-danger {
    color: var(--danger);
  }

  .customer-list-table td:not(.cell-primary):not(.table-actions):not([data-label="Status"]) {
    display: none;
  }
  .customer-list-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
  }
  .customer-list-table td.cell-primary {
    grid-column: 1 / -1;
  }
  .customer-list-table td[data-label="Status"] {
    grid-column: 1;
    display: flex;
    align-items: center;
    padding: .65rem 1rem;
    background: #fbfcfe;
    border-top: 1px solid var(--line);
    border-bottom: none;
  }
  .customer-list-table td[data-label="Status"]::before {
    display: none;
  }
  .customer-list-table td.table-actions {
    grid-column: 2;
    border-top: 1px solid var(--line);
    padding-left: 0;
  }
  .customer-list-table td.table-actions .table-action-group {
    flex-wrap: nowrap;
    align-items: center;
  }
  .customer-list-table td.table-actions .inline-form {
    display: inline-flex;
  }
  .customer-list-table td.table-actions .icon-btn.table-action-btn {
    width: 40px;
    min-width: 40px;
    padding: 0;
  }
  .customer-list-table td.table-actions .icon-btn.table-action-btn::after {
    content: none;
  }
}

@media (max-width: 479px) {
  .content { padding: 1rem; }
  .action-bar .btn { flex: 1 1 100%; }
  .data-table td { grid-template-columns: 42% 1fr; }
}

/* ============ DETAIL PAGE ============ */
.detail-grid { display: grid; gap: 1.25rem; }
@media (min-width: 768px) { .detail-grid { grid-template-columns: 3fr 1fr; } }

.job-layout { display: grid; gap: 1.25rem; align-items: start; }
@media (min-width: 768px) {
  .job-layout { grid-template-columns: 3fr 1fr; }
}
.job-layout-main,
.job-layout-sidebar { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.job-layout-sidebar .detail-list {
  grid-template-columns: 1fr;
  gap: .15rem 0;
}
.job-layout-sidebar .detail-list dt {
  margin-top: .65rem;
}
.job-layout-sidebar .detail-list dt:first-child { margin-top: 0; }
.job-layout-sidebar .detail-list dd { margin: 0; }
.job-sidebar-form label { display: block; margin-bottom: .65rem; }
.job-sidebar-form select,
.job-sidebar-form input[type="file"] {
  width: 100%;
  min-height: 38px;
  padding: .45rem .7rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  background-color: #f8fafd;
  font-family: inherit;
}
.job-sidebar-form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(106, 155, 200, .18);
  background-color: #fff;
}
.detail-panel { background: var(--card); padding: 1.4rem; border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.detail-panel h2 { font-size: 1.05rem; margin: 0 0 1rem; }
.detail-panel h3 { font-size: .95rem; margin: 1.25rem 0 .4rem; }
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1.25rem; margin: 0 0 1rem; font-size: .9rem; }
.detail-list dt { color: var(--muted); font-weight: 500; }
.description { white-space: pre-wrap; }

.comments-section { margin-top: 0; }
.comments .comment { background: var(--card); padding: 1.1rem; border-radius: var(--radius); margin-bottom: .85rem; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.comments .comment.internal { border-left: 3px solid var(--navy-600); background: #fafbff; }
.comment-meta { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; display: flex; gap: .6rem; align-items: center; }
.comment-meta time { margin-left: auto; }
.activity-log { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.activity-log li { padding: .65rem 0; border-bottom: 1px solid var(--line); color: #475569; }
.activity-log time { color: var(--muted); font-size: .78rem; display: inline-block; margin-right: .5rem; }

.grid-2 { display: grid; gap: 1.25rem; }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1.1rem; margin: 0 0 1rem; }
.card-form { background: var(--card); padding: 1.25rem; border-radius: var(--radius); margin-bottom: 1.5rem; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.card-form h2 { font-size: 1rem; margin: 0 0 .9rem; font-weight: 700; color: var(--navy); }
.empty { color: var(--muted); padding: 2rem; text-align: center; background: var(--card); border-radius: var(--radius); border: 1px dashed var(--line); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: .4rem 0; }
.inline-form-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.inline-form-row select {
  flex: 1; min-height: 38px; padding: .45rem .7rem;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  font-size: .9rem; background-color: #f8fafd; font-family: inherit;
  appearance: auto;
  -webkit-appearance: menulist;
  background-image: none;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.inline-form-row select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(106,155,200,.18); background-color: #fff; }
.action-bar { display: flex; flex-wrap: wrap; gap: .75rem; }
.job-header-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: .25rem;
}
.job-number-lg { font-size: .85rem; color: var(--muted); font-weight: 600; }

@media (min-width: 480px) { .profile-info { display: flex; } }

/* ============ APP MODAL (desktop) ============ */
@media (min-width: 1024px) {
  body.job-form-standalone .content {
    position: fixed;
    left: var(--sidebar-w);
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    z-index: 70;
    margin: 0;
    padding: 1.5rem;
    background: rgba(15, 30, 54, .42);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
  }
  body.job-form-standalone .job-form-page {
    width: 100%;
    max-width: 720px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem 1.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--line);
    margin: auto 0;
  }
  body.job-form-standalone .sticky-actions {
    position: static;
    background: none;
    padding-bottom: 0;
  }

  .app-modal[hidden] { display: none !important; }
  .app-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1.5rem;
    overflow-y: auto;
  }
  .app-modal.is-open { display: flex; }
  .app-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 30, 54, .45);
    backdrop-filter: blur(2px);
  }
  .app-modal-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 720px;
    margin: auto 0;
    animation: app-modal-in .2s ease;
  }
  @keyframes app-modal-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .app-modal-panel {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--line);
    overflow: hidden;
  }
  .app-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
  }
  .app-modal-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--navy);
  }
  .app-modal-close-btn {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
  }
  .app-modal-close-btn:hover { background: #eef1f7; color: var(--text); }
  .app-modal-close-btn svg { width: 20px; height: 20px; }
  .app-modal-body {
    padding: 1.25rem 1.5rem 1.5rem;
    max-height: calc(100vh - var(--topbar-h) - 5rem);
    overflow-y: auto;
  }
  .app-modal-body .sticky-actions {
    position: static;
    background: none;
    padding-bottom: 0;
  }
  body.app-modal-open { overflow: hidden; }

  .confirm-modal[hidden] { display: none !important; }
  .confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
  }
  .confirm-modal.is-open { display: flex; }
  .confirm-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 30, 54, .55);
  }
  .confirm-modal-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--line);
    animation: app-modal-in .2s ease;
  }
  .confirm-modal-title {
    margin: 0 0 .65rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--navy);
  }
  .confirm-modal-message {
    margin: 0 0 1.25rem;
    font-size: .92rem;
    color: var(--muted);
    line-height: 1.5;
  }
  .confirm-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    justify-content: flex-end;
  }
}

.text-muted-sm { font-size: .78rem; color: var(--muted); font-weight: 500; }
