/*
  ดีไซน์ตาม BPM_UI_UX_GUIDELINES.md — palette/สไตล์นี้ต้องคงไว้ทุกหน้าที่เพิ่มทีหลัง
  ไฟล์นี้เป็น base เท่านั้น (login/error/pending-access) หน้าโมดูลหลัก (dashboard ฯลฯ) จะขยายเพิ่มทีหลัง
*/

:root {
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --border-subtle: #E2E8F0;
  --sidebar-bg: #0F172A;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;

  --status-success-bg: #ECFDF5;
  --status-success-text: #047857;
  --status-warning-bg: #FFFBEB;
  --status-warning-text: #B45309;
  --status-danger-bg: #FEF2F2;
  --status-danger-text: #B91C1C;

  --accent: #1E3A8A; /* ปุ่ม primary — น้ำเงินเข้ม/กรมท่า ตามคู่มือ */
  --accent-hover: #172554;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: 'Noto Sans Thai', 'Prompt', system-ui, sans-serif;
}

a { color: var(--accent); }

.text-muted { color: var(--text-secondary); }
.small { font-size: 0.85rem; }

.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 36px 32px;
}

.login-card h1 {
  font-family: 'Prompt', sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 12px;
}

.login-card p { line-height: 1.6; margin: 0 0 20px; }

.btn {
  display: block;
  text-align: center;
  text-decoration: none;
  font-family: 'Prompt', sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 12px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-block { width: 100%; }

.btn-primary {
  background: var(--accent);
  color: #F8FAFC;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}

.alert {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.alert-warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.alert-danger  { background: var(--status-danger-bg);  color: var(--status-danger-text); }
.alert-success { background: var(--status-success-bg); color: var(--status-success-text); }

/* ============================================================
   App shell — sidebar + header ใช้ร่วมกันทุกหน้าที่ login แล้ว
   ============================================================ */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  flex: none;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 26px; }
.sidebar-brand .mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.sidebar-brand .mark svg { color: #EFF6FF; }
.sidebar-brand .name { font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 15px; color: #F8FAFC; line-height: 1.2; }
.sidebar-brand .sub { font-size: 11px; color: #7C8AA8; line-height: 1.2; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: #94A3B8; font-family: 'Prompt', sans-serif; font-weight: 500; font-size: 14px; text-decoration: none;
}
.sidebar nav a svg { flex: none; }
.sidebar nav a.active { background: #1E293B; color: #F8FAFC; }
.sidebar nav a .badge-count {
  margin-left: auto; background: var(--status-warning-text); color: var(--status-warning-bg);
  font-family: 'Prompt', sans-serif; font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
}
.sidebar-divider { height: 1px; background: #1E293B; margin: 10px 4px; }
.sidebar-section-label {
  padding: 4px 12px 6px; color: #64748B; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}

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

.topbar {
  height: 64px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; background: var(--bg-surface); border-bottom: 1px solid var(--border-subtle);
}
.topbar h1 { font-family: 'Prompt', sans-serif; font-size: 18px; font-weight: 600; color: var(--text-primary); margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.filter-chip {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border-subtle);
  border-radius: 7px; font-family: 'Prompt', sans-serif; font-size: 13px; color: var(--text-secondary);
  background: var(--bg-surface); text-decoration: none;
}
.filter-chip strong { color: var(--text-primary); }
.topbar-divider { width: 1px; height: 24px; background: var(--border-subtle); }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 999px; background: #EFF6FF; color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 13px;
}
.user-chip .name { font-size: 13px; font-weight: 500; color: var(--text-primary); line-height: 1.2; }
.user-chip .role { font-size: 11px; color: var(--text-muted); line-height: 1.2; }

.content { flex: 1; padding: 26px 28px 40px; display: flex; flex-direction: column; gap: 20px; }

.card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: 10px; padding: 22px 24px; }
.card h2 { font-family: 'Prompt', sans-serif; font-size: 15px; font-weight: 600; color: var(--text-primary); margin: 0 0 16px; }

.kpi-row { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi-card { flex: 1; min-width: 200px; background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: 10px; padding: 18px 20px; }
.kpi-card .label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.kpi-card .value { font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 25px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.kpi-card .sub { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }
.kpi-card.highlight { background: var(--status-success-bg); border-color: #D1FAE5; }
.kpi-card.highlight .label, .kpi-card.highlight .value { color: var(--status-success-text); }
.kpi-card.highlight .sub { color: #059669; }
.kpi-progress { height: 6px; border-radius: 999px; background: #F1F5F9; margin-top: 10px; overflow: hidden; }
.kpi-progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

table.data-table { border-collapse: collapse; width: 100%; }
table.data-table thead tr { background: #F1F5F9; }
table.data-table th { padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-align: left; }
table.data-table th.num, table.data-table td.num { text-align: right; }
table.data-table th.center, table.data-table td.center { text-align: center; }
table.data-table td { padding: 11px 12px; font-size: 13px; color: var(--text-secondary); border-bottom: 1px solid #F1F5F9; }
table.data-table td.num { font-variant-numeric: tabular-nums; color: var(--text-primary); white-space: nowrap; }
table.data-table tbody tr:nth-child(even) { background: #FAFBFC; }

.pill { display: inline-block; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; font-family: inherit; }
.pill-neutral { background: #F1F5F9; color: var(--text-secondary); }
.pill-success { background: var(--status-success-bg); color: var(--status-success-text); }
.pill-warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.pill-danger  { background: var(--status-danger-bg);  color: var(--status-danger-text); }

.table-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border-subtle); border-radius: 7px; padding: 7px 12px; width: 240px; color: var(--text-muted); }
.search-box input { border: none; outline: none; font-size: 13px; font-family: inherit; width: 100%; color: var(--text-primary); background: transparent; }

.two-col { display: flex; gap: 20px; align-items: flex-start; }
.two-col .main-panel { flex: 2; min-width: 0; }
.two-col .side-panel { flex: 1; min-width: 320px; position: sticky; top: 26px; }

dialog.modal {
  border: none; border-radius: 12px; padding: 0; width: 92vw; max-width: 520px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, 0.5); }
dialog.modal .modal-inner { padding: 24px; max-height: 85vh; overflow-y: auto; }
dialog.modal[open] { animation: bpm-modal-in 0.15s ease-out; }
@keyframes bpm-modal-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.field-group { display: flex; flex-direction: column; gap: 14px; }
label.field-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.field, select.field, input.field, textarea.field {
  display: block; width: 100%; border: 1px solid var(--border-subtle); border-radius: 7px; padding: 9px 12px;
  font-size: 13.5px; color: var(--text-primary); background: var(--bg-surface); font-family: inherit;
}
.field.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea.field { resize: vertical; min-height: 56px; }

.balance-box { background: var(--status-success-bg); border: 1px solid #D1FAE5; border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.balance-box .row { display: flex; justify-content: space-between; font-size: 12.5px; color: #059669; }
.balance-box .row.total { font-size: 13px; font-weight: 700; color: var(--status-success-text); }
.balance-box hr { border: none; border-top: 1px solid #D1FAE5; margin: 0; }
.balance-box.negative { background: var(--status-danger-bg); border-color: #FECACA; }
.balance-box.negative .row, .balance-box.negative .row.total { color: var(--status-danger-text); }

/* ช่องเลือกผู้ขอใช้แบบพิมพ์ค้นหา (public/transactions.php) */
.picker { position: relative; }
.picker input.field { padding-right: 38px; }
.picker.is-selected input.field {
  border-color: #16A34A; background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2316A34A' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
.picker-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none; max-height: 320px; overflow-y: auto;
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: 12px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16), 0 2px 6px rgba(15, 23, 42, 0.06);
}
.picker-list[hidden] { display: none; }
.picker-head, .picker-more { padding: 4px 10px 6px; font-size: 11.5px; color: var(--text-muted); }
.picker-more { padding: 6px 10px 2px; border-top: 1px solid var(--border-subtle); margin-top: 4px; }
.picker-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.picker-item.active { background: rgba(30, 58, 138, 0.08); }
.picker-avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 600; background: #E0E7FF; color: var(--accent);
}
.picker-av-1 { background: #DCFCE7; color: #166534; }
.picker-av-2 { background: #FEF3C7; color: #92400E; }
.picker-av-3 { background: #FCE7F3; color: #9D174D; }
.picker-av-4 { background: #E0F2FE; color: #075985; }
.picker-av-5 { background: #EDE9FE; color: #5B21B6; }
.picker-body { min-width: 0; }
.picker-name { font-size: 14px; line-height: 1.4; color: var(--text-primary); }
.picker-name mark { background: #FEF08A; color: inherit; border-radius: 3px; padding: 0 1px; }
.picker-sub { font-size: 12px; line-height: 1.35; color: var(--text-secondary); margin-top: 1px; }
.picker-empty { padding: 14px 10px; font-size: 13px; color: var(--text-muted); text-align: center; }
.picker-chosen { margin-top: 6px; font-size: 12.5px; color: var(--text-secondary); }
.picker-chosen[hidden] { display: none; }
.type-toggle { display: flex; gap: 8px; }
.type-toggle label {
  flex: 1; text-align: center; padding: 9px; border-radius: 7px; border: 1px solid var(--border-subtle);
  color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer;
}
.type-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.type-toggle label:has(input:checked) { background: var(--accent); color: #F8FAFC; border-color: var(--accent); }

.btn-row { display: flex; gap: 10px; margin-top: 4px; }
.btn-row .btn { flex: 1; }

.icon-btn {
  width: 26px; height: 26px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; text-decoration: none;
}
.icon-btn-approve { background: var(--status-success-bg); color: var(--status-success-text); }
.icon-btn-reject  { background: var(--status-danger-bg);  color: var(--status-danger-text); }
.icon-btn-info    { background: #EFF6FF; color: var(--accent); }

.form-error { font-size: 0.85rem; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
  .sidebar nav { flex-direction: row; }
  .two-col { flex-direction: column; }
  .two-col .side-panel { position: static; width: 100%; }
}
