/* =========================================================
   ระบบรายงานการเงิน — สไตล์กลาง (โมเดิร์น, รองรับโหมดมืด)
   ========================================================= */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0d9488;
  --primary-600: #0f766e;
  --primary-soft: #ccfbf1;
  --navy: #0b1f3a;
  --navy-2: #12305a;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --sidebar-w: 270px;
}
[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #16213a;
  --text: #e6edf7;
  --muted: #93a4c0;
  --line: #22304d;
  --primary-soft: #0f3d3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Sarabun', 'Prompt', system-ui, sans-serif;
  font-size: 16px; line-height: 1.55;
  background: var(--bg); color: var(--text);
}
h1, h2, h3, strong { font-family: 'Prompt', 'Sarabun', sans-serif; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.right { text-align: right; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem; justify-content: center;
  border: 0; border-radius: 12px; padding: .65rem 1.1rem; cursor: pointer;
  font: 500 .95rem 'Prompt', sans-serif; transition: .15s;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), #14b8a6); color: #fff; box-shadow: 0 6px 16px rgba(13, 148, 136, .3); }
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:disabled { opacity: .7; cursor: wait; transform: none; }
.btn-block { width: 100%; padding: .85rem; font-size: 1rem; }

.icon-btn {
  width: 40px; height: 40px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); border-radius: 12px; cursor: pointer; transition: .15s;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary-600); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 10px; }

/* ---------- เลย์เอาต์ ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #cbd5e1; transition: transform .25s;
}
.brand { display: flex; gap: .85rem; align-items: center; padding: 1.4rem 1.2rem; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand-logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem;
  background: linear-gradient(135deg, #14b8a6, #0d9488); color: #fff; flex: none;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { color: #fff; font-size: 1.02rem; }
.brand-text small { color: #94a3b8; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu { flex: 1; padding: 1rem .8rem; overflow-y: auto; }
.menu-section { padding: 1rem .8rem .4rem; font-size: .75rem; letter-spacing: .06em; color: #64748b; }
.menu-item {
  display: flex; align-items: center; gap: .85rem; padding: .72rem .9rem; margin-bottom: 4px;
  border-radius: 12px; color: #cbd5e1; transition: .15s;
}
.menu-item i { width: 20px; text-align: center; }
.menu-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.menu-item.active { background: linear-gradient(135deg, rgba(20, 184, 166, .28), rgba(20, 184, 166, .1)); color: #5eead4; box-shadow: inset 3px 0 0 #14b8a6; }
.menu-item em { margin-left: auto; font-style: normal; font-size: .68rem; padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, .1); color: #94a3b8; }
.menu-item.soon { opacity: .65; }
.sidebar-foot { padding: 1rem 1.4rem; font-size: .85rem; color: #94a3b8; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-backdrop { display: none; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 1rem;
  padding: .85rem 1.6rem; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
#sidebarToggle { display: none; }
.topbar-title h1 { margin: 0; font-size: 1.25rem; }
.topbar-title span { color: var(--muted); font-size: .85rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.user-chip { display: flex; align-items: center; gap: .65rem; padding: .3rem .8rem .3rem .3rem; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 600 .95rem 'Prompt'; background: linear-gradient(135deg, #6366f1, #14b8a6); }
.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-info strong { font-size: .88rem; font-weight: 500; }
.user-info small { color: var(--muted); font-size: .74rem; }
.content { padding: 1.6rem; flex: 1; }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.3rem 1.4rem; margin-bottom: 1.2rem; }
.card h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
.card h3 i { color: var(--primary); margin-right: .4rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.card-head h3 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1.1rem; margin-bottom: 1.2rem; }
.cards .card { margin: 0; }
.stat { display: flex; align-items: center; gap: 1rem; }
.stat small { color: var(--muted); display: block; }
.stat strong { font-size: 1.15rem; }
.stat-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 1.3rem; flex: none; }
.stat-icon.teal { background: #ccfbf1; color: #0f766e; }
.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.violet { background: #ede9fe; color: #6d28d9; }
.stat-icon.amber { background: #fef3c7; color: #b45309; }

.welcome {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.2rem; padding: 1.8rem 2rem;
  border-radius: 20px; color: #fff; background: linear-gradient(120deg, var(--navy-2), #0d9488); box-shadow: var(--shadow); overflow: hidden;
}
.welcome h2 { margin: 0 0 .25rem; font-size: 1.5rem; }
.welcome p { margin: 0; opacity: .85; }
.welcome > i { font-size: 4.5rem; opacity: .18; }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font: 500 .82rem 'Prompt'; color: var(--muted); padding: .75rem .9rem; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th.right { text-align: right; }
.table td { padding: .8rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: var(--surface-2); }
.actions { white-space: nowrap; }
.actions .icon-btn + .icon-btn { margin-left: 4px; }

.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .7rem; border-radius: 99px; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--line); }
.badge i { font-size: .45rem; }
.badge.ok { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge.off { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge.role-super_admin { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.badge.role-executive { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.badge.role-finance_head { background: #ccfbf1; color: #115e59; border-color: #99f6e4; }

.empty-state { text-align: center; padding: 4rem 1rem; }
.empty-state i { font-size: 3.5rem; color: var(--muted); opacity: .5; }
.empty-state h2 { margin: 1rem 0 .3rem; }
.empty-state p { color: var(--muted); margin-bottom: 1.4rem; }

/* ---------- ฟอร์มใน SweetAlert ---------- */
.swal-form { text-align: left; }
.swal-field { display: block; margin: .6rem 0; }
.swal-field > span { display: block; font-size: .85rem; color: #64748b; margin-bottom: .2rem; }
.swal-field .swal2-input, .swal-field .swal2-select { width: 100%; margin: 0; box-sizing: border-box; }
.swal2-popup { font-family: 'Sarabun', sans-serif; border-radius: 18px; }
.swal2-title { font-family: 'Prompt', sans-serif; }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.login-page { background: radial-gradient(1200px 600px at 10% 0%, #134e4a 0%, transparent 60%), linear-gradient(135deg, var(--navy), var(--navy-2)); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; align-items: center; max-width: 1100px; margin: 0 auto; padding: 2rem; gap: 2rem; }
.login-hero { color: #e2e8f0; }
.hero-badge { width: 76px; height: 76px; border-radius: 22px; display: grid; place-items: center; font-size: 2rem; color: #fff; background: linear-gradient(135deg, #14b8a6, #0d9488); box-shadow: 0 12px 30px rgba(20, 184, 166, .4); margin-bottom: 1.4rem; }
.login-hero h1 { margin: 0 0 .3rem; font-size: 2.2rem; color: #fff; }
.login-hero p { margin: 0 0 1.6rem; color: #94a3b8; font-size: 1.1rem; }
.login-hero ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .7rem; }
.login-hero li i { color: #2dd4bf; margin-right: .5rem; }
.login-card { background: var(--surface); color: var(--text); border-radius: 24px; padding: 2.4rem; box-shadow: 0 30px 60px rgba(0, 0, 0, .35); }
.login-card h2 { margin: 0; font-size: 1.6rem; }
.login-card .muted { margin: .2rem 0 1.6rem; }
.field { display: block; margin-bottom: 1.1rem; }
.field > span { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .35rem; }
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon input { width: 100%; padding: .8rem 2.8rem; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; outline: none; transition: .15s; }
.input-icon input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(20, 184, 166, .18); background: var(--surface); }
.input-icon .eye { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px; }

/* ---------- พิมพ์ ---------- */
@media print {
  .sidebar, .topbar, .sidebar-backdrop { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; }
}

/* ---------- มือถือ/แท็บเล็ต ---------- */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .5); }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 45; }
  .main { margin-left: 0; }
  #sidebarToggle { display: inline-block; }
  .user-info { display: none; }
  .content { padding: 1rem; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { text-align: center; }
  .login-hero ul { justify-items: center; }
}
