/* กิ้มเส็ง ค้าข้าว — CRM styling.
   Palette ported from the source design (oklch). */
:root {
  --app-bg:      oklch(0.965 0.008 255);
  --card-bg:     oklch(1 0 0);
  --text:        oklch(0.20 0.02 260);
  --text-2:      oklch(0.30 0.02 260);
  --muted:       oklch(0.48 0.02 255);
  --border:      oklch(0.88 0.012 255);
  --border-row:  oklch(0.90 0.012 255);
  --input-bg:    oklch(0.965 0.008 255);
  --input-border:oklch(0.82 0.02 255);
  --btn-border:  oklch(0.78 0.02 255);
  --primary:     oklch(0.62 0.16 255);
  --on-primary:  oklch(0.16 0.01 260);
  --danger:      oklch(0.62 0.19 25);
  --row-hover:   oklch(0.95 0.012 255);
  --sidebar-bg:  oklch(0.30 0.13 255);
  --sidebar-tx:  oklch(0.88 0.02 255);
  --sidebar-tx2: oklch(0.80 0.03 255);
  --sidebar-active: oklch(0.40 0.15 255);
  --sidebar-hover:  oklch(0.38 0.14 255);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Noto Sans Thai', 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  font-size: 15px;
  background: var(--app-bg);
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: oklch(0.75 0.02 255); border-radius: 4px; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: inherit; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--app-bg);
}
.login-card {
  width: 360px; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px;
}
.login-head { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; }
.login-title { font-weight: 700; font-size: 15px; }
.login-sub { font-size: 12px; color: var(--muted); }
.login-fields { display: flex; flex-direction: column; gap: 12px; }
.login-error { font-size: 12px; color: var(--danger); }
.login-hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; text-align: center; line-height: 1.5; }

/* Brand logo badge (CSS placeholder for the shop mark) */
.brand-badge {
  border-radius: 10px; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--on-primary); flex-shrink: 0;
}
.brand-badge.lg { width: 70px; height: 69px; font-size: 26px; }
.brand-badge.sm { width: 50px; height: 36px; font-size: 20px; border-radius: 8px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; background: var(--app-bg); }

.sidebar {
  width: 232px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid oklch(0.26 0.12 255);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 24px;
  color: var(--sidebar-tx);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.sidebar-brand .name { font-weight: 700; font-size: 14px; line-height: 1.3; }
.sidebar-brand .sub { font-size: 11px; color: var(--sidebar-tx2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; border: none; background: transparent;
  color: oklch(0.85 0.03 255); font-size: 14px; text-align: left; width: 100%;
}
.nav-item .ico { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.9; }
.nav-item:hover { background: var(--sidebar-hover); color: oklch(1 0 0); }
.nav-item.active { background: var(--sidebar-active); color: oklch(1 0 0); }

.sidebar-user {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; background: var(--sidebar-hover);
}
.sidebar-user .info { line-height: 1.3; overflow: hidden; flex: 1; }
.sidebar-user .info .n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .info .r { font-size: 11px; color: var(--sidebar-tx2); }
.sidebar-user .logout { background: transparent; border: none; color: var(--sidebar-tx2); font-size: 11px; padding: 4px; }
.sidebar-user .logout:hover { color: oklch(1 0 0); }

.avatar {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--on-primary); flex-shrink: 0;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; flex-shrink: 0; display: flex; align-items: center;
  justify-content: space-between; padding: 0 28px; border-bottom: 1px solid var(--border);
}
.topbar .title { font-size: 19px; font-weight: 700; }
.topbar .updated { font-size: 12px; color: var(--muted); }
.content { flex: 1; overflow-y: auto; padding: 28px; }

/* ---------- Cards & generic ---------- */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--muted); }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stat .val { font-size: 30px; font-weight: 700; }
.stat.today { border-left: 3px solid oklch(0.75 0.15 80); }
.stat.overdue { border-left: 3px solid oklch(0.62 0.19 25); }
.stat.unreachable { border-left: 3px solid oklch(0.60 0.02 260); }
.stat.closed { border-left: 3px solid oklch(0.70 0.15 145); }

.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.dash-left { display: flex; flex-direction: column; gap: 20px; }
.list-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 8px; border-bottom: 1px solid var(--border-row);
}
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { background: var(--row-hover); }
.list-row .primary { font-size: 13.5px; font-weight: 600; }
.list-row .secondary { font-size: 12px; color: var(--muted); }
.list-row .meta { font-size: 12px; color: var(--muted); }
.list-row .meta.due { color: var(--danger); }
.card-title.danger { color: var(--danger); }

.perf-item .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.perf-item .top .n { font-weight: 600; }
.perf-item .top .s { color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: oklch(0.92 0.012 255); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--primary); }
.perf-list { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; flex-wrap: wrap; }
.result-count { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.input, .select, .textarea {
  background: var(--card-bg); border: 1px solid var(--input-border); border-radius: 8px;
  padding: 10px 14px; color: var(--text); font-size: 13.5px;
}
.input.grow { flex: 1; min-width: 220px; }
.textarea { resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid oklch(0.62 0.16 255 / 0.4); outline-offset: 0; }

.btn {
  border: none; border-radius: 8px; padding: 10px 18px;
  color: var(--on-primary); font-weight: 600; font-size: 13.5px; background: var(--primary);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border: 1px solid var(--btn-border); color: var(--text-2); font-weight: 400; }
.btn.ghost:hover { filter: none; background: var(--row-hover); }
.btn.sm { padding: 5px 10px; font-size: 11.5px; }
.btn.block { display: block; }
.btn.danger { background: var(--danger); color: oklch(1 0 0); }
.btn.danger:hover { filter: brightness(1.05); }
.btn.danger.ghost { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn.danger.ghost:hover { background: oklch(0.62 0.19 25 / 0.08); filter: none; }

/* ---------- Customer table ---------- */
.table-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.cust-grid {
  display: grid;
  grid-template-columns: 76px minmax(0,1.5fr) 92px minmax(0,0.85fr) 82px 82px 108px 52px;
  gap: 6px; padding: 12px 14px; min-width: 920px; align-items: center;
}
.cust-head {
  font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.cust-row { border-bottom: 1px solid var(--border-row); font-size: 12.5px; }
.cust-row:hover { background: var(--row-hover); }
.cust-row .id { color: var(--muted); font-size: 11.5px; }
.cust-row .shop { font-weight: 600; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.dim { font-size: 11.5px; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; color: var(--on-primary); white-space: nowrap;
}
.pill.lg { padding: 5px 12px; font-size: 12px; }

/* ---------- Detail ---------- */
.back-link { background: transparent; border: none; color: var(--muted); font-size: 13px; margin-bottom: 16px; padding: 0; }
.back-link:hover { color: var(--text); }
.detail-cols { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; align-items: start; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.detail-head .shop { font-size: 19px; font-weight: 700; }
.detail-head .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 13px; }
.detail-grid .full { grid-column: 1 / 3; }
.field-label { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.detail-right { display: flex; flex-direction: column; gap: 16px; }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag-btn { border-radius: 999px; padding: 5px 12px; font-size: 12px; border: 1px solid var(--btn-border); background: transparent; color: var(--text-2); }
.tag-btn.on { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }

.collapse-head { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.timeline { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; overflow-y: auto; }
.timeline.contacts { max-height: 420px; }
.timeline.edits { max-height: 280px; gap: 12px; }
.tl-item { border-left: 2px solid var(--primary); padding-left: 12px; }
.tl-item.edit { border-left-color: var(--btn-border); }
.tl-item .when { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.tl-item .result { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.tl-item .note { font-size: 12.5px; color: var(--text-2); }
.tl-item .tags { font-size: 11.5px; color: var(--primary); margin-top: 3px; }
.tl-item .chg { font-size: 12.5px; margin-bottom: 2px; }

/* ---------- Users ---------- */
.users-toolbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 14px; }
.lock-note { font-size: 11.5px; color: var(--muted); }
.users-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 24px; }
.users-grid { display: grid; grid-template-columns: 1fr 0.9fr 0.9fr 1.6fr 160px; gap: 8px; padding: 13px 16px; align-items: center; font-size: 13px; }
.users-head { font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; padding: 12px 16px; }
.users-row { border-bottom: 1px solid var(--border-row); }
.users-row .who { display: flex; align-items: center; gap: 10px; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.audit-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.audit-grid { display: grid; grid-template-columns: 150px 1fr 1.4fr 1.4fr; gap: 8px; padding: 12px 16px; font-size: 12.5px; }
.audit-head { font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.audit-row { border-bottom: 1px solid var(--border-row); }

/* ---------- Modal / forms ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: oklch(0.25 0.05 255 / 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal { background: var(--card-bg); border: 1px solid var(--input-border); border-radius: 12px; padding: 26px; max-height: 85vh; overflow-y: auto; }
.modal.wide { width: 640px; }
.modal.narrow { width: 520px; }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-col { display: flex; flex-direction: column; gap: 12px; }
.field { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / 3; }
.field .input, .field .select, .field .textarea { font-size: 13px; padding: 9px 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.perm-list { display: flex; flex-direction: column; gap: 2px; }
.perm-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.perm-item:hover { background: var(--input-bg); }
.perm-item input { width: 16px; height: 16px; accent-color: var(--primary); }
.checkbox { width: 16px; height: 16px; accent-color: var(--primary); }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols { grid-template-columns: 1fr; }
  .detail-cols { grid-template-columns: 1fr; }
}
