/* ============================================================
   pramern — style.css
   เขียนเอง ไม่มี framework · responsive มือถือ/แท็บเล็ต
   ============================================================ */

:root {
  --c-bg: #f4f6f9;
  --c-surface: #ffffff;
  --c-border: #dde3ea;
  --c-text: #1f2933;
  --c-muted: #667080;
  --c-primary: #1f6feb;
  --c-primary-dark: #1a5fce;
  --c-success: #1a7f4b;
  --c-success-bg: #e4f6ec;
  --c-error: #c0392b;
  --c-error-bg: #fdecea;
  --c-warn: #b8860b;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.topbar__brand { font-weight: 700; color: var(--c-text); }
.topbar__spacer { flex: 1; }
.topbar__user { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.topbar__role {
  background: var(--c-bg); color: var(--c-muted);
  padding: 2px 8px; border-radius: 999px; font-size: 0.8rem;
}
.topbar__toggle {
  display: none; background: none; border: none;
  font-size: 1.3rem; cursor: pointer; color: var(--c-text);
}

/* ---- shell + sidebar ---- */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: 12px 0;
}
.sidebar__menu { list-style: none; margin: 0; padding: 0; }
.sidebar__link {
  display: block; padding: 10px 20px; color: var(--c-text);
}
.sidebar__link:hover { background: var(--c-bg); text-decoration: none; }
.sidebar__link.is-active {
  background: #eaf1fd; color: var(--c-primary);
  border-left: 3px solid var(--c-primary); padding-left: 17px; font-weight: 600;
}
.sidebar__group {
  padding: 14px 20px 4px; font-size: 0.75rem; letter-spacing: .04em;
  color: var(--c-muted); text-transform: uppercase;
}

/* ---- content ---- */
/* min-width:0 จำเป็น — .content เป็น flex item ที่ min-width:auto โดยปริยาย ถ้าไม่ใส่
   คอลัมน์เนื้อหาจะขยายตามตารางที่กว้างกว่าจอ แทนที่จะให้ .table-wrap เลื่อนแนวนอน (ตารางล้นจอ) */
.content { flex: 1; min-width: 0; padding: 24px; max-width: 100%; }
.content--plain {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}

h1 { font-size: 1.5rem; margin: 0 0 20px; }
h2 { font-size: 1.2rem; margin: 24px 0 12px; }

/* ---- card ---- */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card--stat .card__num { font-size: 2rem; font-weight: 700; color: var(--c-primary); }
.card--stat .card__label { color: var(--c-muted); font-size: 0.9rem; }

/* ---- alert ---- */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.alert--success { background: var(--c-success-bg); color: var(--c-success); }
.alert--error { background: var(--c-error-bg); color: var(--c-error); }

/* ---- button ---- */
.btn {
  display: inline-block; padding: 9px 18px; border-radius: var(--radius);
  border: 1px solid transparent; background: var(--c-primary); color: #fff;
  font-size: 0.95rem; font-family: inherit; cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--c-primary-dark); text-decoration: none; }
.btn--sm { padding: 5px 12px; font-size: 0.85rem; }
.btn--ghost { background: transparent; color: var(--c-text); border-color: var(--c-border); }
.btn--ghost:hover { background: var(--c-bg); }
.btn--danger { background: var(--c-error); }
.btn--danger:hover { background: #a5311f; }
.btn--block { display: block; width: 100%; text-align: center; }

/* ---- form ---- */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.input, select, textarea {
  width: 100%; padding: 9px 12px; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  background: #fff; color: var(--c-text);
}
.input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px #1f6feb22;
}
.form-hint { font-size: 0.8rem; color: var(--c-muted); margin-top: 4px; }
.form-error { font-size: 0.85rem; color: var(--c-error); margin-top: 4px; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--c-surface); }
table.data th, table.data td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
table.data th { background: var(--c-bg); font-size: 0.85rem; color: var(--c-muted); }
table.data tr:hover td { background: #fafbfc; }

/* ---- badge ---- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; }
.badge--pending { background: #fff4e0; color: var(--c-warn); }
.badge--assigned { background: #eaf1fd; color: var(--c-primary); }
.badge--completed { background: var(--c-success-bg); color: var(--c-success); }
.badge--cancelled { background: #eee; color: var(--c-muted); }

/* ---- pagination ---- */
.pager { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span {
  padding: 6px 12px; border: 1px solid var(--c-border); border-radius: var(--radius);
  color: var(--c-text);
}
.pager .is-current { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* ---- login ---- */
.login-box { width: 100%; max-width: 360px; }
.login-box h1 { text-align: center; }

/* ---- responsive ---- */
@media (max-width: 820px) {
  .topbar__toggle { display: block; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 25;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 2px 0 8px #0002;
  }
  .sidebar.is-open { transform: translateX(0); }
  .content { padding: 16px; }
  .topbar__role { display: none; }
}

/* ---- print ---- */
@media print {
  .topbar, .sidebar, .btn, .pager { display: none !important; }
  .content { padding: 0; }
  .card { border: none; }
  body { background: #fff; }
}
