/* ==========================================================================
   Kenan Foundation Asia — IT Helpdesk
   Design tokens: deep navy chrome + light, high-contrast working surface
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design tokens — Apple-inspired (spec v4.0 หัวข้อ 9)
   แก้ค่าในบล็อกนี้ที่เดียว มีผลทั้งเว็บ
   -------------------------------------------------------------------------- */
:root {
  /* --- Surfaces: ขาว + เทาอ่อนของ apple.com --- */
  --bg:         #f5f5f7;
  --surface:    #ffffff;
  --surface-2:  #f5f5f7;
  --surface-3:  #fafafa;

  /* --- Type colours: ดำเข้มนวล ไม่ใช่ดำสนิท --- */
  --ink:        #1d1d1f;
  --ink-2:      #424245;
  --muted:      #6e6e73;

  /* --- Hairline borders เท่านั้น ห้ามหนา --- */
  --border:     #e5e5e7;
  --border-2:   #d2d2d7;

  /* --- Accent: น้ำเงิน Kenan ใช้อย่างประหยัด --- */
  --accent:      #2e6fe0;
  --accent-600:  #2461c9;
  --accent-300:  #a8c6f5;
  --accent-tint: #f0f5fe;

  /* --- Status: ลด saturation ให้ soft --- */
  --st-new:        #5b6fd6;
  --st-assigned:   #7b62c9;
  --st-progress:   #2e8fc4;
  --st-pending:    #bf8330;
  --st-resolved:   #2f9e7a;
  --st-closed:     #86868b;

  --danger:  #c9453f;
  --warn:    #bf8330;
  --ok:      #2f9e7a;

  /* --- Radius: การ์ดมน 12-16, ปุ่ม/input 8 --- */
  --radius:    14px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  /* --- Soft shadow เท่านั้น --- */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .04);
  --shadow:    0 2px 12px rgba(0, 0, 0, .06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, .12);

  /* --- Spacing scale: โปร่งขึ้นมากจากเดิม --- */
  --space-section: clamp(28px, 4vw, 56px);   /* padding ของ view */
  --space-card:    26px;                     /* padding ในการ์ด */
  --gap:           22px;

  --sidebar-w: 268px;
  --topbar-h:  72px;

  /* --- Motion: นิ่มนวล 200-300ms --- */
  --ease:      cubic-bezier(.4, 0, .2, 1);
  --t-fast:    200ms var(--ease);
  --t-base:    260ms var(--ease);

  --font: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text",
          "Noto Sans Thai", "IBM Plex Sans Thai", "Sarabun", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: -.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 590; letter-spacing: -.018em; line-height: 1.28; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-600); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* Bilingual secondary label — English leads, Thai follows in parentheses */
i, .th {
  font-style: normal;
  font-weight: 400;
  color: var(--muted);
  font-size: .92em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ==========================================================================
   Brand mark
   ========================================================================== */
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -.02em;
  flex: none;
}
.brand-mark--lg {
  width: 56px; height: 56px;
  border-radius: 16px;
  font-size: 27px;
}

/* โลโก้จริงขององค์กร — คลาส has-logo ถูกเติมโดย app.js ก็ต่อเมื่อโหลดไฟล์
   public/img/logo.png สำเร็จเท่านั้น ถ้าไม่มีไฟล์จะตกกลับไปใช้ตัวอักษร K เหมือนเดิม
   จึงไม่มีทางขึ้นรูปแตกให้ผู้ใช้เห็น */
.has-logo .brand-mark {
  background-color: transparent;
  background-image: url("/img/logo.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  color: transparent;      /* ซ่อนตัวอักษรที่อยู่ข้างใต้ */
  border-radius: 0;        /* โลโก้มีรูปทรงของตัวเองอยู่แล้ว ไม่ต้องครอบกรอบมน */
}

/* ==========================================================================
   Login
   ========================================================================== */
.login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  min-height: 100%;
}

.login__brand {
  background: var(--surface-2);
  color: var(--ink);
  padding: clamp(56px, 8vh, 96px) clamp(36px, 7vw, 96px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}
.login__brand h1 {
  font-size: clamp(38px, 4.8vw, 54px);
  font-weight: 600;
  letter-spacing: -.03em;
}
.login__org {
  font-size: 17px;
  color: var(--ink-2);
  line-height: 1.5;
}
.login__org span { color: var(--muted); font-size: 15px; }

.login__points {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 13px;
  max-width: 430px;
}
.login__points li {
  position: relative;
  padding-left: 30px;
  color: var(--ink-2);
  font-size: 15px;
}
.login__points li::before {
  content: "";
  position: absolute; left: 0; top: .58em;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.login__points span { display: block; color: var(--muted); font-size: 13.5px; }

.login__foot {
  margin-top: auto;
  padding-top: 34px;
  font-size: 13px;
  color: var(--muted);
}
.login__foot span { color: var(--border-2); }

.login__panel {
  display: grid;
  place-items: center;
  padding: 48px 24px;
  background: var(--bg);
}
.login__card {
  width: min(480px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 30px;
}
.login__card h2 { font-size: 22px; }
.login__hint {
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}
.login__list { display: grid; gap: 8px; max-height: 52dvh; overflow: auto; padding-right: 4px; }

.login__card code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .92em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}
.login__legal {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

/* Password field with a show/hide toggle */
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 62px; }
.pw-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.pw-toggle:hover { color: var(--accent-600); background: var(--accent-tint); }

/* Idle-session countdown shown in the top bar */
.idle-warn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: #fdf3e2;
  border: 1px solid #f6e2c0;
  color: #8a5a06;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.idle-warn svg { width: 14px; height: 14px; }

.person {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: border-color .14s, background .14s, transform .14s;
}
.person:hover {
  border-color: var(--accent-300);
  background: var(--accent-tint);
  transform: translateY(-1px);
}
.person__name { font-weight: 600; font-size: 14.5px; }
.person__meta { font-size: 12.5px; color: var(--muted); }

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-2) !important;
  color: #fff;
  font-weight: 650;
  font-size: 13.5px;
  flex: none;
  letter-spacing: .01em;
}
.avatar--sm { width: 30px; height: 30px; font-size: 11.5px; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app { display: flex; min-height: 100%; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  /* 100vh บน Safari มือถือ = ความสูงตอน address bar ยุบ ทำให้ sidebar ล้นจอ
     100dvh คือความสูงที่มองเห็นจริงในขณะนั้น (เบราว์เซอร์เก่าถอยไปใช้ 100vh) */
  height: 100vh;
  height: 100dvh;
  z-index: 40;
}

.sidebar__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar__title { display: grid; line-height: 1.3; min-width: 0; }
.sidebar__title strong { font-size: 15px; letter-spacing: -.012em; color: var(--ink); font-weight: 590; }
.sidebar__title span {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar__close {
  display: none;
  margin-left: auto;
  background: none; border: 0;
  color: var(--muted);
  font-size: 26px; line-height: 1;
  cursor: pointer;
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.sidebar__nav::-webkit-scrollbar { width: 8px; }
.sidebar__nav::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 8px;
}

.nav-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 22px 10px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: rgba(0,0,0,.04); }
.nav-item.is-active {
  background: var(--accent-tint);
  color: var(--accent-600);
  font-weight: 560;
}
.nav-item.is-active i { color: var(--accent); opacity: .85; }
.nav-item.is-active svg { opacity: 1; }
.nav-item svg { width: 18px; height: 18px; opacity: .55; }
.nav-item i { color: var(--muted); }
/* English on the first line, Thai underneath — keeps long bilingual labels readable */
.nav-item__text { min-width: 0; line-height: 1.3; }
.nav-item__text i { display: block; font-size: 11px; line-height: 1.35; }
.nav-item__count {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 650;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,.06);
  color: var(--ink-2);
}
.nav-item.is-active .nav-item__count { background: var(--accent); color: #fff; }

.nav-group { display: grid; }
.nav-group__toggle svg.chev {
  margin-left: auto;
  width: 15px; height: 15px;
  opacity: .4;
  transition: transform var(--t-fast);
}
.nav-group.is-open .nav-group__toggle svg.chev { transform: rotate(90deg); }
.nav-group__children { display: none; padding: 2px 0 6px 30px; }
.nav-group.is-open .nav-group__children { display: grid; }
.nav-sub {
  border: 0; background: none;
  text-align: left;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  line-height: 1.45;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-sub:hover { background: rgba(0,0,0,.04); color: var(--ink); }
.nav-sub i { display: block; color: var(--muted); font-size: 11.5px; }

.sidebar__user {
  border-top: 1px solid var(--border);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 11px;
}
.sidebar__user .who { min-width: 0; flex: 1; }
.sidebar__user .who strong {
  display: block;
  font-size: 13.5px; font-weight: 560; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar__user .who span { font-size: 11.5px; color: var(--muted); }
.sidebar__user button {
  background: none;
  border: 0;
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar__user button:hover { background: rgba(0,0,0,.06); color: var(--ink); }

.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.28);
  z-index: 35;
  backdrop-filter: blur(2px);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  height: var(--topbar-h);
  flex: none;
  background: rgba(255,255,255,.8);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 var(--space-section);
  position: sticky; top: 0;
  z-index: 30;
}
.topbar__title { min-width: 0; margin-right: auto; }
.topbar__title h1 {
  font-size: 21px;
  font-weight: 590;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__title p { font-size: 12.5px; color: var(--muted); line-height: 1.3; }

/* `.icon-btn` is declared later and also sets `display`, so scope this to win */
.topbar .topbar__menu { display: none; }
.topbar__menu span {
  display: block; width: 17px; height: 2px;
  background: var(--ink-2); border-radius: 2px; margin: 3px 0;
}

.search {
  position: relative;
  width: min(300px, 30vw);
}
.search__icon {
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 9px 12px 9px 35px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13.5px;
  transition: border-color .14s, background .14s, box-shadow .14s;
}
.search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(47,143,224,.14);
}
.search input::placeholder { color: var(--muted); }

.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--ink-2);
  cursor: pointer;
  flex: none;
  transition: background .13s, border-color .13s, color .13s;
}
.icon-btn:hover { background: var(--accent-tint); border-color: var(--accent-300); color: var(--accent-600); }
.icon-btn .badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--surface);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 520;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              opacity var(--t-fast), transform 120ms var(--ease);
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: var(--surface-2); border-color: var(--border-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Thai gloss stays legible on dark buttons */
.btn--primary i, .btn--accent i { color: rgba(255, 255, 255, .72); }

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn--primary:hover {
  background: var(--accent-600);
  border-color: transparent;
}
.btn--accent {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn--accent:hover { background: var(--accent-600); }
.btn--ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { padding: 6px 12px; font-size: 12.5px; border-radius: 6px; }
.btn--danger { color: var(--danger); border-color: #f0d5d4; background: var(--surface); }
.btn--danger:hover { background: #fdf5f5; }

/* ==========================================================================
   View / layout primitives
   ========================================================================== */
.view {
  padding: var(--space-section) var(--space-section) 96px;
  max-width: 1440px;
  width: 100%;
  animation: rise 320ms var(--ease);
}
/* scroll-reveal เบา ๆ ตาม spec — ใช้แต่พอดี ไม่รบกวนการทำงาน */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;          /* let wide tables scroll inside the card, not blow out the grid */
  overflow: hidden;
  transition: box-shadow var(--t-base);
}
.card__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px var(--space-card);
  border-bottom: 1px solid var(--border);
}
.card__head h2 { font-size: 17px; font-weight: 570; }
.card__head .spacer { margin-left: auto; }
.card__body { padding: var(--space-card); }

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.grid { display: grid; gap: var(--gap); }
.grid > * { min-width: 0; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.dash { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.dash > * { min-width: 0; }

/* ==========================================================================
   Stat cards
   ========================================================================== */
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px var(--space-card) 26px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
/* แถบสีบางที่ขอบบน แทนแถบข้างหนา ๆ แบบเดิม */
.stat::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--accent);
}
.stat--danger::before { background: var(--danger); }
.stat--warn::before   { background: var(--warn); }
.stat--ok::before     { background: var(--ok); }
.stat--navy::before   { background: var(--ink); }

.stat__label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 550;
  display: block;
  line-height: 1.4;
}
.stat__label i { font-size: 11.5px; }
.stat__value {
  font-size: 44px;
  font-weight: 300;
  letter-spacing: -.035em;
  line-height: 1.1;
  margin-top: 14px;
  font-variant-numeric: tabular-nums;
}
.stat__hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* ==========================================================================
   Pills / badges
   ========================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 520;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill--new       { color: var(--st-new);      background: #eef0fe; border-color: #dcdffc; }
.pill--assigned  { color: var(--st-assigned); background: #f2ecfd; border-color: #e6dcfb; }
.pill--progress  { color: #0784b8;            background: #e6f5fd; border-color: #cfeafb; }
.pill--pending   { color: #b3700d;            background: #fdf3e2; border-color: #f8e5c4; }
/* รอ vendor ภายนอก — สีม่วงอมเทา ต่างจาก Pending (ส้ม) อย่างเห็นได้ชัด
   เพราะสองสถานะนี้แปลว่า "รอคนละฝ่าย" และต้องแยกออกจากกันตั้งแต่กวาดตา */
.pill--vendor    { color: #6b4fa8;            background: #f3effc; border-color: #e4daf7; }
.pill--resolved  { color: var(--st-resolved); background: #e6f7f1; border-color: #cbeee1; }
.pill--closed    { color: var(--st-closed);   background: #eff2f6; border-color: #e0e6ee; }

.prio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.prio__dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.sla-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.sla-tag svg { width: 13px; height: 13px; }
.sla--ok       { color: var(--muted);  background: var(--surface-2); }
.sla--due_soon { color: #a86a06;       background: #fdf3e2; }
.sla--breached { color: #b32a38;       background: #fdeef0; }
.sla--met      { color: var(--ok);     background: #e6f7f1; }
.sla--none     { color: var(--muted);  background: var(--surface-2); }
/* หยุดนับ SLA — สีเดียวกับสถานะ "รอผู้ให้บริการภายนอก" ที่ทำให้มันหยุด
   จงใจไม่ใช้สีส้ม/แดง เพราะเรื่องกลุ่มนี้ไม่ได้ช้าและไม่มีใครต้องไปเร่ง */
.sla--paused   { color: #6b4fa8;       background: #f3effc; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}
.chip--flag { background: #fdeef0; border-color: #f5cfd5; color: #b32a38; font-weight: 600; }
.chip--internal { background: #fdf3e2; border-color: #f6e2c0; color: #a86a06; font-weight: 600; }

/* ==========================================================================
   Filter bar
   ========================================================================== */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
  margin-bottom: 16px;
}

/* กลุ่มปุ่มฝั่งขวาของแถบ filter (จำนวนรายการ + export + เพิ่มอุปกรณ์)
   ต้องยุบและตกบรรทัดได้เอง ไม่งั้นบนมือถือมันจะทะลุออกนอกกรอบ
   จนปุ่ม "เพิ่มอุปกรณ์" ถูกตัดหายไปนอกจอ */
.filters__actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-left: auto;
  min-width: 0;
}

@media (max-width: 700px) {
  /* จอแคบ: ให้กลุ่มปุ่มขึ้นบรรทัดใหม่เต็มความกว้าง แล้วชิดขวาตามเดิม */
  .filters__actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}
.select {
  appearance: none;
  padding: 8px 30px 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: 9px;
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236b8199'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E")
    no-repeat right 7px center / 16px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .14s, box-shadow .14s;
}
.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,143,224,.14); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.tab {
  border: 0; background: none;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .13s, color .13s;
}
.tab:hover { color: var(--ink); }
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 590; }

/* ==========================================================================
   Ticket table
   ========================================================================== */
.table-wrap { overflow-x: auto; max-width: 100%; }
table.tickets {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 820px;
}
/* Subject is the column people scan — give it room before anything else wraps */
table.tickets td:nth-child(2) { min-width: 280px; }
table.tickets th:last-child,
table.tickets td:last-child { width: 1%; white-space: nowrap; }

table.tickets--compact { min-width: 560px; }
table.tickets--compact td:nth-child(2) { min-width: 190px; }
table.tickets--compact th:last-child,
table.tickets--compact td:last-child { width: 1%; white-space: nowrap; }
table.tickets th {
  text-align: left;
  font-size: 11px;
  font-weight: 590;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
  position: sticky; top: 0;
}
table.tickets th:first-child { border-top-left-radius: var(--radius); }
table.tickets th:last-child  { border-top-right-radius: var(--radius); }
table.tickets td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.tickets tbody tr { cursor: pointer; transition: background var(--t-fast); }
table.tickets tbody tr:hover { background: var(--surface-2); }

/* ป้ายที่ใช้พื้นหลัง --surface-2 จะกลืนหายไปกับแถวตอน hover เพราะเป็นสี
   เดียวกันเป๊ะ (#f5f5f7) — ยกพื้นหลังเป็นสีขาวตอน hover ให้ยังเห็นเป็นป้ายอยู่ */
table.tickets tbody tr:hover .sla--ok,
table.tickets tbody tr:hover .sla--none,
table.tickets tbody tr:hover .chip:not([class*="chip--"]) { background: var(--surface); }
table.tickets tbody tr:last-child td { border-bottom: 0; }

.t-num {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--accent-600);
  font-weight: 550;
  white-space: nowrap;
}
.t-subject { font-weight: 540; color: var(--ink); line-height: 1.45; }
.t-sub-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.t-flag { color: var(--danger); width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; }
.t-who { display: flex; align-items: center; gap: 8px; }
.t-who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }

/* Card list on narrow screens */
.ticket-cards { display: none; gap: 10px; }
.tcard {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.tcard:hover { border-color: var(--accent-300); }
.tcard__top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.tcard__foot { display: flex; align-items: center; gap: 8px; margin-top: 9px; flex-wrap: wrap; }

/* ==========================================================================
   Empty / loading
   ========================================================================== */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}
.empty svg { width: 40px; height: 40px; opacity: .3; margin-bottom: 10px; }
.empty h3 { font-size: 16px; color: var(--ink-2); margin-bottom: 4px; }
.empty p { font-size: 13.5px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, #eef2f7 50%, var(--surface-2) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 8px;
  height: 56px;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ==========================================================================
   Forms
   ========================================================================== */
.form { display: grid; gap: 22px; }
/* align-content: start — ไม่ให้ input ยืดเต็มความสูงของ grid row
   ถ้าปล่อยให้ยืด ช่องที่ไม่มี help text ข้างล่างจะสูงกว่าและดูเหลื่อมกับช่องข้าง ๆ */
.field { display: grid; gap: 6px; align-content: start; }
.field > label {
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
}
.field > label .req { color: var(--danger); margin-left: 2px; }
.field .help { font-size: 12px; color: var(--muted); }

.input, textarea.input, select.input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { resize: vertical; min-height: 110px; line-height: 1.65; }
select.input {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236b8199'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 17px;
  cursor: pointer;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,111,224,.12);
}
.input::placeholder { color: #b0b0b5; }

/* align-items: start — สองช่องที่มี help text ยาวไม่เท่ากันต้องยังเรียงตรงกันด้านบน */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  align-items: start;
}

/* ช่องยืนยัน (checkbox) กินเต็มแถว — ข้อความเป็นประโยคที่ต้องอ่านจบ
   ไม่ใช่ชื่อช่องสั้น ๆ ที่วางคู่กันสองคอลัมน์แล้วยังอ่านง่าย */
.field--check { grid-column: 1 / -1; padding-top: 2px; }

/* Category / priority pickers */
.picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 9px; }
.pick {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border: 1px solid var(--border-2);
  border-radius: 11px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  line-height: 1.35;
  transition: border-color .14s, background .14s, box-shadow .14s;
}
.pick svg { width: 19px; height: 19px; color: var(--muted); }
.pick strong { display: block; font-weight: 600; font-size: 13.5px; }
.pick i { display: block; font-size: 11.5px; }
.pick:hover { border-color: var(--accent-300); background: var(--accent-tint); }
.pick.is-on {
  border-color: var(--accent);
  background: var(--accent-tint);
  box-shadow: 0 0 0 3px rgba(47,143,224,.13);
}
.pick.is-on svg { color: var(--accent-600); }

.prio-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.prio-pick {
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 6px;
  cursor: pointer;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  transition: border-color .14s, background .14s, box-shadow .14s;
}
.prio-pick .dot { width: 9px; height: 9px; border-radius: 50%; display: block; margin: 0 auto 5px; }
.prio-pick .hrs { display: block; font-size: 10.5px; font-weight: 500; color: var(--muted); margin-top: 1px; }
.prio-pick:hover { border-color: var(--accent-300); }
.prio-pick.is-on { border-color: currentColor; box-shadow: 0 0 0 3px rgba(47,143,224,.12); }

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--ink-2);
}
.checkbox input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent-600); cursor: pointer; }

.form-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.notice {
  display: flex;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  border: 1px solid;
}
.notice svg { width: 17px; height: 17px; margin-top: 2px; }
.notice--info  { background: var(--accent-tint); border-color: #cfe4f8; color: #185b96; }
.notice--warn  { background: #fdf3e2; border-color: #f6e2c0; color: #8a5a06; }
.notice--error { background: #fdeef0; border-color: #f5cfd5; color: #a5252f; }

/* ==========================================================================
   Ticket detail
   ========================================================================== */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }

.detail__head { margin-bottom: 16px; }
.detail__crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0 0 8px;
}
.detail__crumb:hover { color: var(--accent-600); }
.detail__crumb svg { width: 15px; height: 15px; }
.detail__title { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.detail__title h1 { font-size: 22px; line-height: 1.35; flex: 1; min-width: 260px; }
.detail__meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }

.desc {
  white-space: pre-wrap;
  line-height: 1.72;
  color: var(--ink-2);
  font-size: 14.5px;
}

.kv { display: grid; gap: 11px; }
.kv__row { display: grid; grid-template-columns: 106px minmax(0, 1fr); gap: 10px; align-items: start; }
.kv__k { font-size: 12px; color: var(--muted); font-weight: 550; line-height: 1.5; padding-top: 2px; }
.kv__v { font-size: 13.5px; color: var(--ink); line-height: 1.5; word-break: break-word; }
/* Thai gloss always sits on its own line inside key/value pairs */
.kv__k i, .kv__v i { display: block; font-size: 11.5px; line-height: 1.4; }

/* Timeline */
.timeline { display: grid; gap: 0; position: relative; }
.tl {
  position: relative;
  padding: 0 0 20px 26px;
  border-left: 2px solid var(--border);
  margin-left: 7px;
}
.tl:last-child { border-left-color: transparent; padding-bottom: 0; }
.tl::before {
  content: "";
  position: absolute; left: -7px; top: 3px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-2);
}
.tl--status::before { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.tl__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.tl__who { font-weight: 600; }
.tl__time { font-size: 12px; color: var(--muted); }
.tl__note { font-size: 13px; color: var(--ink-2); margin-top: 3px; }

/* Comments */
.comment {
  display: flex;
  gap: 11px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.comment:last-of-type { border-bottom: 0; }
.comment--internal {
  background: #fffcf5;
  margin: 0 -18px;
  padding: 14px 18px;
  border-left: 3px solid #f0c265;
}
.comment__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.comment__name { font-weight: 620; font-size: 13.5px; }
.comment__time { font-size: 12px; color: var(--muted); }
.comment__body { white-space: pre-wrap; line-height: 1.68; font-size: 14px; color: var(--ink-2); }

.att-list { display: grid; gap: 8px; }
.att {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 13px;
}
.att svg { color: var(--muted); width: 17px; height: 17px; }
.att .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.att .size { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

/* ==========================================================================
   Bars / mini charts
   ========================================================================== */
.bars { display: grid; gap: 11px; }
.bar__top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; gap: 10px; }
.bar__top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar__track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar__fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .5s ease; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 62px; }
.spark__bar {
  flex: 1;
  background: linear-gradient(180deg, var(--accent-300), var(--accent));
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  transition: opacity .13s;
}
.spark__bar:hover { opacity: .75; }
.spark-axis { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: 6px; }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
  animation: fade var(--t-base);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal__box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(680px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  animation: pop var(--t-base);
}
.modal__box--wide { width: min(880px, 100%); }
/* slide + fade ผสมกันตาม spec ข้อ 4 */
@keyframes pop { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
}
.modal__head h2 { font-size: 19px; font-weight: 570; }
.modal__head p { font-size: 12.5px; color: var(--muted); }
.modal__x {
  margin-left: auto;
  background: none; border: 0;
  font-size: 24px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 8px;
}
.modal__x:hover { background: var(--surface-2); color: var(--ink); }
.modal__body { padding: 28px; overflow-y: auto; }
.modal__foot {
  padding: 18px 28px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toasts {
  position: fixed;
  bottom: 20px; right: 20px;
  display: grid;
  gap: 9px;
  z-index: 80;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--ink);
  color: #fff;
  padding: 12px 15px;
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  line-height: 1.5;
  animation: slidein .22s cubic-bezier(.2,.9,.3,1.05);
}
.toast svg { width: 17px; height: 17px; margin-top: 2px; flex: none; }
.toast--ok svg { color: #3ddba9; }
.toast--err { background: #7d1d27; }
.toast i { color: rgba(255,255,255,.62); display: block; }
@keyframes slidein { from { transform: translateX(22px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==========================================================================
   Admin
   ========================================================================== */
table.plain { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.plain th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 590;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.plain td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.plain tbody tr:last-child td { border-bottom: 0; }
table.plain tbody tr:hover { background: var(--surface-2); }

.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* Notification list */
.notif {
  display: flex;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.notif:last-child { border-bottom: 0; }
.notif__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex: none; }
.notif__dot--read { background: var(--border-2); }
.notif__body { min-width: 0; flex: 1; }
.notif__subject { font-weight: 600; font-size: 13.5px; line-height: 1.45; }
.notif__msg { font-size: 13px; color: var(--ink-2); white-space: pre-wrap; margin-top: 2px; }
.notif__meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
/* ==========================================================================
   Asset photos (spec ข้อ 10.2.1)
   ========================================================================== */
.photos {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.photo {
  position: relative;
  margin: 0;
  width: 108px;
  height: 108px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  transition: transform var(--t-fast);
}

.photo img[data-view]:hover { transform: scale(1.04); }

/* ปุ่มลบอยู่มุมขวาบนของรูป — พื้นหลังทึบเพราะรูปข้างใต้เป็นสีอะไรก็ได้ */
.photo__x {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--t-fast);
}

.photo__x:hover { background: rgba(0, 0, 0, .78); }

.photo__cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 6px;
  font-size: 10.5px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  text-align: center;
}

.photos__actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* .photos ว่าง ๆ ไม่ควรกินที่ ปุ่มเลือกรูปจะได้ขยับขึ้นมาชิดหัวข้อ */
.photos:empty { display: none; }

/* หัวการ์ดรูปภาพมีทั้งหัวข้อสองภาษา ตัวนับ และปุ่ม — ให้ตกบรรทัดได้เมื่อจอแคบ
   แทนที่จะบีบหัวข้อจนคำภาษาไทยขาดกลางคำ */
.card__head--photos { flex-wrap: wrap; row-gap: 8px; }
.card__head--photos h2 { flex: 0 1 auto; }

/* ดูรูปเต็มในกล่อง modal */
.lightbox {
  display: grid;
  place-items: center;
  background: var(--surface-2);
  min-height: 240px;
}

.lightbox img {
  max-width: 100%;
  max-height: 70dvh;
  border-radius: var(--radius-sm);
}

/* รูปย่อในตารางทะเบียนอุปกรณ์ */
.t-equip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.t-equip .t-subject,
.t-equip .t-sub-meta { display: block; }

.thumb {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.thumb--none {
  display: grid;
  place-items: center;
  color: var(--border-2);
}

.thumb--none svg { width: 18px; height: 18px; }

/* รูปในการ์ด (จอแคบ) ใหญ่กว่าในตารางได้ เพราะมีที่ว่างมากกว่า */
.thumb--lg { width: 52px; height: 52px; border-radius: 9px; }
.thumb--lg.thumb--none svg { width: 24px; height: 24px; }
.tcard .t-equip { margin-top: 2px; }

/* ==========================================================================
   Edit asset — ช่องอ่านอย่างเดียว · แบนเนอร์เตือน · ประวัติการแก้ไข (spec 10.7)
   ========================================================================== */
/* ช่องที่แก้ไม่ได้ — หน้าตาเหมือน .input แต่พื้นเทาและไม่มี border ให้เข้าใจผิดว่าคลิกได้ */
.readonly {
  padding: 10px 12px;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--ink-2);
}

.readonly i { color: var(--muted); font-size: 12.5px; font-style: normal; }

/* ป้าย "แก้ไม่ได้" ข้าง label — มี title อธิบายเหตุผลเมื่อ hover */
.lock {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 7px;
  padding: 1px 7px 1px 5px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 450;
  cursor: help;
}

.lock svg { width: 11px; height: 11px; }

/* ปุ่มที่หน้าตาเป็นลิงก์ — ใช้ในบรรทัด help ที่ไม่ควรมีปุ่มเต็มตัว */
.linkbtn {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.linkbtn:hover { color: var(--accent-600); }

/* แบนเนอร์เตือนในฟอร์ม (เช่น ปลดระวางทั้งที่ยังมีผู้ถือครอง) */
.banner {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: var(--gap);
}

.banner strong { display: block; font-weight: 560; margin-bottom: 2px; }
.banner svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }

.banner--warn {
  background: #fdf6ec;
  color: #7a5316;
}

.banner--warn svg { color: var(--warn); }

/* ประวัติการแก้ไข */
.edits { display: grid; gap: 2px; }

.edit {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 4px 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.edit:last-child { border-bottom: 0; }

.edit__field { font-size: 13px; font-weight: 520; color: var(--ink); }
.edit__field i { display: block; color: var(--muted); font-size: 11.5px; font-style: normal; }

.edit__diff {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

/* ค่าเดิม/ค่าใหม่ ต้องอ่านออกว่าอันไหนคืออันไหนโดยไม่ต้องพึ่งสีอย่างเดียว
   (ค่าเดิมขีดฆ่า ค่าใหม่ตัวหนา) เผื่อผู้ใช้ตาบอดสี */
.diff {
  font-size: 13.5px;
  padding: 2px 8px;
  border-radius: 6px;
  word-break: break-word;
}

.diff--old { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.diff--new { background: var(--accent-tint); color: var(--ink); font-weight: 540; }
.diff__arrow { color: var(--muted); font-size: 13px; }
.diff__empty { font-style: italic; opacity: .75; }

.edit__who { grid-column: 2; font-size: 12px; color: var(--muted); }

@media (max-width: 700px) {
  .edit { grid-template-columns: 1fr; }
  .edit__who { grid-column: 1; }
}

/* ==========================================================================
   LINE Login (spec ข้อ 8.7)
   ========================================================================== */
/* เส้นคั่น "หรือ" ระหว่างฟอร์ม LDAP กับปุ่ม LINE */
.login__alt { margin-top: 22px; }

.login__or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12.5px;
}

.login__or::before,
.login__or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* สีเขียว LINE ตาม brand guideline แต่มุมมน/เงา/ตัวอักษรตามดีไซน์ของเว็บ
   เพื่อไม่ให้ดูเป็นปุ่มแปลกปลอมที่แปะเข้ามา */
.btn--line {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 15px;
  background: #06c755;
  border-color: #06c755;
  color: #fff;
  text-decoration: none;
}

.btn--line:hover { background: #05b34c; border-color: #05b34c; }
.btn--line i { color: rgba(255, 255, 255, .82); }
.btn__line-icon { width: 20px; height: 20px; flex: none; }

/* การ์ดบัญชี LINE ในหน้าโปรไฟล์ */
.line-card { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.line-card__avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex: none;
}

.line-card__who { min-width: 0; flex: 1; }
.line-card__who strong { display: block; font-size: 14.5px; color: var(--ink); }
.line-card__who span { font-size: 12.5px; color: var(--muted); }

/* ==========================================================================
   iOS / อุปกรณ์ touch — 5 เรื่องที่ต้องแก้เฉพาะทาง
   ========================================================================== */

/* --- 4. กันกล่องเทาแวบตอนแตะ ---------------------------------------------
   Safari/Chrome บนมือถือวาดกล่องไฮไลต์ทับ element ที่แตะ ซึ่งชนกับสไตล์ปุ่มของเรา
   ปิดทิ้งแล้วไปทำ feedback เองด้วย :active ข้างล่างแทน (ห้ามปิดเฉย ๆ
   โดยไม่มีอะไรมาแทน ไม่งั้นผู้ใช้จะไม่รู้ว่ากดติดหรือยัง) */
a, button, label, summary,
input, select, textarea,
.btn, .choice, .tcard, .icon-btn, .tab, .linkbtn, .photo img {
  -webkit-tap-highlight-color: transparent;
}

/* --- 2. Safe area (จอมีรอยบาก / แถบ home indicator) -----------------------
   index.html ตั้ง viewport-fit=cover ไว้ เนื้อหาจึงกินพื้นที่เต็มจอรวมส่วนที่ถูกบัง
   ต้องเว้นระยะกลับด้วย env() เอง ไม่งั้นแถบบนไปอยู่ใต้รอยบาก และปุ่มล่างสุด
   ไปอยู่ใต้แถบ home indicator จนกดไม่โดน
   (env() บนเบราว์เซอร์ที่ไม่รองรับจะได้ค่า fallback 0px — ไม่กระทบ desktop) */
.topbar {
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}

.sidebar {
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

.view {
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(var(--space-section) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--space-section) + env(safe-area-inset-right, 0px));
}

.toasts {
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
}

.modal__foot {
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

/* --- 1 + 3 + 4. เฉพาะเครื่องที่ใช้นิ้วเป็นหลัก ---------------------------- */
@media (pointer: coarse) {

  /* 1. Safari บน iOS ซูมหน้าจอเข้าเองทุกครั้งที่แตะช่องกรอกที่ฟอนต์เล็กกว่า 16px
        แล้วไม่ซูมกลับ ทำให้ฟอร์มยาว ๆ ใช้งานทรมานมาก — 16px คือค่าต่ำสุดที่กันได้
        (แก้ที่ฟอนต์ ไม่ใช่ใส่ maximum-scale=1 ใน viewport เพราะนั่นจะปิดการซูม
        ด้วยนิ้วของผู้ใช้ไปด้วย ซึ่งเป็นปัญหาด้าน accessibility) */
  .input,
  textarea.input,
  select.input,
  .select,
  .search input,
  input[type="file"] {
    font-size: 16px;
  }

  /* 3. พื้นที่กดขั้นต่ำ 44×44 pt ตามแนวทางของ Apple */
  .icon-btn { width: 44px; height: 44px; }
  .sidebar__close { width: 44px; height: 44px; }
  /* flex: none จำเป็น — .modal__head เป็น flex container ปุ่มจะถูกบีบแคบกว่า
     width ที่ตั้งไว้ถ้าไม่ห้าม */
  .modal__x { width: 44px; height: 44px; flex: none; display: grid; place-items: center; }
  .tab { padding: 11px 15px; }
  .btn { min-height: 44px; }
  .btn--sm { min-height: 44px; }
  .nav__item { min-height: 44px; }
  .sidebar__user button { width: 44px; height: 44px; }

  /* ปุ่มแจ้งปัญหาบนแถบบนย่อเหลือแค่ไอคอนที่จอแคบ ต้องกว้างพอให้กดโดน */
  .topbar__new { min-width: 44px; justify-content: center; }

  /* ปุ่มลบรูปอยู่บนรูปย่อ 108px — ขยายปุ่มจริงจะบังรูปเกินไป
     จึงขยายเฉพาะ "พื้นที่กด" ด้วย pseudo-element แทน หน้าตาเท่าเดิม */
  .photo__x::after {
    content: '';
    position: absolute;
    inset: -7px;
  }

  /* 4. feedback ตอนแตะ มาแทนกล่องไฮไลต์ที่ปิดไป */
  .btn:active,
  .icon-btn:active,
  .tab:active,
  .linkbtn:active { opacity: .6; }

  .choice:active,
  .tcard:active {
    background: var(--surface-2);
    transform: scale(.995);
  }

  tr[data-id]:active,
  tr[data-asset]:active { background: var(--surface-2); }
}

@media (max-width: 1180px) {
  /* give the page title room back before it starts truncating */
  .search { width: min(210px, 22vw); }
  .topbar__title h1 { font-size: 17px; }
}

@media (max-width: 1080px) {
  .dash { grid-template-columns: minmax(0, 1fr); }
  .detail { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login__brand { padding: 44px 28px 34px; }
  .login__points { display: none; }
  .login__foot { display: none; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.3,.9,.3,1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .sidebar__close { display: grid; place-items: center; }
  .topbar .topbar__menu { display: grid; }
  .search { width: auto; flex: 1; min-width: 0; }
  .topbar__title { display: none; }
  .topbar__new span i { display: none; }
  /* เขียน env() ซ้ำตรงนี้ด้วย เพราะ shorthand จะล้างค่าที่ตั้งไว้ก่อนหน้าทิ้ง
     และจอแคบคืออุปกรณ์ที่มีรอยบาก/แถบ home indicator จริง ๆ */
  .view {
    padding: 18px calc(15px + env(safe-area-inset-right, 0px))
             calc(48px + env(safe-area-inset-bottom, 0px))
             calc(15px + env(safe-area-inset-left, 0px));
  }
  table.tickets { display: none; }
  .ticket-cards { display: grid; }
  .field-row { grid-template-columns: 1fr; }
  .kv__row { grid-template-columns: 96px minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .topbar {
    /* shorthand ตรงนี้จะล้าง padding-top ที่กัน notch ไว้ — ต้องใส่กลับ */
    padding: env(safe-area-inset-top, 0px) 13px 0;
    gap: 9px;
  }
  .topbar__new span { display: none; }
  .topbar__new { padding: 9px 11px; }
  .prio-picker { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 0; align-items: flex-end; }
  .modal__box { max-height: 94dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; width: 100%; }
  .toasts {
    left: calc(14px + env(safe-area-inset-left, 0px));
    right: calc(14px + env(safe-area-inset-right, 0px));
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
}

@media print {
  .sidebar, .topbar, .toasts, .btn { display: none !important; }
  .view { padding: 0; }
  .card { box-shadow: none; }
}

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

/* ==========================================================================
   Asset Management
   ========================================================================== */

/* Selectable list used by the assign / return flows */
.pick-list { display: grid; }
.pick-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px var(--space-card);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--t-fast);
}
.pick-row:last-child { border-bottom: 0; }
.pick-row:hover { background: var(--surface-2); }
.pick-row input[type="checkbox"] {
  width: 19px; height: 19px;
  accent-color: var(--accent);
  flex: none;
  cursor: pointer;
}
.pick-row__main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.pick-row__main strong { font-weight: 540; font-size: 14.5px; }
.pick-row__main span { font-size: 12.5px; color: var(--muted); }

/* Return rows carry an extra condition field on a second line */
.pick-row--return { flex-wrap: wrap; cursor: default; }
.pick-row--return:hover { background: none; }
.pick-row__extra {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding-left: 33px;
}
.pick-row__extra .input { flex: 1; padding: 8px 11px; font-size: 13px; }

/* Two-up choice cards (print vs sign on screen) */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.choice {
  display: grid;
  gap: 8px;
  padding: 22px 20px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), transform 120ms var(--ease);
}
.choice:hover { border-color: var(--accent); background: var(--accent-tint); transform: translateY(-1px); }
.choice svg { width: 22px; height: 22px; color: var(--accent); }
.choice strong { font-weight: 550; font-size: 14.5px; }
.choice span { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

/* ตัวเลือกหลัก — "เซ็นบนหน้าจอ" คือวิธีที่ใช้จริงเกือบทุกครั้ง (spec ข้อ 10.3)
   จึงเป็นปุ่มเต็มความกว้างสีเน้น ไม่ใช่หนึ่งในสองตัวเลือกที่เด่นเท่ากัน */
.choice--primary {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent-tint);
  box-shadow: 0 0 0 3px rgba(46, 111, 224, .08);
}

.choice--primary:hover { background: #e7f0fd; }
.choice--primary strong { color: var(--accent-600); font-size: 15.5px; }

/* ทางเลือกสำรอง — ลดระดับเป็นลิงก์ข้อความ ไม่ให้แข่งสายตากับปุ่มหลัก */
/* ตัวเลือกแบบ checkbox + ข้อความในบรรทัดเดียว (พื้นที่กดครอบทั้งบรรทัด) */
.checkline {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.5;
  cursor: pointer;
  min-height: 44px;
  padding: 4px 0;
}
.checkline input { width: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--accent); }

.fallback {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
}

/* Signature canvas */
.sigpad {
  position: relative;
  height: 220px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.sigpad canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;      /* กันหน้าจอเลื่อนขณะวาดด้วยนิ้ว */
  cursor: crosshair;
}
.sigpad__hint {
  position: absolute;
  inset: 0;
  /* flex ไม่ใช่ grid — ไม่งั้นข้อความไทยในวงเล็บจะกลายเป็น grid item แล้วตกลงมาคนละบรรทัด */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--border-2);
  font-size: 15px;
  pointer-events: none;
}
.sigpad__hint i { color: inherit; opacity: .85; }
.sigpad__baseline {
  position: absolute;
  left: 32px; right: 32px; bottom: 46px;
  border-bottom: 1px dashed var(--border-2);
  pointer-events: none;
}

@media (max-width: 700px) {
  .choice-grid { grid-template-columns: 1fr; }
  .pick-row__extra { padding-left: 0; flex-wrap: wrap; }
}

/* ---------------------------------------------------------------- import */
/* ตารางตรวจทานก่อนนำเข้า — แถวที่ผิดต้องสะดุดตาทันทีโดยไม่ต้องอ่านทีละบรรทัด */
.imp-table td { vertical-align: top; }
.imp-line { color: var(--muted); font-variant-numeric: tabular-nums; }

.imp-row--error   { background: color-mix(in srgb, var(--danger) 7%, transparent); }
.imp-row--muted   { opacity: .62; }

.imp-chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--ink);
}
.imp-chip--ok    { background: color-mix(in srgb, var(--ok) 16%, transparent);
                   color: var(--ok); }
.imp-chip--warn  { background: color-mix(in srgb, var(--warn) 18%, transparent);
                   color: var(--warn); }
.imp-chip--error { background: color-mix(in srgb, var(--danger) 14%, transparent);
                   color: var(--danger); }
.imp-chip--muted { color: var(--muted); }

.imp-msg {
  margin-top: 4px; font-size: 12.5px; line-height: 1.45; color: var(--muted);
}
.imp-msg--error { color: var(--danger); }

/* ช่องค้นหาในฟอร์ม (มอบอุปกรณ์ / รับคืน) — เต็มความกว้างการ์ด ไม่ใช่ 300px
   แบบช่องค้นหาบนแถบหัวเรื่อง */
.search--wide { width: 100%; }
.search--wide input { background: var(--bg); }

.pick-empty {
  padding: var(--space-card);
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}

/* ---------------------------------------------------------- SLA progress */
/* แถบบางแสดงว่าใช้เวลาในกรอบ SLA ไปแล้วเท่าไหร่ — เปอร์เซ็นต์มาจาก server
   ที่นับเฉพาะเวลาทำการ ฝั่งนี้แค่วาดตาม */
.slabar {
  height: 5px;
  margin-top: 7px;
  width: 92px;                 /* ในตาราง: พอเห็นสัดส่วน ไม่ดันคอลัมน์ให้กว้าง */
  max-width: 100%;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.slabar--wide { width: 100%; margin-top: 12px; }

.slabar__fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width var(--t-base), background var(--t-fast);
}
.slabar__fill--ok   { background: var(--accent); }
.slabar__fill--warn { background: var(--warn); }
.slabar__fill--over { background: var(--danger); }

/* บนแถวที่ hover พื้นหลังเป็น --surface-2 ซึ่งใกล้กับ --border ของราง
   ยกรางให้เข้มขึ้นนิดเพื่อให้ยังเห็นขอบแถบชัด */
table.tickets tbody tr:hover .slabar { background: var(--border-2); }

@media (prefers-reduced-motion: reduce) {
  .slabar__fill { transition: none; }
}

/* ------------------------------------------------------- asset timeline */
/* จุดบนไทม์ไลน์บอกชนิดเหตุการณ์ด้วยสี — มอบ/รับคืน/แก้ไขข้อมูล
   ใช้สีจาก token เดิมทั้งหมด ไม่เพิ่มสีใหม่เข้ามาในระบบ */
.tl--assign::before { border-color: var(--accent);   background: var(--accent); }
.tl--return::before { border-color: var(--border-2); background: var(--surface); }
.tl--edit::before   { border-color: var(--warn);     background: var(--surface); }

/* เหตุการณ์ล่าสุดอยู่บนสุดและเด่นกว่าเล็กน้อย — ใหญ่ขึ้นพร้อมวงแหวนรอบจุด */
.tl--latest::before {
  width: 14px; height: 14px;
  left: -8px; top: 2px;
  box-shadow: 0 0 0 4px var(--accent-tint);
}
.tl--latest.tl--edit::before   { box-shadow: 0 0 0 4px #fdf3e2; }
.tl--latest.tl--return::before { box-shadow: 0 0 0 4px var(--surface-2); }

.tl__when { color: var(--muted); }

/* แถบปุ่มบนหน้ามอบอุปกรณ์ — อยู่บนสุดและติดหนึบตอนเลื่อน
   รายการอุปกรณ์ยาวหลายร้อยชิ้น ถ้าปุ่มเลื่อนหายไปกับหน้าก็ต้องเลื่อนกลับมาหาอยู่ดี */
.form-actions--sticky {
  position: sticky;
  /* จอดใต้ topbar พอดี — topbar เป็น sticky top:0 z-index:30 อยู่แล้ว
     ถ้าตั้ง top:0 เหมือนกัน แถบนี้จะมุดไปอยู่ใต้ topbar แล้วมองไม่เห็นตอนเลื่อน */
  top: calc(var(--topbar-h) + 10px);
  z-index: 20;
  margin: calc(var(--space-section) * -0.5) 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  box-shadow: var(--shadow-sm);
}
.form-actions--sticky .spacer { flex: 1; }

/* เบราว์เซอร์ที่ไม่รองรับ backdrop-filter ต้องได้พื้นทึบ ไม่ใช่พื้นโปร่งจนอ่านไม่ออก */
@supports not (backdrop-filter: blur(1px)) {
  .form-actions--sticky { background: var(--surface); }
}

@media (max-width: 720px) {
  .form-actions--sticky {
    padding: 9px 10px;
    gap: 8px;
    /* topbar บนมือถือสูงขึ้นตาม safe-area ของรอยบาก แถบนี้ต้องขยับตามด้วย
       ไม่งั้นบน iPhone จะไปซ้อนใต้ topbar เหมือนเดิม */
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 8px);
  }
  /* ตัว spacer แย่งพื้นที่จนปุ่มตกบรรทัดคนละอัน แถบเลยสูงกินจอไปเปล่า ๆ
     บนจอแคบให้ปุ่มสองอันอยู่แถวเดียวกัน ตัวนับขึ้นบรรทัดบนแบบบาง ๆ */
  .form-actions--sticky .spacer { display: none; }
  .form-actions--sticky #asCountTop {
    width: 100%;
    text-align: center;
    padding: 3px 8px;
    font-size: 12px;
  }
  .form-actions--sticky .btn { flex: 1; justify-content: center; }
}


/* ฟอร์มหลายช่องแบบสองคอลัมน์ (หน้า Admin → Users) — ยุบเป็นคอลัมน์เดียวบนจอแคบ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0 18px;
}
