/* ══════════════════════════════════════════════════════════════════
   Bangsaen Accounting – Global Stylesheet
   Palette: Navy #1a3a5c · Teal #0d9488 · Emerald #10b981
   ══════════════════════════════════════════════════════════════════ */

:root {
  --navy:       #1a3a5c;
  --navy-light: #2a5a8c;
  --teal:       #0d9488;
  --teal-light: #14b8a6;
  --emerald:    #10b981;
  --emerald-light: #34d399;
  --rose:       #f43f5e;
  --rose-light: #fb7185;
  --amber:      #f59e0b;
  --bg:         #f0f4f8;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #1e293b;
  --text-muted: #64748b;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:     0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:  0 10px 40px rgba(0,0,0,.12);
  --radius:     14px;
  --radius-sm:  8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Sarabun', -apple-system, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.6;
}

/* ══ NAVBAR ══════════════════════════════════════════════════════════════════ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.5rem;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  box-shadow: 0 2px 20px rgba(0,0,0,.2);
  flex-wrap: wrap;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
}

.nav-logo {
  font-size: 1.8rem;
  line-height: 1;
}

.nav-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .02em;
}

.nav-sub {
  font-size: .75rem;
  color: rgba(255,255,255,.65);
}

.nav-tabs {
  display: flex;
  gap: .4rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.nav-tab {
  padding: .45rem 1rem;
  border: none;
  border-radius: 50px;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.85);
  font-family: 'Sarabun', sans-serif;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.nav-tab:hover { background: rgba(255,255,255,.22); color: #fff; }
.nav-tab.active { background: var(--teal); color: #fff; box-shadow: 0 2px 8px rgba(13,148,136,.4); }

.nav-actions { flex-shrink: 0; }

.btn-export {
  padding: .45rem 1rem;
  border: 1.5px solid rgba(255,255,255,.4);
  border-radius: 50px;
  background: transparent;
  color: #fff;
  font-family: 'Sarabun', sans-serif;
  font-size: .85rem;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.btn-export:hover { background: rgba(255,255,255,.15); border-color: #fff; }

/* ══ MAIN CONTENT ════════════════════════════════════════════════════════════ */
.main-content {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* ══ TABS ════════════════════════════════════════════════════════════════════ */
.tab-section { display: none; }
.tab-section.active { display: block; }

/* ══ TOAST ═══════════════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  top: 80px;
  right: 1.5rem;
  z-index: 999;
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--navy);
  color: #fff;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn .3s ease;
  max-width: 340px;
}

.toast.success { background: var(--teal); }
.toast.error   { background: var(--rose); }
.toast.hidden  { display: none; }

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ══ SUMMARY CARDS ═══════════════════════════════════════════════════════════ */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.4rem 1.5rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-left: 5px solid transparent;
  transition: transform .2s, box-shadow .2s;
}

.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

.card-income  { border-left-color: var(--emerald); }
.card-expense { border-left-color: var(--rose); }
.card-profit  { border-left-color: var(--teal); }

.card-icon {
  font-size: 2.4rem;
  flex-shrink: 0;
  line-height: 1;
}

.card-label {
  font-size: .82rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .15rem;
}

.card-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

.card-income  .card-value { color: var(--emerald); }
.card-expense .card-value { color: var(--rose); }
.card-profit  .card-value { color: var(--teal); }

.card-badge {
  display: inline-block;
  margin-top: .35rem;
  padding: .2rem .6rem;
  border-radius: 50px;
  font-size: .75rem;
  font-weight: 600;
}

.income-badge  { background: #d1fae5; color: #065f46; }
.expense-badge { background: #ffe4e6; color: #9f1239; }
.profit-badge  { background: #ccfbf1; color: #0f766e; }

/* ══ CHARTS ══════════════════════════════════════════════════════════════════ */
.charts-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
}

.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.chart-header h3 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1rem;
}

.chart-container { position: relative; height: 240px; }
.chart-doughnut-wrap { height: 240px; display: flex; align-items: center; justify-content: center; }
.chart-doughnut-wrap canvas { max-height: 240px; }

/* ══ RECENT CARD ═════════════════════════════════════════════════════════════ */
.recent-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-header h3 { font-size: .95rem; font-weight: 700; color: var(--navy); }

.btn-link {
  background: none;
  border: none;
  color: var(--teal);
  font-family: 'Sarabun', sans-serif;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
}

/* ══ TRANSACTION LIST ════════════════════════════════════════════════════════ */
.tx-list { display: flex; flex-direction: column; gap: .5rem; }

.tx-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  transition: background .15s;
}

.tx-item:hover { background: #eaf4fb; }

.tx-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tx-dot.income  { background: var(--emerald); }
.tx-dot.expense { background: var(--rose); }

.tx-info { flex: 1; min-width: 0; }

.tx-desc {
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.tx-amount {
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-left: .5rem;
}

.tx-amount.income  { color: var(--emerald); }
.tx-amount.expense { color: var(--rose); }

.tx-actions {
  display: flex;
  gap: .4rem;
  flex-shrink: 0;
}

.btn-voucher {
  padding: .3rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--navy);
  font-family: 'Sarabun', sans-serif;
  font-size: .78rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn-voucher:hover { background: var(--navy); color: #fff; }

.btn-delete {
  padding: .3rem .55rem;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  background: #fff5f5;
  color: var(--rose);
  font-family: 'Sarabun', sans-serif;
  font-size: .78rem;
  cursor: pointer;
  transition: all .15s;
}

.btn-delete:hover { background: var(--rose); color: #fff; border-color: var(--rose); }

/* ══ ENTRY FORM ══════════════════════════════════════════════════════════════ */
.entry-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 860px) {
  .entry-layout { grid-template-columns: 1fr; }
}

.form-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.form-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.25rem;
  padding-bottom: .75rem;
  border-bottom: 2px solid var(--border);
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-bottom: 1.25rem;
}

.toggle-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .75rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  cursor: pointer;
  font-weight: 600;
  font-size: .95rem;
  transition: all .2s;
}

.toggle-option input { display: none; }

.toggle-option.income-toggle:has(input:checked) {
  border-color: var(--emerald);
  background: #d1fae5;
  color: #065f46;
}

.toggle-option.expense-toggle:has(input:checked) {
  border-color: var(--rose);
  background: #ffe4e6;
  color: #9f1239;
}

.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-control {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif;
  font-size: .95rem;
  color: var(--text);
  background: var(--bg);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}

.form-control:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,.12);
  background: #fff;
}

.input-prefix { position: relative; display: flex; align-items: center; }
.prefix-label {
  position: absolute;
  left: .9rem;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}

.prefix-input { padding-left: 2rem; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--teal) 0%, var(--emerald) 100%);
  color: #fff;
  font-family: 'Sarabun', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  box-shadow: 0 4px 12px rgba(13,148,136,.3);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(13,148,136,.4); }
.btn-primary:active { transform: translateY(0); }
.btn-block { width: 100%; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .75rem 1.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-family: 'Sarabun', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}

.btn-secondary:hover { background: var(--bg); }

/* ══ SYNC CARD ═══════════════════════════════════════════════════════════════ */
.sync-card {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.5rem;
  color: #fff;
  text-align: center;
}

.sync-icon { font-size: 3rem; margin-bottom: .75rem; }

.sync-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: .5rem;
}

.sync-desc {
  font-size: .88rem;
  color: rgba(255,255,255,.75);
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

.btn-sync {
  width: 100%;
  padding: 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--teal);
  color: #fff;
  font-family: 'Sarabun', sans-serif;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(13,148,136,.4);
  margin-bottom: 1.25rem;
}

.btn-sync:hover { background: var(--teal-light); transform: translateY(-2px); }
.btn-sync small { font-size: .78rem; font-weight: 400; opacity: .85; }

.sync-result {
  padding: .75rem;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.12);
  font-size: .85rem;
  margin-bottom: 1.25rem;
  text-align: left;
  line-height: 1.6;
}

.sync-result.hidden { display: none; }

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-top: 1rem;
}

.stat-item {
  background: rgba(255,255,255,.1);
  border-radius: var(--radius-sm);
  padding: .6rem .4rem;
}

.stat-label { font-size: .7rem; opacity: .75; margin-bottom: .2rem; }
.stat-value { font-size: 1rem; font-weight: 700; }
.income-text  { color: var(--emerald-light); }
.expense-text { color: var(--rose-light); }

/* ══ FILTER BAR ══════════════════════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-input { flex: 1; min-width: 200px; }

.filter-tabs { display: flex; gap: .4rem; }

.filter-btn {
  padding: .4rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  background: #fff;
  color: var(--text-muted);
  font-family: 'Sarabun', sans-serif;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}

.filter-btn:hover { border-color: var(--teal); color: var(--teal); }

.filter-btn.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* ══ VOUCHER MODAL ═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
}

.modal-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.5rem;
  justify-content: center;
}

/* ══ VOUCHER DOCUMENT ════════════════════════════════════════════════════════ */
.voucher-doc {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  font-size: .9rem;
}

.voucher-header {
  text-align: center;
  border-bottom: 2px solid var(--navy);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.voucher-org { font-size: 1.15rem; font-weight: 800; color: var(--navy); }
.voucher-org-en { font-size: .8rem; color: var(--text-muted); }
.voucher-type-badge {
  display: inline-block;
  margin-top: .5rem;
  padding: .3rem 1rem;
  border-radius: 50px;
  font-weight: 700;
  font-size: .88rem;
}

.voucher-type-badge.income  { background: #d1fae5; color: #065f46; }
.voucher-type-badge.expense { background: #ffe4e6; color: #9f1239; }

.voucher-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem .5rem;
  margin-bottom: 1rem;
}

.voucher-field { display: flex; flex-direction: column; gap: .2rem; }
.voucher-field label { font-size: .75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.voucher-field span { font-weight: 600; }

.voucher-amount-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
  margin: 1rem 0;
  border: 1.5px dashed var(--border);
}

.voucher-amount-label { font-size: .78rem; color: var(--text-muted); margin-bottom: .25rem; }
.voucher-amount-value { font-size: 2rem; font-weight: 800; }
.voucher-amount-value.income  { color: var(--emerald); }
.voucher-amount-value.expense { color: var(--rose); }

.voucher-sig {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1.5rem;
}

.sig-box {
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: .5rem;
  font-size: .78rem;
  color: var(--text-muted);
}

.voucher-footer {
  margin-top: 1rem;
  text-align: center;
  font-size: .72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: .75rem;
}

/* ══ PRINT STYLES ════════════════════════════════════════════════════════════ */
@media print {
  .navbar, .main-content, .modal-actions { display: none !important; }
  .modal-overlay {
    position: static !important;
    background: none !important;
    padding: 0 !important;
    display: block !important;
  }
  .modal-box {
    box-shadow: none !important;
    padding: 0 !important;
    max-height: none !important;
  }
  .no-print { display: none !important; }
  body { background: #fff; }
}

/* ══ EMPTY STATE ═════════════════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* ══ RESPONSIVE ══════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .navbar { gap: .5rem; padding: .65rem 1rem; }
  .nav-tabs { gap: .3rem; }
  .nav-tab { padding: .4rem .7rem; font-size: .78rem; }
  .summary-cards { grid-template-columns: 1fr; }
  .card-value { font-size: 1.5rem; }
  .main-content { padding: 1rem .75rem 3rem; }
  .form-card { padding: 1.25rem; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-tabs { justify-content: center; }
  .voucher-grid { grid-template-columns: 1fr; }
}
