/* Job Ratchanee web app. Light theme tuned for outdoor phone use (technicians) and desktop (admin). */
:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --subtle: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #0369a1;
  --primary-hover: #075985;
  --primary-weak: #e0f2fe;
  --on-primary: #ffffff;
  --danger: #b91c1c;
  --danger-weak: #fee2e2;
  --success: #15803d;
  --success-weak: #dcfce7;
  --warning: #b45309;
  --warning-weak: #fef3c7;
  --info: #1d4ed8;
  --info-weak: #dbeafe;

  --k-clean: #0369a1;   --k-clean-bg: #e0f2fe;
  --k-install: #6d28d9; --k-install-bg: #ede9fe;
  --k-repair: #c2410c;  --k-repair-bg: #ffedd5;
  --k-check: #0f766e;   --k-check-bg: #ccfbf1;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 8%);
  --shadow-lg: 0 10px 30px rgb(15 23 42 / 18%);
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --nav-h: 64px;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.375rem; font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; border-radius: 6px; }

/* ---------- Layout ---------- */
.shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.125rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--primary); }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.page { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.page-narrow { max-width: 640px; }

.bottomnav {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .75rem; font-weight: 500; color: var(--subtle); text-decoration: none;
}
.bottomnav a[aria-current="page"] { color: var(--primary); }
.bottomnav a[aria-current="page"] .icon { stroke-width: 2.4; }

.sidenav { display: none; }
@media (min-width: 960px) {
  .shell.has-side { padding-bottom: 0; padding-left: 240px; }
  .has-side .bottomnav { display: none; }
  .has-side .sidenav {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; inset: 0 auto 0 0; width: 240px; padding: 16px 12px;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .sidenav .brand { padding: 4px 8px 20px; }
  .sidenav a {
    display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px;
    border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; font-weight: 500;
  }
  .sidenav a:hover { background: var(--surface-2); color: var(--text); }
  .sidenav a[aria-current="page"] { background: var(--primary-weak); color: var(--primary); }
  .sidenav .spacer { flex: 1; }
  .has-side .topbar .brand { display: none; }
}

/* ---------- Cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.stack-sm { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.xs { font-size: .8125rem; }
.grow { flex: 1; min-width: 0; }
.hr { height: 1px; background: var(--border); margin: 4px 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; display: grid; gap: 8px; justify-items: center; }
.empty .icon { width: 40px; height: 40px; color: var(--border-strong); }

.list { display: grid; }
.list > * + * { border-top: 1px solid var(--border); }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px;
  color: inherit; text-decoration: none; background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
}
.list-item:hover { background: var(--surface-2); }
.list-item .chev { color: var(--border-strong); }
.group-label { padding: 10px 16px 6px; font-size: .8125rem; font-weight: 600; color: var(--muted); background: var(--surface-2); }

.kv { display: grid; grid-template-columns: 7.5rem 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #166534; }
.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--danger-weak); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-lg { min-height: 52px; font-size: 1.0625rem; padding: 0 20px; }
.btn-block { width: 100%; }
.icon-btn { width: 44px; padding: 0; }
.btn .spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: .9375rem; }
.req::after { content: ' *'; color: var(--danger); }
.help { font-size: .8125rem; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.textarea { min-height: 88px; resize: vertical; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgb(3 105 161 / 20%); }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--subtle); pointer-events: none; }
.input-icon .input { padding-left: 40px; }
.grid-2 { display: grid; gap: 12px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.form-error { color: var(--danger); background: var(--danger-weak); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9375rem; }

/* Chips used for quick date/time picks and filters */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); font-weight: 500; cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Segmented tabs */
.tabs { display: flex; gap: 4px; padding: 4px; background: #e8edf3; border-radius: 10px; overflow-x: auto; }
.tab {
  flex: 1; min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent;
  font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--border); font-size: .75rem; }
.tab[aria-selected="true"] .count { background: var(--primary-weak); color: var(--primary); }

/* Service picker */
.svc-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.svc {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; text-align: left;
}
.svc:hover { border-color: var(--primary); }
.svc .box { width: 22px; height: 22px; border: 2px solid var(--border-strong); border-radius: 6px; display: grid; place-items: center; flex: none; }
.svc.on { border-color: var(--primary); background: var(--primary-weak); }
.svc.on .box { background: var(--primary); border-color: var(--primary); color: #fff; }
.svc .box .icon { width: 14px; height: 14px; stroke-width: 3; }
.svc-name { flex: 1; font-weight: 500; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }
.stepper button { width: 36px; height: 36px; border: 0; background: none; font-size: 1.125rem; font-weight: 700; cursor: pointer; color: var(--primary); }
.stepper span { min-width: 28px; text-align: center; font-weight: 600; }
.selected-summary { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 600; white-space: nowrap; }
.st-pending { background: var(--warning-weak); color: var(--warning); }
.st-in_progress { background: var(--info-weak); color: var(--info); }
.st-done { background: var(--success-weak); color: var(--success); }
.st-cancelled { background: #f1f5f9; color: var(--muted); }
.st-overdue { background: var(--danger-weak); color: var(--danger); }
.k-clean { background: var(--k-clean-bg); color: var(--k-clean); }
.k-install { background: var(--k-install-bg); color: var(--k-install); }
.k-repair { background: var(--k-repair-bg); color: var(--k-repair); }
.k-check { background: var(--k-check-bg); color: var(--k-check); }

/* ---------- Job cards ---------- */
.job-card { display: grid; gap: 8px; padding: 14px 16px; color: inherit; text-decoration: none; }
.job-card:hover { background: var(--surface-2); }
.job-time { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--primary); }
.job-title { font-weight: 600; }
.job-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .875rem; }
.job-meta span { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; }
.cal-head h2 { flex: 1; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal .day {
  position: relative; aspect-ratio: 1 / .9; min-height: 44px; border: 1px solid transparent; border-radius: 10px;
  background: var(--surface-2); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px;
}
.cal .day:hover { border-color: var(--border-strong); }
.cal .day.out { opacity: .4; }
.cal .day.today .num { background: var(--text); color: #fff; border-radius: 999px; min-width: 26px; }
.cal .day[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-weak); }
.cal .num { font-weight: 600; font-size: .9375rem; line-height: 26px; text-align: center; }
.cal .dot { font-size: .6875rem; font-weight: 700; min-width: 20px; padding: 0 5px; border-radius: 999px; line-height: 18px; text-align: center; }
.dot.pending { background: var(--warning); color: #fff; }
.dot.done { background: var(--success); color: #fff; }
.dot.overdue { background: var(--danger); color: #fff; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8125rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.375rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8125rem; color: var(--muted); }
@media (min-width: 960px) {
  .schedule-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
}

/* ---------- Technician job page ---------- */
.hero { background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px; display: grid; gap: 12px; }
.contact-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-section { display: grid; gap: 12px; }
.photo-section-head { display: flex; align-items: center; gap: 8px; }
.stage { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; background: var(--surface-2); }
.stage.ok { border-style: solid; border-color: #86efac; background: #f0fdf4; }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stage-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; }
.ok .check-dot { background: var(--success); border-color: var(--success); color: #fff; }
.check-dot .icon { width: 13px; height: 13px; stroke-width: 3; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.thumb .del {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: rgb(15 23 42 / 70%); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.thumb.uploading::after { content: ''; position: absolute; inset: 0; background: rgb(255 255 255 / 60%); }
.add-photo {
  aspect-ratio: 1; border-radius: 10px; border: 1.5px dashed var(--primary); background: var(--surface);
  color: var(--primary); display: grid; place-items: center; align-content: center; gap: 4px; font-size: .8125rem; font-weight: 600; cursor: pointer;
}
.add-photo .icon { width: 26px; height: 26px; }
.sticky-action {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10;
  padding: 12px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.missing { display: grid; gap: 4px; font-size: .875rem; color: var(--warning); }
.missing li { list-style: none; display: flex; gap: 6px; align-items: center; }
.missing ul { margin: 0; padding: 0; }

/* ---------- Overlays ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px); transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: rgb(15 23 42 / 55%); display: grid; place-items: end center; animation: fade .15s var(--ease); }
.modal { width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 16px 16px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 14px; animation: rise .2s var(--ease); }
@media (min-width: 640px) { .modal-backdrop { place-items: center; } .modal { border-radius: 16px; } }
.lightbox { position: fixed; inset: 0; z-index: 95; background: rgb(0 0 0 / 90%); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-height: 90dvh; border-radius: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #e0f2fe, var(--bg) 55%); }
.login .card { width: 100%; max-width: 400px; padding: 28px 24px; display: grid; gap: 16px; }
.login .brand-mark { width: 52px; height: 52px; border-radius: 14px; }
.login .brand-mark .icon { width: 28px; height: 28px; }

.skeleton { background: linear-gradient(90deg, #eef2f6 25%, #f8fafc 50%, #eef2f6 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; min-height: 72px; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
