@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
  --ink: #211b12;
  --muted: #746d61;
  --line: #e9e3d9;
  --paper: #fffdf9;
  --canvas: #f6f3ed;
  --gold: #b88418;
  --gold-dark: #7c560a;
  --gold-soft: #f5e8bd;
  --red: #a33a2c;
  --red-soft: #f9e3df;
  --green: #1d7657;
  --green-soft: #def2e9;
  --blue: #315f87;
  --blue-soft: #e4eef7;
  --shadow: 0 18px 45px rgba(62, 43, 12, .08);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* shared */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.brand-logo { display: block; width: 118px; height: auto; }
.brand-subtitle { padding-left: 10px; border-left: 1px solid var(--line); color: var(--muted); font-size: 9px; font-weight: 600; letter-spacing: .09em; line-height: 1.2; text-transform: uppercase; }
.eyebrow { color: var(--gold-dark); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.amount { font-family: Manrope, sans-serif; letter-spacing: -.035em; }
.card { background: var(--paper); border: 1px solid rgba(174,145,91,.18); border-radius: var(--radius); box-shadow: var(--shadow); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.gold { color: var(--gold-dark); background: var(--gold-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.blue { color: var(--blue); background: var(--blue-soft); }
.btn { border: 0; border-radius: 12px; padding: 11px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { color: white; background: var(--ink); box-shadow: 0 8px 20px rgba(33,27,18,.17); }
.btn-gold { color: #fff; background: linear-gradient(135deg, #bf8a1e, #8c5f09); box-shadow: 0 8px 20px rgba(140,95,9,.2); }
.btn-line { color: #fff; background: #06c755; }
.btn-soft { color: var(--ink); background: #f1ede5; }
.btn-danger { color: var(--red); background: var(--red-soft); }
.btn-sm { padding: 7px 10px; border-radius: 9px; font-size: 12px; }
.icon-btn { width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); background: var(--paper); border-radius: 11px; display: grid; place-items: center; }
.progress { height: 8px; border-radius: 99px; background: #ece6db; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, #d8aa42, #9d6c0d); border-radius: inherit; }
.field { display: grid; gap: 7px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 11px 12px; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184,132,24,.12); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toast-wrap { position: fixed; z-index: 100; top: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: min(92vw, 430px); pointer-events: none; }
.toast { padding: 13px 16px; color: #fff; background: #2a251d; border-radius: 13px; box-shadow: 0 15px 35px rgba(0,0,0,.18); animation: toast-in .25s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
.modal { position: fixed; inset: 0; z-index: 90; display: none; place-items: center; padding: 18px; background: rgba(27,22,15,.58); backdrop-filter: blur(6px); }
.modal.open { display: grid; }
.modal-panel { width: min(540px, 100%); max-height: 90vh; overflow: auto; background: var(--paper); border-radius: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.modal-head, .modal-body, .modal-foot { padding: 18px 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }

/* customer app */
.customer-app { min-height: 100vh; max-width: 500px; margin: 0 auto; background: #fbfaf7; box-shadow: 0 0 50px rgba(51,39,17,.09); padding-bottom: 88px; }
.mobile-header { position: sticky; z-index: 20; top: 0; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; background: rgba(251,250,247,.92); border-bottom: 1px solid rgba(216,205,186,.55); backdrop-filter: blur(14px); }
.customer-profile { display: flex; align-items: center; gap: 9px; }
.avatar { width: 38px; height: 38px; object-fit: cover; border-radius: 50%; background: var(--gold-soft); border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.customer-profile strong { display: block; font-size: 13px; line-height: 1.2; }
.customer-profile span { color: #06a548; font-size: 10px; font-weight: 700; }
.customer-main { padding: 18px; }
.page { display: none; animation: page-in .24s ease; }
.page.active { display: block; }
@keyframes page-in { from { opacity: .4; transform: translateY(5px); } }
.welcome { display: flex; justify-content: space-between; align-items: flex-end; margin: 4px 2px 18px; }
.welcome h1 { margin: 4px 0 0; font-size: 25px; line-height: 1.25; letter-spacing: -.02em; }
.gold-price { text-align: right; }
.gold-price strong { display: block; color: var(--red); font-family: Manrope,sans-serif; font-size: 17px; }
.gold-price small { color: var(--muted); font-size: 10px; }
.contract-hero { position: relative; overflow: hidden; padding: 20px; color: #fff; background: linear-gradient(145deg, #302518, #6e4d11); border-radius: 24px; box-shadow: 0 20px 45px rgba(82,54,6,.2); }
.contract-hero::after { content: ""; position: absolute; right: -10px; bottom: 4px; width: 170px; height: 44px; opacity: .08; background: url('orange-logo.svg') center / contain no-repeat; }
.contract-top { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: flex-start; }
.contract-top h2 { margin: 5px 0 1px; font-size: 18px; }
.contract-top p { margin: 0; color: rgba(255,255,255,.65); font-size: 12px; }
.contract-hero .badge { color: #f7dfa0; background: rgba(255,255,255,.12); }
.contract-hero .progress { margin: 18px 0 9px; background: rgba(255,255,255,.16); }
.contract-hero .progress > span { background: linear-gradient(90deg, #f2c55e, #fff0b7); }
.progress-copy { display: flex; justify-content: space-between; color: rgba(255,255,255,.74); font-size: 11px; }
.next-due { position: relative; z-index: 1; margin-top: 18px; padding: 15px; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; }
.next-due small { display: block; color: rgba(255,255,255,.62); }
.next-due strong { display: block; margin-top: 2px; font: 800 23px Manrope,sans-serif; }
.section-head { margin: 24px 2px 12px; display: flex; align-items: center; justify-content: space-between; }
.section-head h2 { margin: 0; font-size: 17px; }
.section-head button { color: var(--gold-dark); background: none; border: 0; font-size: 12px; font-weight: 700; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.quick-item { border: 1px solid var(--line); background: var(--paper); border-radius: 15px; padding: 13px 4px 10px; text-align: center; color: var(--ink); }
.quick-icon { width: 34px; height: 34px; margin: 0 auto 7px; display: grid; place-items: center; border-radius: 11px; color: var(--gold-dark); background: var(--gold-soft); font-size: 17px; }
.quick-item span { display: block; font-size: 10px; font-weight: 600; }
.timeline { display: grid; }
.timeline-item { position: relative; display: grid; grid-template-columns: 30px 1fr auto; gap: 9px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-dot { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 12px; }
.timeline-item strong { font-size: 13px; }
.timeline-item p { margin: 1px 0 0; color: var(--muted); font-size: 10px; }
.timeline-item .money { font: 700 12px Manrope,sans-serif; }
.list-card { padding: 16px; }
.bottom-nav { position: fixed; z-index: 25; bottom: 0; left: 50%; width: min(500px,100%); transform: translateX(-50%); display: grid; grid-template-columns: repeat(5,1fr); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: rgba(255,253,249,.95); border-top: 1px solid var(--line); backdrop-filter: blur(16px); }
.nav-item { border: 0; background: transparent; color: #938b7e; padding: 3px 1px; display: grid; gap: 2px; place-items: center; font-size: 10px; }
.nav-icon { font-size: 19px; line-height: 1; }
.nav-item.active { color: var(--gold-dark); font-weight: 700; }
.page-title { margin: 6px 0 18px; }
.page-title h1 { margin: 4px 0; font-size: 25px; }
.page-title p { margin: 0; color: var(--muted); font-size: 12px; }
.contract-list { display: grid; gap: 12px; }
.contract-card { padding: 16px; }
.contract-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.product-thumb { width: 50px; height: 50px; flex: 0 0 auto; display: grid; place-items: center; color: #8b5c00; background: radial-gradient(circle at 35% 25%, #fff1b6, #ddb657); border-radius: 14px; font: 800 12px Manrope; box-shadow: inset 0 0 0 1px rgba(128,81,0,.14); }
.contract-name { flex: 1; }
.contract-name strong { display: block; font-size: 14px; }
.contract-name small { color: var(--muted); font-size: 10px; }
.contract-meta { margin-top: 13px; display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.contract-meta div { padding: 9px; border-radius: 10px; background: #f4f1ea; }
.contract-meta small, .stat small { display: block; color: var(--muted); font-size: 9px; }
.contract-meta strong { font: 700 12px Manrope; }
.installment-list { display: grid; gap: 8px; }
.installment { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 13px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.installment-no { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; font: 700 12px Manrope; background: #eee9df; }
.installment.due { border-color: #d9ac4b; box-shadow: 0 7px 20px rgba(152,104,8,.08); }
.installment.due .installment-no { color: #fff; background: var(--gold); }
.installment.paid .installment-no { color: var(--green); background: var(--green-soft); }
.installment strong { display: block; font-size: 12px; }
.installment small { color: var(--muted); font-size: 10px; }
.installment .money { font: 700 12px Manrope; text-align: right; }
.product-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.product-card { overflow: hidden; }
.product-visual { height: 120px; display: grid; place-items: center; color: #865a05; background: radial-gradient(circle at 50% 20%, #fff4c9, #e7c26b 60%, #c99933); font: 800 22px Manrope; }
.product-info { padding: 13px; }
.product-info h3 { margin: 0 0 3px; font-size: 13px; line-height: 1.35; }
.product-info p { margin: 0; color: var(--muted); font-size: 10px; }
.product-price { margin-top: 10px; display: flex; align-items: flex-end; justify-content: space-between; }
.product-price strong { font: 800 14px Manrope; }
.profile-card { text-align: center; padding: 24px; }
.profile-card .avatar { width: 76px; height: 76px; }
.profile-card h2 { margin: 9px 0 0; }
.profile-card p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.menu-list { margin-top: 12px; overflow: hidden; }
.menu-row { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: var(--paper); padding: 15px 16px; display: flex; align-items: center; gap: 11px; text-align: left; }
.menu-row:last-child { border-bottom: 0; }
.menu-row > span:first-child { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: var(--gold-soft); }
.menu-row strong { flex: 1; font-size: 13px; }

/* admin */
.admin-body { background: #f2f0eb; }
.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 15px; color: #efe7d8; background: #201d18; display: flex; flex-direction: column; }
.sidebar .brand { padding: 0 8px 21px; color: #fff; }
.sidebar .brand-logo { width: 124px; }
.sidebar .brand-subtitle { color: #81796d; border-left-color: #4a443b; }
.side-label { margin: 16px 10px 7px; color: #746d61; font-size: 9px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.side-nav { display: grid; gap: 3px; }
.side-link { width: 100%; border: 0; border-radius: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 11px; color: #a9a195; background: transparent; text-align: left; font-size: 12px; }
.side-link span:first-child { width: 20px; text-align: center; font-size: 15px; }
.side-link:hover, .side-link.active { color: #fff; background: rgba(255,255,255,.085); }
.side-link.active span:first-child { color: #e0ae40; }
.sidebar-footer { margin-top: auto; padding: 12px; background: rgba(255,255,255,.05); border-radius: 13px; }
.sidebar-footer small { color: #8e867a; }
.sidebar-footer strong { display: block; color: #fff; font-size: 12px; }
.admin-content { min-width: 0; }
.admin-topbar { height: 67px; padding: 0 26px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.82); border-bottom: 1px solid #e3ded4; backdrop-filter: blur(14px); }
.admin-topbar h1 { margin: 0; font-size: 18px; }
.admin-actions { display: flex; align-items: center; gap: 9px; }
.admin-actions .avatar { width: 35px; height: 35px; }
.admin-main { padding: 24px 26px 40px; }
.admin-page { display: none; }
.admin-page.active { display: block; animation: page-in .2s ease; }
.admin-heading { margin-bottom: 18px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.admin-heading h2 { margin: 0; font-size: 23px; }
.admin-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.stat { padding: 17px; }
.stat-top { display: flex; justify-content: space-between; align-items: center; }
.stat-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--gold-soft); }
.stat .value { display: block; margin: 12px 0 4px; font: 800 22px Manrope; }
.trend { font-size: 10px; font-weight: 700; color: var(--green); }
.dashboard-grid { margin-top: 15px; display: grid; grid-template-columns: 1.4fr .8fr; gap: 15px; }
.panel { padding: 18px; }
.panel-head { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin: 0; font-size: 15px; }
.chart { height: 210px; display: flex; align-items: flex-end; gap: 12px; padding: 15px 4px 0; border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to top, transparent 0 51px, #eeeae2 52px); }
.bar-group { flex: 1; height: 100%; display: flex; align-items: flex-end; gap: 3px; position: relative; }
.bar { flex: 1; min-height: 5px; border-radius: 5px 5px 0 0; background: #d0a13b; }
.bar.alt { background: #373127; }
.bar-group small { position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%); color: var(--muted); font-size: 9px; }
.chart-legend { margin-top: 29px; display: flex; gap: 16px; font-size: 10px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 2px; background: #d0a13b; }
.chart-legend span:last-child i { background: #373127; }
.activity { display: grid; gap: 14px; }
.activity-item { display: grid; grid-template-columns: 32px 1fr; gap: 10px; }
.activity-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: var(--green-soft); color: var(--green); font-size: 12px; }
.activity-item strong { display: block; font-size: 11px; }
.activity-item p { margin: 1px 0; color: var(--muted); font-size: 9px; }
.table-panel { overflow: hidden; }
.table-toolbar { padding: 15px 17px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); }
.search { min-width: 230px; position: relative; }
.search input { width: 100%; padding: 9px 11px 9px 32px; border: 1px solid var(--line); border-radius: 10px; outline: 0; }
.search::before { content: "⌕"; position: absolute; left: 11px; top: 7px; color: var(--muted); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { padding: 10px 15px; color: var(--muted); background: #faf8f3; text-align: left; white-space: nowrap; font-weight: 600; }
td { padding: 12px 15px; border-top: 1px solid var(--line); white-space: nowrap; }
td strong { font-size: 11px; }
.table-product { display: flex; align-items: center; gap: 9px; }
.table-product .product-thumb { width: 34px; height: 34px; border-radius: 9px; font-size: 8px; }
.row-actions { display: flex; gap: 5px; }
.mini-bars { display: flex; align-items: flex-end; gap: 5px; height: 155px; padding-top: 10px; }
.mini-bars span { flex: 1; background: linear-gradient(#e7bb58,#aa7614); border-radius: 5px 5px 0 0; }
.report-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
.report-card { padding: 18px; }
.report-card h3 { margin: 0 0 3px; font-size: 14px; }
.report-card .value { margin: 15px 0 8px; font: 800 22px Manrope; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.settings-card { padding: 18px; }
.settings-card h3 { margin: 0 0 15px; font-size: 16px; }
.settings-form { display: grid; gap: 12px; }
.notice { padding: 13px 14px; border-radius: 12px; color: #71520e; background: #fff1c9; font-size: 11px; line-height: 1.5; }
.mobile-menu { display: none; }

@media (max-width: 980px) {
  .admin-shell { grid-template-columns: 74px minmax(0,1fr); }
  .sidebar { padding-inline: 10px; }
  .sidebar .brand { justify-content: center; padding-inline: 0; }
  .sidebar .brand-subtitle, .side-label, .side-link span:last-child, .sidebar-footer { display: none; }
  .sidebar .brand-logo { width: 48px; }
  .side-link { justify-content: center; padding-inline: 0; }
  .stat-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 700px) {
  .admin-shell { display: block; }
  .sidebar { position: fixed; z-index: 50; left: -250px; width: 245px; transition: .2s ease; }
  .sidebar.open { left: 0; }
  .sidebar .brand { justify-content: flex-start; }
  .sidebar .brand-subtitle, .side-label, .side-link span:last-child, .sidebar-footer { display: block; }
  .sidebar .brand-logo { width: 124px; }
  .side-link { justify-content: flex-start; padding-inline: 12px; }
  .mobile-menu { display: grid; }
  .admin-topbar { padding: 0 15px; }
  .admin-topbar h1 { font-size: 15px; }
  .admin-main { padding: 18px 14px 30px; }
  .admin-actions > span { display: none; }
  .stat-grid, .dashboard-grid, .report-grid, .settings-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .search { min-width: 0; }
}

@media (max-width: 380px) {
  .quick-grid { grid-template-columns: repeat(2,1fr); }
  .contract-meta { grid-template-columns: 1fr 1fr; }
}
