:root {
  --ink: #1a2129;
  --slate: #2b3644;
  --slate-light: #445064;
  --paper: #f6f5f2;
  --panel: #ffffff;
  --line: #dde1e6;
  --amber: #d98e2b;
  --amber-dark: #b8721c;
  --good: #3d8b5f;
  --warn: #c85a3a;
  --muted: #6b7684;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-size: 15px; }
button { cursor: pointer; font-family: inherit; }

/* ---- Login ---- */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--ink);
}
.login-card { background: var(--panel); padding: 48px 40px; border-radius: 4px; width: 320px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; color: var(--slate); font-weight: 700; }
.login-card h1 span { display: block; font-size: 13px; font-weight: 500; color: var(--amber-dark); letter-spacing: 0.02em; margin-top: 2px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
#pin-input { width: 100%; padding: 12px; font-size: 22px; text-align: center; letter-spacing: 6px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 12px; }
#login-btn { width: 100%; padding: 12px; background: var(--amber); color: #fff; border: none; border-radius: 4px; font-weight: 600; }
#login-btn:hover { background: var(--amber-dark); }
.error-text { color: var(--warn); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* ---- App shell ---- */
.topbar { display: flex; align-items: center; gap: 24px; background: var(--slate); color: #fff; padding: 0 24px; height: 56px; }
.brand { font-weight: 700; }
.brand span { color: #f0c477; font-weight: 500; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.nav-btn { background: none; border: none; color: #cdd3da; padding: 8px 14px; border-radius: 4px; font-size: 14px; }
.nav-btn.active, .nav-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #cdd3da; }
#logout-btn { background: none; border: 1px solid rgba(255,255,255,0.25); color: #fff; padding: 5px 10px; border-radius: 4px; font-size: 12px; }

.view { padding: 28px 32px; max-width: 1100px; margin: 0 auto; }
.view h2 { margin-top: 0; }
.view-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.filters { display: flex; gap: 8px; }

input, select, textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 4px; font-size: 14px; background: #fff; color: var(--ink);
}
textarea { width: 100%; min-height: 70px; margin: 10px 0; resize: vertical; }

.data-table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 6px; overflow: hidden; }
.data-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.data-table tr:hover td { background: #faf8f4; cursor: pointer; }

.status-pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-open { background: #f2e6d8; color: var(--amber-dark); }
.status-closed { background: #e2e2e2; color: #555; }

/* ---- Wizard ---- */
.wizard-steps { display: flex; gap: 4px; margin-bottom: 20px; }
.step-btn { flex: 1; padding: 10px; border: 1px solid var(--line); background: #fff; border-radius: 4px; font-size: 13px; color: var(--muted); }
.step-btn.active { background: var(--slate); color: #fff; border-color: var(--slate); }
.step-panel { background: var(--panel); padding: 22px; border-radius: 6px; border: 1px solid var(--line); }
.form-row { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.form-row select, .form-row input { flex: 1; min-width: 140px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.or-divider { color: var(--muted); font-size: 12px; margin: 14px 0 8px; text-transform: none; }
.result-list { max-height: 220px; overflow-y: auto; margin: 8px 0; }
.result-list.wide { max-height: none; }
.result-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 6px; background: #fff; }
.result-item:hover { border-color: var(--amber); cursor: pointer; }
.selected-box { background: #f2ede2; border: 1px solid #e2d3ae; border-radius: 4px; padding: 12px; margin-top: 12px; font-size: 13px; }

/* ---- Device picker: breadcrumb + icon tiles (matches the old system's flow) ---- */
.device-breadcrumb { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; font-size: 13px; }
.crumb { color: var(--muted); cursor: default; }
.crumb.active { color: var(--slate); font-weight: 700; }
.crumb.done { color: var(--amber-dark); cursor: pointer; }
.crumb.done:hover { text-decoration: underline; }
.crumb-sep { color: var(--line); }
.tile-search { width: 100%; margin-bottom: 14px; }
.tile-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 22px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.tile:hover { border-color: var(--amber); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.tile-icon { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; color: var(--slate-light); }
.tile-icon svg { width: 32px; height: 32px; }
.tile-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.tile-add { border: 1.5px dashed var(--amber); color: var(--amber-dark); }
.tile-add .tile-icon { color: var(--amber); }
.tile-custom { border-style: dashed; color: var(--muted); }
.add-form { background: #f2ede2; border: 1px solid #e2d3ae; border-radius: 8px; padding: 16px; margin-top: 14px; }
.add-form .form-row { margin-bottom: 8px; }
@media (max-width: 700px) { .tile-grid { grid-template-columns: repeat(2, 1fr); } }
.check-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.check-chip { border: 1px solid var(--line); padding: 7px 12px; border-radius: 20px; font-size: 13px; background: #fff; }
.check-chip.selected { background: var(--amber); color: #fff; border-color: var(--amber); }

button.primary, #save-device-btn, #create-client-btn, #problems-next-btn, #submit-ticket-btn, #add-staff-btn {
  background: var(--amber); color: #fff; border: none; padding: 10px 18px; border-radius: 4px; font-weight: 600; margin-top: 10px;
}
button.primary:hover, #save-device-btn:hover, #create-client-btn:hover, #problems-next-btn:hover, #submit-ticket-btn:hover, #add-staff-btn:hover { background: var(--amber-dark); }
.back-btn { background: none; border: none; color: var(--slate-light); font-size: 13px; margin-bottom: 14px; padding: 0; }

/* ---- Ticket detail ---- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 20px; margin-bottom: 20px; }
.detail-card h3 { margin-top: 0; font-size: 14px; color: var(--muted); text-transform: none; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f0eee9; font-size: 14px; }
.kv span:first-child { color: var(--muted); }
.log-entry { border-left: 2px solid var(--line); padding: 6px 0 6px 14px; margin-bottom: 4px; font-size: 13px; }
.log-entry .log-time { color: var(--muted); font-size: 11px; }
.chip-remove { margin-left: 6px; cursor: pointer; color: var(--warn); font-weight: 700; }

/* ---- Ticket detail v2 (matches the reference layout) ---- */
.ticket-head-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.ticket-head-row h2 { margin: 0; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.service-table th, .service-table td { vertical-align: top; }
.service-table select, .service-table input { width: 100%; }
.activity-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.atab { background: none; border: none; padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.atab small { font-size: 10px; display: block; }
.atab.active { color: var(--slate); border-bottom-color: var(--amber); font-weight: 600; }
.comment-box { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.comment-box textarea { flex: 1; min-height: 44px; margin: 0; }
.comment-box button { margin: 0; white-space: nowrap; }
.upload-box { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px dashed var(--line); }
.upload-box button { margin: 0; white-space: nowrap; }
.activity-entry { border-radius: 4px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px; }
.activity-entry .activity-time { font-size: 11px; color: var(--muted); margin-top: 3px; }
.activity-entry a { color: var(--amber-dark); font-weight: 600; }
.activity-activity { background: #e6f2ea; }
.activity-internal { background: #e3edf7; }
.activity-diagnostic { background: #fbf1d6; }
.activity-attachment { background: #ece6f5; }

/* ---- Create New Customer modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(26,33,41,0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-card { background: #fff; border-radius: 8px; padding: 32px 36px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-icon { width: 56px; height: 56px; border-radius: 50%; background: #f2ede2; color: var(--amber-dark); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.modal-icon svg { width: 28px; height: 28px; }
.modal-title { text-align: center; margin: 0 0 20px; font-size: 19px; }
.modal-tabs { display: flex; background: #f3f2ef; border-radius: 6px; padding: 3px; margin-bottom: 20px; }
.mtab { flex: 1; background: none; border: none; padding: 9px; border-radius: 5px; font-size: 13px; color: var(--muted); }
.mtab.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.modal-tab-panel label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--slate); }
.modal-tab-panel .form-grid > div { display: flex; flex-direction: column; }
.modal-tab-panel input, .modal-tab-panel select, .modal-tab-panel textarea { width: 100%; }
.tag-primary { background: #e1f0e6; color: var(--good); font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; margin-left: 4px; vertical-align: middle; }
.notifications-box { background: #f6f5f2; border-radius: 6px; padding: 14px 16px; margin-top: 6px; }
.notif-header { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.notif-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-size: 14px; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #d5d5d5; border-radius: 22px; transition: .15s; }
.slider:before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--good); }
.switch input:checked + .slider:before { transform: translateX(18px); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.btn-secondary { background: #fff; border: 1px solid var(--line); color: var(--ink); padding: 10px 18px; border-radius: 4px; font-weight: 600; }
#open-new-customer-modal { background: #fff; border: 1px solid var(--amber); color: var(--amber-dark); padding: 10px 18px; border-radius: 4px; font-weight: 600; width: 100%; margin-top: 4px; }
#open-new-customer-modal:hover { background: #fdf6ea; }

/* ---- Ticket row Action dropdown ---- */
.action-cell { position: relative; text-align: right; }
.action-btn { background: #fff; border: 1px solid var(--line); padding: 6px 12px; border-radius: 4px; font-size: 13px; color: var(--slate); }
.action-btn:hover { border-color: var(--amber); }
.action-menu { position: absolute; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); min-width: 180px; z-index: 20; padding: 6px 0; text-align: left; }
.action-menu button { display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 16px; font-size: 13px; color: var(--ink); }
.action-menu button:hover { background: #f6f5f2; }
.action-menu button.danger { color: var(--warn); }
.action-menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.ticket-label-badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; margin-left: 6px; vertical-align: middle; background: #f5e0c8; color: var(--amber-dark); }

/* ---- Printable thermal receipt ---- */
#receipt-print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #receipt-print-area, #receipt-print-area * { visibility: visible; }
  #receipt-print-area { display: block; position: fixed; top: 0; left: 0; width: 300px; font-family: monospace; font-size: 12px; padding: 10px; }
  #receipt-print-area h3 { text-align: center; margin: 4px 0; }
  #receipt-print-area .line { border-top: 1px dashed #000; margin: 6px 0; }
  #receipt-print-area .row { display: flex; justify-content: space-between; }
}

/* ---- Condition checklist ---- */
.condition-checklist { display: flex; flex-direction: column; gap: 6px; }
.condition-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.condition-item .ci-name { font-size: 14px; }
.condition-item .ci-options { display: flex; gap: 4px; }
.ci-btn { border: 1px solid var(--line); background: #fff; padding: 5px 10px; font-size: 12px; border-radius: 4px; color: var(--muted); }
.ci-btn.selected-pass { background: #e1f0e6; color: var(--good); border-color: var(--good); }
.ci-btn.selected-fail { background: #f5e0dc; color: var(--warn); border-color: var(--warn); }
.ci-btn.selected-na { background: #eceef0; color: var(--slate-light); border-color: var(--slate-light); }
.ci-remove { color: var(--warn); cursor: pointer; margin-left: 6px; font-weight: 700; }

/* ---- Ticket detail top action bar ---- */
.ticket-action-bar { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.tab-btn { background: var(--slate); color: #fff; border: none; padding: 9px 14px; border-radius: 4px; font-size: 13px; font-weight: 600; }
.tab-btn:hover { background: var(--slate-light); }
.tab-btn.rush-active { background: var(--warn); }
.tab-btn.outline { background: #fff; color: var(--slate); border: 1px solid var(--line); }
.tab-spacer { flex: 1; }
.print-dropdown-wrap { position: relative; display: inline-block; }
.flash-highlight { animation: flashHighlight 1.2s ease; }
@keyframes flashHighlight { 0% { box-shadow: 0 0 0 3px var(--amber); } 100% { box-shadow: none; } }

/* ---- Payments ---- */
.payment-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid #f0eee9; }

/* ---- Printable full invoice ---- */
#invoice-print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #invoice-print-area, #invoice-print-area * { visibility: visible; }
  #invoice-print-area { display: block; position: fixed; top: 0; left: 0; width: 100%; padding: 24px 32px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000; }
  .inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
  .inv-shop-name { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
  .inv-title { font-size: 26px; font-weight: 800; text-align: right; }
  .inv-qr-block { text-align: center; margin-top: 6px; }
  .inv-qr-block .inv-ticket-num { font-size: 11px; margin-top: 2px; }
  .inv-two-col { display: flex; gap: 24px; margin-bottom: 16px; }
  .inv-two-col > div { flex: 1; }
  .inv-box-table { width: 100%; border-collapse: collapse; }
  .inv-box-table td { border: 1px solid #999; padding: 6px 10px; }
  .inv-items-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
  .inv-items-table th, .inv-items-table td { border: 1px solid #999; padding: 8px; text-align: left; vertical-align: top; font-size: 11px; }
  .inv-items-table th { background: #f0f0f0; }
  .inv-summary-wrap { display: flex; justify-content: flex-end; margin-bottom: 20px; }
  .inv-summary-table { border-collapse: collapse; min-width: 260px; }
  .inv-summary-table td { padding: 3px 8px; font-size: 12px; }
  .inv-summary-table .inv-total-row td { border-top: 2px solid #000; font-weight: 700; }
  .inv-summary-table .inv-due-row td { font-weight: 700; }
  .inv-terms { font-size: 9px; color: #333; border-top: 1px solid #999; padding-top: 10px; }
  .inv-terms h4 { font-size: 11px; margin: 8px 0 3px; }
  .inv-footer { margin-top: 14px; font-size: 9px; color: #666; }
}

/* ---- Inventory ---- */
.add-part-btn { background: var(--amber); color: #fff; border: none; padding: 9px 16px; border-radius: 4px; font-weight: 600; font-size: 13px; }
.add-part-btn:hover { background: var(--amber-dark); }
.stock-low { color: var(--warn); font-weight: 700; }
.stock-ok { color: var(--good); font-weight: 600; }
.result-item.out-of-stock { opacity: 0.6; }
.qty-input { width: 44px; border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; margin: 0 4px; }
.history-entry { padding: 8px 0; border-bottom: 1px solid #f0eee9; font-size: 13px; }
.history-entry .h-time { font-size: 11px; color: var(--muted); }
