:root {
  --red: #D6403E;
  --red-dark: #b3352f;
  --black: #0d0d0f;
  --bg: #f5f4f2;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e3df;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Prompt', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}

/* ---------- header ---------- */
.topbar {
  background: var(--black); color: #fff; display: flex; align-items: center;
  gap: 24px; padding: 10px 24px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; }
.brand-logo { height: 46px; width: auto; border-radius: 8px; background: #fff; padding: 2px 8px; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }
.brand-text { font-weight: 500; letter-spacing: 1px; color: var(--red); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-link { color: #d1d5db; text-decoration: none; padding: 8px 12px; border-radius: 8px; }
.nav-link:hover { background: #1f1f23; color: #fff; }
.nav-cta { background: var(--red); color: #fff; font-weight: 500; }
.nav-cta:hover { background: var(--red-dark); color: #fff; }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me-name { font-weight: 500; }
.me-role { color: #9ca3af; font-size: 12px; }

/* ---------- layout ---------- */
.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
.page-title { font-size: 22px; font-weight: 600; margin: 8px 0 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.card h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
.card h3 { font-size: 14px; margin: 14px 0 6px; }
.center-card { max-width: 480px; margin: 60px auto; text-align: center; }
.action-card { border-left: 4px solid var(--red); }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.stat-num { font-size: 24px; font-weight: 600; color: var(--black); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-danger { border-color: var(--red); }
.stat-danger .stat-num { color: var(--red); }
.stat-hero { grid-column: span 2; }
.meter { height: 8px; background: #edece8; border-radius: 6px; margin-top: 8px; overflow: hidden; }
.meter-fill { height: 100%; background: #2a78d6; border-radius: 6px; }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table td, .table th { padding: 8px 10px; text-align: left; vertical-align: top; }
.table-full thead th { border-bottom: 2px solid var(--border); font-weight: 600; font-size: 13px; color: var(--muted); }
.table tbody tr, .table tr { border-bottom: 1px solid var(--border); }
.table .num { text-align: right; font-weight: 600; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 12px 4px 0; white-space: nowrap; vertical-align: top; }
.kv td { padding: 4px 0; }

/* ---------- forms ---------- */
label { display: block; margin-bottom: 12px; font-weight: 500; font-size: 14px; }
input, select, textarea {
  width: 100%; padding: 9px 12px; margin-top: 5px; border: 1px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: 14px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(214,64,62,.35); border-color: var(--red); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.form-card { max-width: 720px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.req { color: var(--red); }
.chk { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.chk input { width: auto; margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; margin-top: 0; }

/* ---------- buttons & badges ---------- */
.btn { display: inline-block; border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-family: inherit; font-size: 14px; text-decoration: none; }
.btn-primary { background: var(--red); color: #fff; font-weight: 500; }
.btn-primary:hover { background: var(--red-dark); }
.btn-danger { background: #7f1d1d; color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--red); color: var(--red); }
.topbar .btn-ghost { color: #d1d5db; border-color: #3f3f46; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.badge { color: #fff; border-radius: 20px; padding: 3px 10px; font-size: 12px; white-space: nowrap; }
.badge-lg { font-size: 14px; padding: 6px 14px; }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- misc ---------- */
.link { color: var(--red-dark); font-weight: 500; text-decoration: none; }
.link:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.pre-inline { white-space: pre-wrap; }
.inline { display: inline; }
.flash { padding: 10px 16px; border-radius: 10px; margin-bottom: 14px; }
.flash-ok { background: #ecfdf3; color: #166534; border: 1px solid #bbe5c8; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #f3c6c6; }
/* ช่องรหัสผ่าน + ปุ่มกดค้างเพื่อดู */
.pwwrap { position: relative; display: block; }
.pwwrap input { padding-right: 42px; }
.pw-eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-42%);
  border: 0; background: transparent; cursor: pointer; font-size: 17px;
  padding: 4px 6px; border-radius: 6px; line-height: 1; user-select: none; -webkit-user-select: none;
}
.pw-eye:hover { background: #f0efec; }
.pw-eye:active { background: #e6e4df; }

.perm-table .perm-cell { text-align: center; }
.perm-table .perm-cell input { width: 18px; height: 18px; margin: 0; accent-color: var(--red); cursor: pointer; }
.perm-table .perm-role { text-align: center; font-size: 13px; }
.edit-row td { background: #fbfaf8; }
.edit-user-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 8px 0; }
.edit-user-form label { margin: 0; flex: 1 1 150px; font-size: 13px; }
.comment { border-top: 1px solid var(--border); padding: 10px 0; }
.comment-head { margin-bottom: 4px; }
.timeline { max-height: 420px; overflow-y: auto; }
.tl-item { border-left: 2px solid var(--red); padding: 4px 0 10px 12px; margin-left: 4px; }
.tl-time { color: var(--muted); font-size: 12px; }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #1a1a1e 0%, #000 70%);
}
.login-card {
  background: #101013; border: 1px solid #26262b; color: #e5e7eb; width: 380px; max-width: 92vw;
  border-radius: 16px; padding: 32px 32px 24px; text-align: center;
}
.login-logo { width: 190px; margin-bottom: 8px; border-radius: 10px; }
.login-card h1 { font-size: 20px; margin: 4px 0 2px; font-weight: 500; }
.login-card .muted { color: #9ca3af; }
.login-form { text-align: left; margin-top: 18px; }
.login-form input { background: #1a1a1f; border-color: #33333a; color: #fff; }
.login-card label { color: #d1d5db; }

/* ---------- stepper ความคืบหน้า ---------- */
.stepper-card { padding: 14px 20px; }
.stepper { display: flex; align-items: flex-start; gap: 4px; }
.step { display: flex; flex-direction: column; align-items: center; min-width: 58px; }
.step-dot {
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: #e5e3df; color: #6b7280; font-weight: 600; font-size: 14px;
}
.step.now .step-dot { background: var(--red); color: #fff; box-shadow: 0 0 0 4px rgba(214,64,62,.18); }
.step.done .step-dot { background: #1d7a4f; color: #fff; }
.step-name { font-size: 11px; color: var(--muted); margin-top: 5px; text-align: center; }
.step.now .step-name { color: var(--red); font-weight: 600; }
.step.done .step-name { color: #1d7a4f; }
.step-line { flex: 1; height: 3px; background: #e5e3df; margin-top: 14px; border-radius: 2px; min-width: 12px; }
.step-line.done { background: #1d7a4f; }
.next-msg { margin: 10px 0 0; font-size: 14px; }
.stat-link { display: block; text-decoration: none; color: inherit; }
.stat-link:hover { border-color: var(--red); }

/* ---------- mobile ---------- */
@media (max-width: 700px) {
  .card { overflow-x: auto; }                    /* ตารางกว้างเลื่อนแนวนอนได้ ไม่ล้นจอ */
  .topbar { padding: 8px 12px; gap: 10px; }
  .nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .nav-link { white-space: nowrap; padding: 10px 12px; }
  .me { margin-left: 0; width: 100%; justify-content: space-between; }
  .btn, .btn-sm { min-height: 44px; }            /* touch target ตามมาตรฐาน */
  .pw-eye { min-height: 36px; min-width: 40px; }
  .stepper { overflow-x: auto; }
}

/* ---------- responsive: ตาราง vs การ์ด ---------- */
.only-mobile { display: none; }
@media (max-width: 700px) {
  .only-desktop { display: none; }
  .only-mobile { display: block; }
}
.ticket-cards { display: flex; flex-direction: column; gap: 10px; }
.tcard { display: block; background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--red);
  border-radius: 10px; padding: 12px 14px; text-decoration: none; color: var(--text); }
.tcard-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.tcard-title { font-weight: 500; margin-bottom: 4px; }
