/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --font: 'Sarabun', sans-serif;
  --green:       #1D9E75;
  --green-dark:  #0F6E56;
  --green-light: #E1F5EE;
  --green-mid:   #5DCAA5;
  --purple:      #534AB7;
  --purple-light:#EEEDFE;
  --blue:        #378ADD;
  --blue-light:  #E6F1FB;
  --amber:       #BA7517;
  --amber-light: #FAEEDA;
  --red:         #E24B4A;
  --red-light:   #FCEBEB;
  --orange:      #D85A30;
  --orange-light:#FAECE7;
  --gray-bg:     #F8F8F6;
  --gray-line:   #D3D1C7;
  --gray-mid:    #888780;
  --gray-dark:   #2C2C2A;
  --white:       #FFFFFF;
  --sidebar-w:   220px;
  --topbar-h:    52px;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 1px 4px rgba(0,0,0,.08);
}
html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--gray-dark); background: #f5f4f1; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-line); border-radius: 3px; }

/* ════════════════════════════════════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════════════════════════════════════ */
.login-page {
  display: grid;
  grid-template-columns: 1fr 420px;
  min-height: 100vh;
  background: #f5f4f1;
}
@media (max-width: 768px) {
  .login-page { grid-template-columns: 1fr; }
  .login-left  { display: none; }
  .login-right { padding: 24px 20px; }
}
.login-left {
  background: var(--green-dark);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 40px;
  position: relative; overflow: hidden;
}
.login-left::before {
  content: ''; position: absolute;
  width: 340px; height: 340px; border-radius: 50%;
  background: rgba(255,255,255,.05);
  top: -100px; left: -80px;
}
.login-left::after {
  content: ''; position: absolute;
  width: 200px; height: 200px; border-radius: 50%;
  background: rgba(255,255,255,.05);
  bottom: 40px; right: -50px;
}
.login-brand {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 44px; z-index: 1;
}
.brand-icon {
  width: 56px; height: 56px; border-radius: 16px;
  background: rgba(255,255,255,.15); border: 1.5px solid rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.brand-name { font-size: 20px; font-weight: 600; color: #fff; }
.brand-url  { font-size: 12px; color: rgba(255,255,255,.6); margin-top: 2px; }
.login-features { z-index: 1; width: 100%; display: flex; flex-direction: column; gap: 14px; }
.feat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  background: rgba(255,255,255,.08); border-radius: 12px;
  border: 0.5px solid rgba(255,255,255,.12);
}
.feat-icon { font-size: 20px; flex-shrink: 0; }
.feat-t { font-size: 13px; color: rgba(255,255,255,.92); font-weight: 500; }
.feat-s { font-size: 11px; color: rgba(255,255,255,.55); margin-top: 2px; }

.login-right {
  background: #fff; display: flex;
  align-items: center; justify-content: center;
  padding: 40px 36px;
  border-left: 1px solid var(--gray-line);
}
.login-box { width: 100%; }
.login-title { font-size: 24px; font-weight: 600; color: var(--gray-dark); margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--gray-mid); margin-bottom: 24px; }

.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-field label { font-size: 12px; font-weight: 500; color: var(--gray-mid); }
.form-field input {
  padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--gray-line);
  font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(29,158,117,.1); }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 42px; }
.eye-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 16px; color: var(--gray-mid);
  padding: 4px; border-radius: 6px; transition: color .15s;
}
.eye-btn:hover { color: var(--gray-dark); }

/* Slider */
.slider-section { margin-bottom: 14px; }
.slider-label { font-size: 11px; color: var(--gray-mid); margin-bottom: 6px; display: flex; align-items: center; gap: 5px; }
.slider-track {
  width: 100%; height: 22px; border-radius: 11px;
  background: #f1f0ec; border: 1px solid var(--gray-line);
  position: relative; overflow: hidden; cursor: pointer; user-select: none;
}
.slider-fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 11px; background: var(--green-light); pointer-events: none; }
.slider-fill.done { background: var(--green); transition: width .25s; }
.slider-thumb {
  position: absolute; left: 1px; top: 1px;
  width: 20px; height: 20px; border-radius: 10px;
  background: #fff; border: 1px solid var(--gray-line);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--gray-mid); z-index: 2; cursor: grab;
  transition: background .2s, border-color .2s;
}
.slider-thumb.done { background: var(--green); border-color: var(--green); color: #fff; cursor: default; }
.slider-hint, .slider-done {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 10px; pointer-events: none; white-space: nowrap; transition: opacity .2s;
}
.slider-hint { color: var(--gray-mid); }
.slider-done { color: #fff; opacity: 0; font-weight: 500; }

/* Attempt bar */
.attempt-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.attempt-dots { display: flex; gap: 5px; }
.attempt-dot { width: 7px; height: 7px; border-radius: 50%; background: #e0e0e0; }
.attempt-dot.used { background: var(--red); }
.attempt-lbl { font-size: 11px; color: var(--gray-mid); }
.locked-msg {
  background: var(--red-light); border: 1px solid #f09595;
  border-radius: 8px; padding: 9px 13px; font-size: 12px; color: #791f1f;
  text-align: center; margin-bottom: 12px;
}
.login-remember {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; font-size: 12px;
}
.chk-label { display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--gray-mid); }
.forgot-link { color: var(--green); }
.login-btn {
  width: 100%; padding: 13px; border-radius: 10px;
  background: var(--green); color: #fff; border: none;
  font-size: 14px; font-weight: 600; transition: opacity .15s; margin-bottom: 12px;
}
.login-btn:hover:not(:disabled) { opacity: .88; }
.login-btn:disabled { opacity: .4; cursor: not-allowed; }
.login-footer { font-size: 11px; color: #aaa; text-align: center; }

/* ════════════════════════════════════════════════════════════════════════
   MAIN APP LAYOUT
════════════════════════════════════════════════════════════════════════ */
.main-app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: #fff; border-right: 1px solid var(--gray-line);
  display: flex; flex-direction: column; overflow-y: auto;
  transition: transform .25s; z-index: 100;
}
.sb-header {
  padding: 14px 14px 12px; border-bottom: 1px solid var(--gray-line); flex-shrink: 0;
}
.sb-logo-row { display: flex; align-items: center; gap: 9px; }
.sb-icon {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--green); display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.sb-name { font-size: 13px; font-weight: 600; color: var(--gray-dark); line-height: 1.3; }
.sb-url  { font-size: 10px; color: var(--gray-mid); }
.sb-nav  { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-group { padding: 6px 0; }
.nav-label {
  font-size: 10px; font-weight: 600; color: #bbb;
  padding: 6px 14px 3px; letter-spacing: .6px; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; font-size: 12px; color: var(--gray-mid);
  cursor: pointer; position: relative; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--gray-bg); color: var(--gray-dark); }
.nav-item.active {
  background: var(--green-light); color: var(--green-dark); font-weight: 600;
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--green); border-radius: 0 3px 3px 0;
}
.ni-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gray-line); flex-shrink: 0;
}
.nav-item.active .ni-dot { background: var(--green); }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 600;
  background: var(--red-light); color: var(--red);
  padding: 1px 6px; border-radius: 10px;
}
.nav-badge.warn { background: var(--amber-light); color: var(--amber); }
.nav-badge.green { background: var(--green-light); color: var(--green-dark); }
.sb-footer { padding: 10px 12px; border-top: 1px solid var(--gray-line); flex-shrink: 0; }
.sb-user { display: flex; align-items: center; gap: 8px; }
.sb-user-av {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--purple-light); color: var(--purple);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; flex-shrink: 0;
}
.sb-user-name { font-size: 12px; font-weight: 500; color: var(--gray-dark); }
.sb-user-role { font-size: 10px; color: var(--gray-mid); }
.sb-logout {
  margin-left: auto; background: none; border: none;
  font-size: 16px; color: var(--gray-mid); padding: 4px;
  border-radius: 6px; transition: background .15s;
}
.sb-logout:hover { background: var(--red-light); color: var(--red); }

/* ── Main Content ────────────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid var(--gray-line);
  display: flex; align-items: center; padding: 0 18px; gap: 10px; flex-shrink: 0;
}
.menu-toggle {
  background: none; border: none; font-size: 18px; color: var(--gray-mid);
  padding: 4px 6px; border-radius: 6px; display: none;
}
@media (max-width: 768px) { .menu-toggle { display: block; } }
.topbar-title { font-size: 15px; font-weight: 600; color: var(--gray-dark); flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.notif-channel-badge {
  font-size: 11px; font-weight: 500; padding: 4px 10px;
  border-radius: 20px; background: var(--green-light); color: var(--green-dark);
  border: 1px solid var(--green-mid); cursor: pointer;
}
.topbar-icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--gray-line); background: none; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.topbar-icon-btn:hover { background: var(--gray-bg); }
.topbar-date { font-size: 12px; color: var(--gray-mid); white-space: nowrap; }
.new-repair-btn {
  padding: 8px 16px; border-radius: 8px;
  background: var(--green); color: #fff; border: none;
  font-size: 13px; font-weight: 600; transition: opacity .15s; white-space: nowrap;
}
.new-repair-btn:hover { opacity: .88; }
.page-content { flex: 1; overflow-y: auto; padding: 16px; background: var(--gray-bg); }

/* ════════════════════════════════════════════════════════════════════════
   SHARED COMPONENTS
════════════════════════════════════════════════════════════════════════ */
.card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--gray-line); overflow: hidden; margin-bottom: 12px;
}
.card-head {
  padding: 12px 16px; border-bottom: 1px solid var(--gray-line);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--gray-dark); display: flex; align-items: center; gap: 7px; }
.card-body  { padding: 14px 16px; }
.card-link  { font-size: 12px; color: var(--green); cursor: pointer; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; }
.grid5 { display: grid; grid-template-columns: repeat(5,1fr); gap: 10px; }
@media (max-width: 768px) {
  .grid2,.grid3,.grid4,.grid5 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .grid2,.grid3,.grid4,.grid5 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 11px; font-weight: 600; color: var(--gray-mid); }
.field input, .field select, .field textarea {
  padding: 8px 11px; border-radius: var(--radius);
  border: 1px solid var(--gray-line); font-size: 13px; outline: none;
  transition: border-color .18s, box-shadow .18s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--green); box-shadow: 0 0 0 3px rgba(29,158,117,.08);
}
.field textarea { resize: vertical; min-height: 60px; line-height: 1.55; }
.req { color: var(--red); }
.field .hint { font-size: 10px; color: var(--gray-mid); margin-top: 2px; }

.divider { height: 1px; background: var(--gray-line); margin: 10px 0; }
.sec-label {
  font-size: 10px; font-weight: 600; color: #bbb;
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px;
}

/* Status pills */
.pill {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
}
.pill-repair  { background: var(--green-light); color: var(--green-dark); }
.pill-wait    { background: var(--amber-light); color: #633806; }
.pill-done    { background: #eaf3de; color: #27500a; }
.pill-pickup  { background: var(--blue-light); color: #185fa5; }
.pill-fail    { background: var(--red-light); color: #791f1f; }
.pill-claim   { background: var(--purple-light); color: #3c3489; }
.pill-out     { background: var(--orange-light); color: #712b13; }

/* KPI Cards */
.kpi-card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--gray-line); padding: 13px 14px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.kpi-card:hover { border-color: var(--gray-mid); box-shadow: var(--shadow); }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.kpi-icon { font-size: 18px; }
.kpi-trend { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 10px; }
.trend-up { background: #eaf3de; color: #27500a; }
.trend-dn { background: var(--red-light); color: #a32d2d; }
.kpi-val { font-size: 24px; font-weight: 700; color: var(--gray-dark); line-height: 1; }
.kpi-lbl { font-size: 11px; color: var(--gray-mid); margin-top: 4px; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th {
  padding: 8px 12px; font-size: 11px; font-weight: 600; color: var(--gray-mid);
  border-bottom: 1px solid var(--gray-line); text-align: left;
  background: var(--gray-bg); white-space: nowrap;
}
.data-table td { padding: 9px 12px; border-bottom: 1px solid #f0f0ed; color: var(--gray-dark); vertical-align: middle; }
.data-table tbody tr { cursor: pointer; transition: background .1s; }
.data-table tbody tr:hover td { background: var(--green-light); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Buttons */
.btn { padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--gray-line); background: none; font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; font-family: var(--font); }
.btn:hover { background: var(--gray-bg); }
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { opacity: .88; background: var(--green); }
.btn-purple  { background: var(--purple); color: #fff; border-color: var(--purple); }
.btn-purple:hover  { opacity: .88; }
.btn-orange  { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn-orange:hover  { opacity: .88; }
.btn-danger  { border-color: #f09595; color: var(--red); }
.btn-danger:hover  { background: var(--red-light); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 12px; line-height: 1.6; border: 1px solid; margin-bottom: 10px; }
.alert-success { background: var(--green-light); color: var(--green-dark); border-color: var(--green-mid); }
.alert-warn    { background: var(--amber-light); color: #633806; border-color: #ef9f27; }
.alert-danger  { background: var(--red-light); color: #791f1f; border-color: #f09595; }
.alert-info    { background: var(--blue-light); color: #185fa5; border-color: #85b7eb; }

/* Toggle switch */
.toggle { position: relative; width: 36px; height: 20px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.tg-track { position: absolute; inset: 0; border-radius: 10px; background: #e0e0e0; border: 1px solid var(--gray-line); transition: all .2s; }
.toggle input:checked + .tg-track { background: var(--green); border-color: var(--green); }
.tg-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.toggle input:checked ~ .tg-thumb { transform: translateX(16px); }

/* Chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 12px; border-radius: 20px; font-size: 12px;
  border: 1px solid var(--gray-line); cursor: pointer;
  color: var(--gray-mid); background: none; transition: all .15s; font-family: var(--font);
}
.chip:hover { border-color: var(--green); background: var(--green-light); color: var(--green-dark); }
.chip.on    { background: var(--green-light); border-color: var(--green); color: var(--green-dark); font-weight: 600; }

/* Photo upload grid */
.photo-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.photo-slot {
  aspect-ratio: 1; border-radius: var(--radius);
  border: 1px dashed var(--gray-line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-size: 11px; color: var(--gray-mid);
  cursor: pointer; background: var(--gray-bg);
  position: relative; overflow: hidden; transition: all .15s;
}
.photo-slot:hover { border-color: var(--green); background: var(--green-light); color: var(--green-dark); }
.photo-slot input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-slot.filled { border-style: solid; }
.photo-slot.filled img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 48px 20px;
  text-align: center; color: var(--gray-mid);
}
.empty-state .es-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .es-title { font-size: 15px; font-weight: 600; color: var(--gray-dark); margin-bottom: 6px; }
.empty-state .es-sub   { font-size: 13px; color: var(--gray-mid); margin-bottom: 16px; }

/* Bar chart */
.bar-row  { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.bar-lbl  { font-size: 11px; color: var(--gray-mid); width: 72px; text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; height: 8px; background: var(--gray-bg); border-radius: 4px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 4px; transition: width .5s; }
.bar-cnt   { font-size: 11px; color: var(--gray-mid); min-width: 24px; text-align: right; }

/* Timeline */
.tl-item { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f0f0ed; }
.tl-item:last-child { border-bottom: none; }
.tl-dot  { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.tl-title { font-size: 12px; color: var(--gray-dark); line-height: 1.4; }
.tl-sub   { font-size: 10px; color: var(--gray-mid); margin-top: 2px; }

/* Print styles */
@media print {
  .sidebar, .topbar, .new-repair-btn, .btn, button { display: none !important; }
  .main-content { overflow: visible; }
  .page-content  { padding: 0; background: #fff; }
  .card { border: 1px solid #ccc; box-shadow: none; page-break-inside: avoid; }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .page-content { padding: 10px; }
  .data-table th, .data-table td { padding: 7px 8px; font-size: 11px; }
}
