:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: #dbe3ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #166534;
  --warning: #b45309;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}
.page {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px;
}
.hero {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.hero > div, .card, .message {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}
.hero > div:first-child {
  padding: 28px;
}
.hero h1 {
  margin: 10px 0;
  font-size: 2rem;
  line-height: 1.2;
}
.hero p, .muted, li { color: var(--muted); }
.eyebrow {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.hero-stats {
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.stat-card, .mini-stat {
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.stat-label {
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
}
.stat-card strong, .mini-stat strong {
  font-size: 1.8rem;
}
.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.tab {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  font-weight: 700;
}
.tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.card {
  padding: 22px;
}
.grid {
  display: grid;
  gap: 20px;
}
.grid.two { grid-template-columns: 1fr 1.2fr; }
.grid.two.compact { grid-template-columns: 1fr 1fr; gap: 12px; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; }
.between { justify-content: space-between; }
.center { align-items: center; }
.gap { gap: 12px; }
.metric-grid { margin-bottom: 18px; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
}
textarea { resize: vertical; }
.button {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}
.button.primary {
  background: var(--primary);
  color: white;
}
.button.primary:hover { background: var(--primary-dark); }
.button.secondary {
  background: #eff6ff;
  color: var(--primary-dark);
}
.button.small {
  padding: 8px 10px;
  font-size: 0.9rem;
}
.search-controls {
  min-width: 320px;
}
.message {
  padding: 14px 18px;
  margin-bottom: 18px;
}
.message.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--success);
}
.message.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}
.hidden { display: none; }
.list-stack { margin-top: 10px; }
.list-item {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: white;
}
.item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}
.item-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.item-meta, .item-body, .item-foot {
  color: var(--muted);
  font-size: 0.93rem;
}
.item-body { margin: 8px 0; }
.badges, .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 700;
  background: #f8fafc;
}
.badge.low, .badge.closed, .badge.not-linked { background: #f8fafc; color: #334155; }
.badge.medium, .badge.due-soon, .badge.partially-received, .badge.pending { background: #fffbeb; color: #92400e; }
.badge.high, .badge.urgent, .badge.breached, .badge.error, .badge.canceled { background: #fef2f2; color: #991b1b; }
.badge.open, .badge.in-progress, .badge.scheduled, .badge.ordered, .badge.queued { background: #eff6ff; color: #1d4ed8; }
.badge.resolved, .badge.received, .badge.delivered, .badge.synced, .badge.met { background: #ecfdf5; color: #166534; }
.checkbox-row {
  flex-direction: row;
  align-items: center;
}
.inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 8px;
}
ul { margin: 0; padding-left: 18px; }

@media (max-width: 980px) {
  .hero, .grid.two, .tabs, .grid.three { grid-template-columns: 1fr; }
  .search-controls { min-width: 0; }
}


.toolbar-links {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 6px;
}
.public-page .hero {
  grid-template-columns: 1.6fr 0.9fr;
}
.public-grid {
  grid-template-columns: 1.35fr 0.95fr;
  align-items: start;
}
.hero-actions-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}
.hero-actions-card .soft {
  background: #f8fbff;
}
.no-margin { margin: 0; }
.calendar-month {
  min-width: 170px;
  text-align: center;
  border: 1px solid var(--border);
  background: #f8fbff;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
}
.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
}
.calendar-weekdays {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}
.calendar-day {
  min-height: 96px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: white;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}
.calendar-day:hover:not(:disabled) {
  border-color: var(--primary);
}
.calendar-day .day-number {
  display: block;
  font-weight: 700;
}
.calendar-day .day-slots {
  display: block;
  margin-top: 10px;
  color: var(--primary-dark);
  font-size: 0.85rem;
}
.muted-day {
  background: #f8fafc;
  color: #94a3b8;
  cursor: default;
}
.selected-day {
  border-color: var(--primary);
  background: #eff6ff;
}
.slot-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.slot-button {
  border: 1px solid var(--border);
  background: white;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  font-weight: 700;
}
.slot-button:hover:not(:disabled) {
  border-color: var(--primary);
}
.slot-selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.slot-booked {
  background: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(100%, 520px);
}
.wrap-top { margin-top: 10px; }
@media (max-width: 980px) {
  .public-grid,
  .public-page .hero,
  .hero,
  .grid.two {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 640px) {
  .calendar-weekdays,
  .calendar-grid {
    gap: 8px;
  }
  .calendar-day {
    min-height: 80px;
    padding: 10px;
  }
  .slot-grid {
    grid-template-columns: 1fr;
  }
  .toolbar-links {
    justify-content: stretch;
    flex-direction: column;
  }
}


/* Technician dark mode */
body.tech-theme {
  --bg: #020617;
  --card: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1e293b;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  background:
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.14), transparent 30%),
    radial-gradient(circle at top left, rgba(14, 165, 233, 0.10), transparent 26%),
    var(--bg);
  color: var(--text);
}
body.tech-theme .hero > div,
body.tech-theme .card,
body.tech-theme .message {
  background: rgba(15, 23, 42, 0.94);
  border-color: var(--border);
  box-shadow: 0 18px 42px rgba(2, 6, 23, 0.46);
}
body.tech-theme .stat-card,
body.tech-theme .mini-stat,
body.tech-theme .list-item,
body.tech-theme .calendar-month,
body.tech-theme .hero-actions-card,
body.tech-theme .badge,
body.tech-theme code {
  background: #0b1220;
  border-color: var(--border);
}
body.tech-theme .tab {
  background: #0f172a;
  color: var(--text);
}
body.tech-theme .tab.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: #2563eb;
}
body.tech-theme input,
body.tech-theme select,
body.tech-theme textarea {
  background: #020617;
  color: var(--text);
  border-color: #334155;
}
body.tech-theme input::placeholder,
body.tech-theme textarea::placeholder {
  color: #64748b;
}
body.tech-theme .button.secondary {
  background: #172554;
  color: #dbeafe;
  border: 1px solid #1d4ed8;
}
body.tech-theme .button.secondary:hover {
  background: #1d4ed8;
  color: white;
}
body.tech-theme .message.success {
  background: rgba(20, 83, 45, 0.25);
  border-color: rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}
body.tech-theme .message.error {
  background: rgba(127, 29, 29, 0.25);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fecaca;
}
body.tech-theme .badge.low,
body.tech-theme .badge.closed,
body.tech-theme .badge.not-linked {
  background: #111827;
  color: #cbd5e1;
}
body.tech-theme .badge.medium,
body.tech-theme .badge.due-soon,
body.tech-theme .badge.partially-received,
body.tech-theme .badge.pending {
  background: rgba(180, 83, 9, 0.18);
  color: #fcd34d;
}
body.tech-theme .badge.high,
body.tech-theme .badge.urgent,
body.tech-theme .badge.breached,
body.tech-theme .badge.error,
body.tech-theme .badge.canceled {
  background: rgba(153, 27, 27, 0.22);
  color: #fca5a5;
}
body.tech-theme .badge.open,
body.tech-theme .badge.in-progress,
body.tech-theme .badge.scheduled,
body.tech-theme .badge.ordered,
body.tech-theme .badge.queued {
  background: rgba(29, 78, 216, 0.2);
  color: #93c5fd;
}
body.tech-theme .badge.resolved,
body.tech-theme .badge.received,
body.tech-theme .badge.delivered,
body.tech-theme .badge.synced,
body.tech-theme .badge.met {
  background: rgba(22, 101, 52, 0.25);
  color: #86efac;
}
body.tech-theme .item-meta,
body.tech-theme .item-body,
body.tech-theme .item-foot,
body.tech-theme .muted,
body.tech-theme .hero p,
body.tech-theme li,
body.tech-theme .stat-label,
body.tech-theme .calendar-weekdays {
  color: var(--muted);
}
body.tech-theme a {
  color: #bfdbfe;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
}
.brand-logo {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: white;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}
.public-hero h1 {
  margin: 8px 0 0;
}
@media (max-width: 640px) {
  .brand-lockup {
    flex-direction: column;
    align-items: flex-start;
  }
  .brand-logo {
    width: 76px;
    height: 76px;
    border-radius: 18px;
  }
}


.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: center;
}

.field-note {
  margin-top: -0.25rem;
  font-size: 0.84rem;
  color: #94a3b8;
}

.credential-row {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 1rem;
  padding: 0.8rem 0.9rem;
  background: rgba(15, 23, 42, 0.5);
}

.credential-label {
  font-size: 0.83rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
}

.credential-value {
  padding: 0.25rem 0.55rem;
  border-radius: 0.6rem;
  background: rgba(2, 6, 23, 0.7);
  color: #f8fafc;
  font-size: 0.95rem;
}

.button.tiny {
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
}

.badge.serial {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(30, 64, 175, 0.25);
  color: #bfdbfe;
}

.badge.secure {
  border-color: rgba(34, 197, 94, 0.32);
  background: rgba(20, 83, 45, 0.28);
  color: #bbf7d0;
}


.availability-rule-list {
  gap: 0.8rem;
}

.availability-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto 1fr 1fr;
  gap: 0.75rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.7);
}

.availability-day {
  font-weight: 700;
}

.availability-check {
  font-size: 0.9rem;
}

body.tech-theme .availability-row {
  background: rgba(2, 6, 23, 0.62);
  border-color: var(--border);
}

@media (max-width: 780px) {
  .availability-row {
    grid-template-columns: 1fr 1fr;
  }
}


.auth-card {
  max-width: 560px;
}
.helper-links {
  flex-wrap: wrap;
}
.slim-page {
  max-width: 980px;
}
.account-hero {
  grid-template-columns: 1fr;
}
.account-card {
  max-width: 620px;
}
.narrow-stack {
  max-width: 420px;
}

.grid.four { grid-template-columns: repeat(4, 1fr); }
.detail-panels { display: grid; gap: 12px; margin-top: 12px; }
.detail-card { border: 1px solid var(--border); border-radius: 14px; background: #fbfdff; padding: 0; overflow: hidden; }
.detail-card summary { cursor: pointer; list-style: none; padding: 12px 14px; font-weight: 700; color: var(--text); }
.detail-card summary::-webkit-details-marker { display: none; }
.detail-card[open] summary { border-bottom: 1px solid var(--border); background: #f8fbff; }
.detail-card .detail-inner { padding: 14px; }
.inline-form { display: grid; gap: 10px; margin-top: 10px; }
.note-stream, .log-stream { display: flex; flex-direction: column; gap: 10px; }
.note-item, .log-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: white; }
.note-item .meta, .log-item .meta { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 6px; }
.ticket-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.ticket-kpi { padding: 10px 12px; border-radius: 12px; background: #f8fbff; border: 1px solid var(--border); }
.ticket-kpi span { display:block; color: var(--muted); font-size: 0.78rem; margin-bottom: 4px; }
.ticket-kpi strong { font-size: 1rem; }
.form-inline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.badge.referred-out, .badge.waiting-on-customer, .badge.waiting-on-part { background: #fff7ed; color: #9a3412; }
.field-note.small { font-size: 0.82rem; margin-top: -4px; }
@media (max-width: 980px) { .grid.four, .ticket-kpis, .form-inline-grid { grid-template-columns: 1fr; } }


.hero-actions-stack{display:flex;flex-direction:column;gap:12px;}
.billing-summary-card{margin-bottom:14px;}
.status-results{display:grid;gap:18px;}
.status-ticket-card{background:#fff;border:1px solid #dbe3f0;border-radius:18px;padding:20px;box-shadow:0 10px 28px rgba(15,27,61,.08);}
.attachment-link{font-weight:600;}


/* Phase 5 customer portal */
.portal-topbar{display:flex;justify-content:space-between;align-items:center;gap:16px;padding:18px 24px;background:#0f1b3d;color:#fff;flex-wrap:wrap}.portal-actions{display:flex;gap:10px;flex-wrap:wrap}.portal-shell{max-width:1100px;margin:0 auto;padding:24px}.portal-ticket-list{display:grid;gap:18px}.portal-ticket-card{background:#fff;border:1px solid #dbe3f0;border-radius:18px;padding:18px;box-shadow:0 10px 24px rgba(15,27,61,.08)}.portal-subsection{margin-top:16px}.portal-subsection h3{margin:0 0 10px;font-size:18px}.auth-shell{min-height:100vh;display:grid;place-items:center;padding:24px}.auth-card{max-width:540px;width:100%;background:#fff;border:1px solid #dbe3f0;border-radius:18px;padding:28px;box-shadow:0 10px 24px rgba(15,27,61,.08)}.brand-mini{font-size:13px;text-transform:uppercase;letter-spacing:.08em;color:#5f6d86;margin-bottom:10px}.stack-form{display:grid;gap:14px}.portal-reply-form textarea{width:100%}@media (max-width:768px){.portal-topbar{padding:16px}.portal-shell{padding:16px}}


.attachment-preview-modal.hidden{display:none;}
.attachment-preview-modal{position:fixed;inset:0;z-index:9999;}
.attachment-preview-backdrop{position:absolute;inset:0;background:rgba(2,6,23,.72);}
.attachment-preview-panel{position:relative;max-width:min(92vw,1000px);max-height:90vh;margin:5vh auto;background:#fff;border-radius:16px;overflow:hidden;box-shadow:0 20px 50px rgba(0,0,0,.28);}
.attachment-preview-close{position:absolute;top:10px;right:14px;border:0;background:transparent;font-size:32px;line-height:1;cursor:pointer;z-index:2;}
.attachment-preview-body{padding:48px 16px 16px;max-height:90vh;overflow:auto;text-align:center;}
.attachment-preview-body img{max-width:100%;height:auto;border-radius:8px;}
.attachment-preview-body iframe{width:min(90vw,960px);height:78vh;border:0;}
