@import url("https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700&display=swap");

:root {
  --mea: #f26522;
  --mea-dark: #c2560f;
  --mea-soft: #fff3ec;
  --ink: #16202e;
  --muted: #6b7787;
  --line: #e6e8ec;
  --surface: #ffffff;
  --canvas: #eef1f5;
  --navy: #0f2c52;
  --success: #127a45;
  --success-soft: #eaf7f0;
  --danger: #b3261e;
  --danger-soft: #fdeeee;
  --warning: #9a4a0b;
  --warning-soft: #fff7e8;
  --blue: #3d6fa8;
  --blue-soft: #eef4fd;
  --shadow: 0 18px 48px rgba(22, 32, 46, .12);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%; margin: 0; color: var(--ink); background: var(--canvas);
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgba(242, 106, 33, .3); outline-offset: 2px; }

.login-page {
  display: grid; grid-template-columns: minmax(380px, 42%) 1fr; min-height: 100vh;
  background: #fff;
}
.login-panel { display: grid; place-items: center; padding: 48px; }
.login-card { width: min(100%, 420px); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 46px; }
.login-brand img { width: 78px; }
.login-brand span { padding-left: 14px; border-left: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.4; }
.login-card h1 { margin: 0 0 8px; font-size: clamp(29px, 4vw, 40px); letter-spacing: -.04em; }
.login-card > p { margin: 0 0 28px; color: var(--muted); }
.login-visual {
  position: relative; display: grid; place-items: center; overflow: hidden; padding: 70px;
  color: #fff; background: linear-gradient(145deg, #f7772d, #d84b0c 72%);
}
.login-visual::before, .login-visual::after {
  content: ""; position: absolute; border: 1px solid rgba(255,255,255,.18); border-radius: 50%;
}
.login-visual::before { width: 660px; height: 660px; right: -210px; top: -190px; }
.login-visual::after { width: 420px; height: 420px; left: -150px; bottom: -170px; }
.visual-copy { position: relative; max-width: 580px; }
.visual-copy .mark { width: 60px; height: 6px; margin-bottom: 28px; background: #fff; border-radius: 10px; }
.visual-copy h2 { margin: 0; font-size: clamp(38px, 5vw, 72px); line-height: 1.06; letter-spacing: -.045em; }
.visual-copy p { max-width: 520px; margin: 26px 0 0; font-size: 18px; line-height: 1.7; color: rgba(255,255,255,.82); }
.demo-note { margin-top: 22px; padding: 12px 14px; border: 1px solid #ffd8c2; border-radius: 12px; color: #9b480f; background: #fff8f3; font-size: 13px; }

.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { color: #3d4a5c; font-size: 12px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; color: var(--ink); background: #fff;
  border: 1px solid #d7dce3; border-radius: 8px;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--mea); outline: 3px solid rgba(242,106,33,.12); }
.field label .req { color: var(--danger); }
.field-hint { color: var(--muted); font-size: 12px; }
.field-error { min-height: 20px; color: var(--danger); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  padding: 8px 15px; border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  color: var(--ink); background: #fff; font-size: 13px; font-weight: 600; text-decoration: none;
  transition: border-color .16s ease, background-color .16s ease, color .16s ease;
}
.btn:hover { border-color: #c8d0da; background: #f8fafc; }
.btn.primary { color: #fff; background: var(--mea); border-color: var(--mea); box-shadow: none; }
.btn.primary:hover { background: var(--mea-dark); }
.btn.secondary { color: var(--mea-dark); border-color: #f7c5a7; background: var(--mea-soft); }
.btn.ghost { border-color: var(--line); background: #fff; }
.btn.danger { color: var(--danger); border-color: #efbcc1; background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.icon-btn { width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #3d4a5c; cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto;
  z-index: 30; color: #3d4a5c; background: #fff; border-right: 1px solid var(--line);
}
.side-brand { display: flex; align-items: center; min-height: 72px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.side-brand img { width: 88px; }
.side-menu { flex: 1; padding: 14px 12px 20px; }
.side-label { margin: 15px 12px 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.side-label:first-child { margin-top: 2px; }
.side-link {
  display: flex; align-items: center; gap: 11px; min-height: 40px; padding: 8px 12px; margin: 2px 0;
  border-radius: 8px; color: #3d4a5c; text-decoration: none; font-size: 13px; font-weight: 500;
}
.side-link:hover { color: var(--mea-dark); background: var(--mea-soft); }
.side-link.active { color: var(--mea); background: var(--mea-soft); box-shadow: inset 3px 0 var(--mea); font-weight: 600; }
.side-link .ico { display: grid; place-items: center; width: 22px; min-width: 22px; color: inherit; text-align: center; }
.side-footer { padding: 14px 16px; border-top: 1px solid var(--line); }
.demo-chip { padding: 10px 12px; border: 1px solid #f2dec8; border-radius: 8px; color: #7b4a24; background: #fffbf7; font-size: 11px; line-height: 1.55; }

.app-main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  min-height: 72px; padding: 10px 24px; color: var(--ink); background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(14px);
}
.topbar h1 { margin: 0; font-size: 16px; letter-spacing: 0; }
.topbar small { display: block; margin-top: 2px; color: var(--muted); font-size: 11.5px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-actions .btn { color: #3d4a5c; border-color: var(--line); background: #fff; box-shadow: none; }
.top-actions .pay-link { color: var(--mea-dark); border-color: #f0d5c4; background: var(--mea-soft); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #f1d8c8; border-radius: 50%; color: var(--mea); background: var(--mea-soft); font-weight: 700; }
.content { width: min(100%, 1540px); margin: 0 auto; padding: 22px 26px 34px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: clamp(24px, 2.4vw, 28px); line-height: 1.25; letter-spacing: -.02em; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric { position: relative; overflow: hidden; min-height: 132px; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.metric::after { display: none; }
.metric .metric-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: color-mix(in srgb, var(--accent, var(--mea)) 12%, #fff); font-size: 17px; }
.metric .metric-label { margin-top: 10px; color: var(--muted); font-size: 12px; font-weight: 500; }
.metric strong { display: block; margin-top: 2px; font-size: clamp(23px, 2.3vw, 30px); line-height: 1.16; letter-spacing: -.035em; }
.metric small { color: var(--muted); font-size: 11px; }
.panel { margin-bottom: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 16px 20px; border-bottom: 1px solid #eef1f5; }
.panel-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.panel-body { padding: 20px 22px; }
.panel-body.flush { padding: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; border-bottom: 1px solid #f0f2f5; text-align: left; vertical-align: middle; font-size: 13px; }
th { color: #5a6779; background: #f8fafc; font-size: 12px; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fffaf6; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.code { color: var(--mea-dark); font-family: inherit; font-weight: 700; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.active, .status.success { color: var(--success); background: var(--success-soft); }
.status.inactive, .status.failed, .status.revoked { color: var(--danger); background: var(--danger-soft); }
.status.pending { color: var(--warning); background: var(--warning-soft); }

.chart-bars { display: grid; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 90px; align-items: center; gap: 12px; font-size: 12px; }
.bar-track { height: 10px; overflow: hidden; border-radius: 20px; background: #eef1f4; }
.bar-fill { height: 100%; min-width: 4px; border-radius: inherit; background: var(--mea); }
.donut-wrap { display: flex; align-items: center; gap: 28px; min-height: 210px; }
.donut { display: grid; place-items: center; width: 148px; height: 148px; flex: 0 0 auto; border-radius: 50%; background: conic-gradient(var(--mea) 0 46%, #2678bd 46% 72%, #16a36a 72% 89%, #e5a82d 89%); }
.donut::after { content: attr(data-total); display: grid; place-items: center; width: 92px; height: 92px; border-radius: 50%; background: #fff; font-size: 23px; font-weight: 800; }
.legend { display: grid; gap: 10px; }
.legend span { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

.empty { padding: 42px 20px; color: var(--muted); text-align: center; }
.notice { padding: 12px 14px; margin-bottom: 18px; border: 1px solid #f2dec8; border-radius: 10px; color: #7b4a24; background: #fffbf7; font-size: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 9px; min-height: 38px; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--mea); }
.stack { display: grid; gap: 12px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; background: rgba(18,24,33,.56); }
.modal { width: min(100%, 620px); max-height: 90vh; overflow: auto; border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-foot { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.modal-body { padding: 20px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: min(360px, calc(100vw - 48px)); padding: 13px 16px; border-radius: 11px; color: #fff; background: #20242c; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.payment-page { min-height: 100vh; background: var(--canvas); }
.payment-header { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 12px clamp(20px, 5vw, 70px); color: var(--ink); background: #fff; border-bottom: 1px solid var(--line); }
.payment-header img { width: 82px; }
.payment-header span { font-size: 12px; color: var(--muted); }
.payment-wrap { width: auto; max-width: 1120px; margin: 34px auto; }
.payment-grid { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; min-width: 0; }
.bill-card, .pay-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: none; }
.bill-card, .pay-card { min-width: 0; overflow: hidden; }
.bill-card { padding: 24px; }
.bill-card h1 { margin: 5px 0 4px; font-size: 20px; }
.ref { color: var(--muted); font-size: 12px; }
.bill-line { display: flex; justify-content: space-between; gap: 15px; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.bill-line span, .bill-line strong { min-width: 0; overflow-wrap: anywhere; }
.bill-line strong { text-align: right; }
.bill-total { display: flex; justify-content: space-between; align-items: end; padding-top: 20px; }
.bill-total strong { color: var(--mea-dark); font-size: 30px; }
.pay-card { padding: 26px; }
.pay-card h2 { margin: 0 0 6px; font-size: 24px; }
.pay-card > p { margin: 0 0 22px; color: var(--muted); }
.method-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.method { padding: 18px; border: 1px solid var(--line); border-radius: 13px; background: #fff; cursor: pointer; text-align: left; }
.method:hover, .method.selected { border-color: var(--mea); background: var(--mea-soft); }
.method b { display: block; margin-top: 9px; }
.method small { color: var(--muted); }
.pay-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.result-state { padding: 36px 20px; text-align: center; }
.result-icon { display: grid; place-items: center; width: 74px; height: 74px; margin: 0 auto 18px; border-radius: 50%; color: #fff; background: var(--success); font-size: 34px; }
.result-state h2 { margin: 0 0 8px; }

@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .payment-wrap { margin-left: 16px; margin-right: 16px; }
  .payment-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .login-page { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .login-panel { padding: 32px 22px; }
  .app-shell { grid-template-columns: 1fr; }
  .app-shell::after {
    content: ""; position: fixed; inset: 0; z-index: 50; pointer-events: none;
    background: rgba(15, 28, 45, .4); opacity: 0; transition: opacity .2s ease;
  }
  body.menu-open { overflow: hidden; }
  body.menu-open .app-shell::after { pointer-events: auto; opacity: 1; }
  .sidebar { position: fixed; z-index: 60; width: min(86vw, 268px); transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.menu-open .sidebar { transform: translateX(0); }
  .topbar { min-height: 68px; padding: 10px 16px; }
  .topbar .menu-toggle { display: inline-grid !important; place-items: center; }
  .content { padding: 20px 18px 30px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .page-head { align-items: stretch; flex-direction: column; }
  .table-wrap table { min-width: 720px; }
}
@media (max-width: 600px) {
  .topbar { gap: 10px; }
  .topbar h1 { max-width: 42vw; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
  .topbar small { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { gap: 6px; }
  .top-actions .pay-link { display: none; }
  .top-actions .btn { min-height: 36px; padding: 7px 10px; font-size: 12px; }
  .avatar { width: 36px; height: 36px; }
  .content { padding: 18px 14px 26px; }
  .page-head { margin-bottom: 16px; }
  .page-head h2 { font-size: 24px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 116px; }
  .form-grid, .method-grid { grid-template-columns: 1fr; }
  .payment-wrap { margin-top: 18px; }
  .payment-header span { display: none; }
  .bill-card, .pay-card { padding: 20px; }
  .bill-total { gap: 12px; }
  .bill-total strong { font-size: 24px; }
  .bar-row { grid-template-columns: 74px 1fr 70px; }
  .donut-wrap { flex-direction: column; }
  .modal-backdrop { padding: 12px; }
  .modal-head, .modal-foot, .modal-body { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* Topbar user bar: env badge, bell, greeting, icon logout */
.user-bar { display: flex; align-items: center; gap: 16px; }
.env-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; color: #3d4a5c; background: #fff; font-size: 13px; white-space: nowrap; }
.env-badge i { width: 8px; height: 8px; border-radius: 50%; background: #16a36a; }
.notify-wrap { position: relative; }
.bell { position: relative; display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: #3d4a5c; background: #f8fafc; cursor: pointer; }
.bell svg { width: 20px; height: 20px; }
.bell b { position: absolute; top: -4px; right: -4px; display: grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; border: 2px solid #fff; border-radius: 999px; color: #fff; background: #16a36a; font-size: 10.5px; font-weight: 700; }
.notify-pop { position: absolute; top: calc(100% + 10px); right: 0; z-index: 45; width: 320px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.notify-pop a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink); font-size: 13px; text-decoration: none; }
.notify-pop a small { display: block; color: var(--muted); }
.notify-pop a:hover { background: var(--mea-soft); }
.notify-pop .empty { padding: 18px; }
.greet { display: grid; padding-right: 16px; border-right: 1px solid var(--line); line-height: 1.3; white-space: nowrap; }
.greet strong { font-size: 15px; font-weight: 700; }
.greet small { color: var(--muted); font-size: 12px; }
.logout-btn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 10px; color: var(--mea); background: #fff; cursor: pointer; }
.logout-btn:hover { background: var(--mea-soft); }
.logout-btn svg { width: 20px; height: 20px; }
@media (max-width: 1180px) { .env-badge { display: none; } }
@media (max-width: 960px) { .greet strong { font-size: 14px; } }
@media (max-width: 600px) {
  .user-bar { gap: 8px; }
  .greet { display: none; }
  .bell, .logout-btn { width: 38px; height: 38px; }
}
