/* =====================================================================
   Lift Maintenance CRM - UI stylesheet
   ===================================================================== */
:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-600: #1e40af;
  --primary-50: #eff4ff;
  --sidebar: #0f1d3a;
  --sidebar-text: #c4cde0;
  --sidebar-active: #1d4ed8;
  --green: #15803d;   --green-bg: #e7f6ec;
  --amber: #b45309;   --amber-bg: #fdf3e1;
  --red: #b91c1c;     --red-bg: #fdeaea;
  --blue: #1d4ed8;    --blue-bg: #e8effe;
  --purple: #6d28d9;  --purple-bg: #f0eafe;
  --gray: #475569;    --gray-bg: #eef1f5;
  --orange: #c2410c;  --orange-bg: #fdeee5;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-lg: 0 20px 45px rgba(15, 23, 42, .18);
  --sidebar-w: 248px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i-sm { width: 15px; height: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  position: fixed; inset: 0 auto 0 0;
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: #fff; font-weight: 700; font-size: 16px; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--sidebar-text); letter-spacing: .02em; }
.nav { padding: 8px 12px; overflow-y: auto; flex: 1; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7d8aa5; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; margin: 2px 0;
  border-radius: 8px; color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav .count { margin-left: auto; background: rgba(255,255,255,.14); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12.5px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar .title { font-weight: 600; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.backdrop { display: none; }

.tracking-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 99px; background: var(--gray-bg); color: var(--gray); cursor: pointer; border: 0;
}
.tracking-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.tracking-pill.on { background: var(--green-bg); color: var(--green); }
.tracking-pill.on .dot { animation: pulse 1.6s infinite; }
.tracking-pill.err { background: var(--red-bg); color: var(--red); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(21,128,61,.5);} 70% { box-shadow: 0 0 0 7px rgba(21,128,61,0);} 100% { box-shadow: 0 0 0 0 rgba(21,128,61,0);} }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 14.5px; font-weight: 600; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: block; color: inherit; }
a.stat:hover { text-decoration: none; border-color: #c7d2e6; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.warn .value { color: var(--amber); }
.stat.danger .value { color: var(--red); }
.stat.good .value { color: var(--green); }

/* Detail definition list */
.dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.dl > div { min-width: 0; }
.dl dt { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 2px; }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.dl .full { grid-column: 1 / -1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #166534; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: #f5c2c2; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 46px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; display: inline-grid; place-items: center; cursor: pointer; color: inherit; }
.icon-btn:hover { background: var(--surface-2); }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--gray-bg); color: var(--gray); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.col-full { grid-column: 1 / -1; }
.field label, .label { font-size: 12.5px; font-weight: 600; color: #334155; }
.field label .req { color: var(--red); }
.field .help { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--red); display: none; }
.field.has-error .error { display: block; }
.field.has-error .input { border-color: #ef8f8f; }
.form-section { grid-column: 1 / -1; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--primary); padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.input {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid #cfd7e3; border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font: inherit; font-size: 14px;
}
textarea.input { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; }
select.input { padding-right: 28px; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
.input[readonly] { background: var(--surface-2); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }

/* Checklist (report form) */
.checklist { display: grid; gap: 8px; grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.check-row .name { font-weight: 500; }
.seg { display: inline-flex; border: 1px solid #cfd7e3; border-radius: 7px; overflow: hidden; flex: none; }
.seg label { padding: 5px 10px; font-size: 12px; font-weight: 600; cursor: pointer; background: #fff; color: var(--muted); border-left: 1px solid #cfd7e3; }
.seg label:first-of-type { border-left: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: inherit; }
.seg label:has(input:checked) { color: #fff; }
.seg label.ok:has(input:checked) { background: var(--green); }
.seg label.attention:has(input:checked) { background: var(--red); }
.seg label.na:has(input:checked) { background: var(--gray); }

/* ---------- Toolbar & tables ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .search { position: relative; flex: 1 1 240px; max-width: 360px; }
.toolbar .search svg { position: absolute; left: 10px; top: 10px; color: var(--muted); }
.toolbar .search .input { padding-left: 34px; }
.toolbar select.input, .toolbar input[type=date].input { width: auto; min-width: 140px; flex: 0 1 auto; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: #f7f9fd; }
.table .actions { text-align: right; white-space: nowrap; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 6px; }

/* Simple list rows (dashboards) */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { min-width: 0; flex: 1; }
.list a.row-link { color: inherit; display: block; }
.list a.row-link:hover { text-decoration: none; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 12px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { font-size: 11px; background: var(--gray-bg); border-radius: 99px; padding: 1px 6px; margin-left: 4px; }

/* Job cards (technician) */
.job-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.job-card + .job-card { margin-top: 12px; }
.job-card.in_progress { border-left: 4px solid var(--purple); }
.job-card.urgent { border-left: 4px solid var(--red); }
.job-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.job-card h4 { font-size: 15px; }
.job-card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.job-card .meta span { display: inline-flex; align-items: center; gap: 5px; }
.job-card .btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* Bars */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar span.fill { width: 100%; max-width: 44px; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 3px; }
.bars .bar .v { font-size: 12px; font-weight: 600; }
.bars .bar .m { font-size: 11.5px; color: var(--muted); }

/* Map */
.map { height: 560px; border-radius: 0 0 var(--radius) var(--radius); z-index: 1; }
.map.small { height: 300px; border-radius: var(--radius-sm); }
.map-side { max-height: 560px; overflow-y: auto; }
.leaflet-popup-content { font-family: var(--font); font-size: 13px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--primary); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: rise .18s; }
.modal-lg { max-width: 820px; }
.modal-xl { max-width: 1040px; }
.modal-sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.pdf-frame { width: 100%; height: 72vh; border: 1px solid var(--border); border-radius: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: var(--shadow-lg); font-weight: 500; animation: rise .2s; max-width: 420px; }
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }

.spinner { width: 26px; height: 26px; border: 3px solid #d6deeb; border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
.loading { display: grid; place-items: center; padding: 60px; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.alert.info { background: var(--blue-bg); color: #1e3a8a; }
.alert.warn { background: var(--amber-bg); color: #78350f; }
.alert.error { background: var(--red-bg); color: #7f1d1d; }
.alert.success { background: var(--green-bg); color: #14532d; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: linear-gradient(150deg, #0f1d3a 0%, #1e3a8a 100%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-hero h1 { font-size: 34px; line-height: 1.2; margin: 18px 0 14px; }
.auth-hero p { color: #c4cde0; font-size: 15px; max-width: 460px; }
.auth-hero ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; color: #dbe3f3; }
.auth-hero li { display: flex; gap: 10px; align-items: center; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 23px; margin-bottom: 6px; }
.auth-card form { display: grid; gap: 14px; margin-top: 22px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 35; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .map { height: 420px; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .form-grid, .dl { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 22px; }
  .page-head h1 { font-size: 19px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .toolbar select.input, .toolbar input[type=date].input { flex: 1 1 45%; min-width: 0; }
  /* Tables collapse into cards */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); font-size: 12px; color: var(--muted); font-weight: 500; text-align: left; flex: none; }
  .table td.primary { display: block; text-align: left; padding-bottom: 4px; }
  .table td.primary::before { display: none; }
  .table td.actions { justify-content: flex-end; padding-top: 6px; }
  .table td.actions::before { display: none; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none !important; border-radius: 14px 14px 0 0; max-height: 94vh; }
  .modal-body { overflow-y: auto; }
  .modal-foot { border-radius: 0; }
  .modal-foot .btn { flex: 1; }
  .btn { height: 40px; }
  .input { height: 42px; font-size: 16px; } /* prevents iOS zoom */
  textarea.input { font-size: 16px; }
  .check-row { flex-direction: column; align-items: flex-start; }
}
@media print {
  .sidebar, .topbar, .page-actions, .toolbar, .pagination { display: none !important; }
  .main { margin: 0; }
}
