:root {
  --navy: #0f548c;
  --navy-dark: #093961;
  --red: #e60000;
  --bg: #f3f6f9;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #dbe2ea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 84, 140, 0.08);
  --shadow-md: 0 6px 20px rgba(15, 84, 140, 0.15);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Sarabun', 'Segoe UI', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--navy); }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.wrap { white-space: normal; word-break: break-word; }

/* ---------- buttons ---------- */
button, .btn-primary, .btn-secondary, .btn-outline { font-family: inherit; }
.btn-primary, .btn-secondary, .btn-outline, .btn-approve, .btn-reject, .btn-back, .btn-add-item, .btn-mini {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 7px; font-weight: 600; font-size: 13px; cursor: pointer;
  padding: 8px 14px; border: 1px solid transparent; text-decoration: none;
  transition: background .15s, opacity .15s; white-space: nowrap;
}
button:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: #c20000; }
.btn-secondary { background: var(--navy); color: #fff; }
.btn-secondary:hover { background: var(--navy-dark); }
.btn-outline { background: #fff; color: var(--navy); border-color: var(--border); }
.btn-outline:hover { background: #eff6ff; }
.btn-approve { background: #16a34a; color: #fff; }
.btn-reject { background: #dc2626; color: #fff; }
.btn-back { background: transparent; color: var(--navy); border-color: var(--border); }
.btn-add-item { background: #eff6ff; color: var(--navy); border: 1px dashed var(--navy); }
.btn-mini { padding: 4px 8px; font-size: 12px; background: #fff; border-color: var(--border); color: var(--navy); }
.btn-mini:hover { background: #eff6ff; }
.full-width { width: 100%; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--navy); color: #fff; padding: 8px 20px;
  border-bottom: 4px solid var(--red); box-shadow: var(--shadow-md);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.brand-logo { background: #fff; border-radius: 6px; padding: 4px 10px; height: 42px; display: flex; align-items: center; cursor: pointer; }
.brand-logo-img { height: 32px; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .4px; }
.title-accent { color: #ff6b6b; margin-left: 4px; }
.nav-pill { color: #fff; text-decoration: none; background: rgba(255,255,255,.12); padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.nav-pill:hover { background: rgba(255,255,255,.22); }
.btn-sync {
  display: inline-flex; align-items: center; gap: 8px; background: #fff; color: var(--navy);
  border: none; padding: 7px 12px; border-radius: 7px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.sync-badge { background: var(--red); color: #fff; font-size: 11px; padding: 1px 8px; border-radius: 999px; }
.sync-badge.synced { background: #16a34a; }
.user-Chip { background: rgba(0,0,0,.2); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.user-meta { text-align: right; line-height: 1.2; }
.user-role-line { font-size: 10px; color: #ffb3b3; font-weight: 700; }
.user-name-line { font-size: 13px; font-weight: 600; }

/* ---------- layout ---------- */
.main-container { max-width: 1560px; margin: 0 auto; padding: 18px 16px 48px; }
.view-section { display: none; }
.view-section.active { display: block; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1280px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 700px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  background: var(--card); border: 1.5px solid #e2e8f0; border-radius: 12px; padding: 12px 16px;
  cursor: pointer; box-shadow: var(--shadow); border-top: 4px solid var(--navy); transition: transform .1s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card.active { outline: 2px solid var(--navy); }
.kpi-draft { border-top-color: #94a3b8; }
.kpi-wait { border-top-color: #f59e0b; }
.kpi-progress { border-top-color: #2563eb; }
.kpi-win { border-top-color: #16a34a; }
.kpi-loss { border-top-color: #7c3aed; }
.kpi-cancel { border-top-color: #dc2626; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--navy); }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* ---------- filters ---------- */
.filter-panel { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 16px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.filter-group label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.filter-search { flex: 1; min-width: 220px; }
.filter-actions { display: flex; gap: 8px; margin-left: auto; }
input, select, textarea {
  font-family: inherit; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,84,140,.25); border-color: var(--navy); }
textarea { resize: vertical; }
.readonly-input, input[readonly] { background: #f1f5f9; color: #475569; }

/* ---------- tables ---------- */
.table-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-header-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px; }
.table-title { font-weight: 700; display: flex; gap: 10px; align-items: center; }
.record-count-pill { background: #eff6ff; color: var(--navy); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.table-legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot-draft { background: #94a3b8; } .dot-wait { background: #f59e0b; } .dot-progress { background: #2563eb; }
.dot-win { background: #16a34a; } .dot-reject { background: #dc2626; }
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #f8fafc; text-align: left; font-size: 12px; color: var(--muted); padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 9px 10px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
.data-table tbody tr:hover { background: #f8fbff; }
.data-table td.actions { text-align: right; white-space: nowrap; }
.data-table td.actions .btn-mini { margin-left: 4px; }
.compact-table td, .compact-table th { padding: 6px 8px; font-size: 12px; }
.empty-cell { text-align: center; color: var(--muted); padding: 28px !important; }

/* ---------- status ---------- */
.status-pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.st-draft { background: #e2e8f0; color: #334155; }
.st-wait { background: #fef3c7; color: #92400e; }
.st-progress { background: #dbeafe; color: #1e40af; }
.st-win { background: #dcfce7; color: #166534; }
.st-loss { background: #ede9fe; color: #5b21b6; }
.st-cancel, .st-reject { background: #fee2e2; color: #991b1b; }
.verify-pill { font-size: 12px; font-weight: 600; }

/* ---------- editor ---------- */
.editor-action-bar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  background: var(--card); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px;
  position: sticky; top: 66px; z-index: 50;
}
.editor-bar-left, .editor-bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.editor-doc-badge { font-weight: 700; color: var(--navy); background: #eff6ff; padding: 4px 10px; border-radius: 6px; }
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.lang-btn { border: none; background: #fff; padding: 7px 12px; cursor: pointer; font-weight: 600; font-family: inherit; }
.lang-btn.active { background: var(--navy); color: #fff; }
.inline-status-box { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.inline-status-box select { width: auto; }

.approval-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fffbeb; border: 1px solid #fcd34d; border-left: 5px solid #f59e0b; padding: 12px 16px;
  border-radius: var(--radius); margin-bottom: 14px;
}
.approval-banner-title { font-weight: 700; }
.approval-banner-desc { font-size: 13px; color: var(--muted); }
.approval-banner-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.suggestion-input { min-width: 280px; }
.already-processed-banner { background: #ecfdf5; border: 1px solid #6ee7b7; padding: 10px 16px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 600; }

.quotation-paper { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 28px 32px; max-width: 1200px; margin: 0 auto; }
.paper-company-header { display: flex; gap: 24px; align-items: flex-start; border-bottom: 2px solid var(--navy); padding-bottom: 12px; }
.paper-logo img { max-width: 200px; }
.co-th { font-weight: 700; font-size: 16px; }
.co-en { font-weight: 700; }
.co-addr { font-size: 13px; color: var(--muted); }
.paper-doc-heading { text-align: center; font-size: 20px; font-weight: 700; margin: 14px 0; color: var(--navy); }
.meta-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .meta-form-grid { grid-template-columns: 1fr; } }
.form-field-row { display: grid; grid-template-columns: 170px 1fr; gap: 8px; align-items: start; margin-bottom: 8px; }
.form-field-row label { font-size: 12px; font-weight: 600; padding-top: 8px; }
.req { color: var(--red); }
.combo-wrap, .two-inputs { display: flex; gap: 6px; }
.rev-input { max-width: 80px; }

.line-items-section { margin-top: 18px; }
.line-items-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.line-items-intro { font-size: 13px; font-weight: 600; }
.items-editor-table { width: 100%; border-collapse: collapse; }
.items-editor-table th { background: var(--navy); color: #fff; font-size: 12px; padding: 8px; }
.items-editor-table td { border: 1px solid var(--border); padding: 4px; vertical-align: top; }
.items-editor-table input, .items-editor-table textarea { border: none; padding: 6px; }
.items-editor-table td.it-amount { padding: 8px; font-weight: 600; }

.summary-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; margin-top: 18px; }
@media (max-width: 900px) { .summary-grid { grid-template-columns: 1fr; } }
.summary-label { font-weight: 700; font-size: 13px; display: block; margin-bottom: 4px; }
.baht-words-box, .suggestion-display-box { margin-top: 12px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.baht-words-label, .suggestion-display-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.baht-words-value { font-weight: 700; color: var(--navy); }
.suggestion-display-box { background: #fff1f2; border-color: #fecdd3; }
.totals-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.totals-lbl { font-size: 13px; font-weight: 600; }
.totals-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.totals-input { width: 140px; text-align: right; }
.vat-pct-input { width: 64px; display: inline-block; margin: 0 4px; padding: 3px 6px; }
.subtotal-highlight { background: #f8fafc; padding: 8px; border-radius: 6px; }
.threshold-badge { display: inline-block; margin-left: 6px; font-size: 11px; background: #dcfce7; color: #166534; padding: 1px 8px; border-radius: 999px; }
.threshold-badge.need-approve { background: #fef3c7; color: #92400e; }
.grand-total-row { background: var(--navy); color: #fff; padding: 10px; border-radius: 6px; border: none; margin-top: 6px; }
.grand-total-row .totals-val { font-size: 18px; }
.signer-row { margin-top: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.library-files-box { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.library-files-title { font-weight: 700; margin-bottom: 6px; }
.library-files-list { display: flex; flex-direction: column; gap: 4px; }

/* ---------- modals ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; z-index: 500; padding: 20px; }
.modal-card { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-md); }
.modal-lg { max-width: 960px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 16px; color: var(--navy); }
.modal-close { border: none; background: none; font-size: 18px; cursor: pointer; }
.modal-body { padding: 16px 18px; }
.sync-info-box, .user-current-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.sync-btn-row, .modal-footer-btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.sub-heading { margin: 16px 0 8px; }
.sso-login-box { margin: 12px 0; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.field-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }

/* ---------- toast ---------- */
.toast-container { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #1e293b; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-md); max-width: 420px; opacity: 0; transform: translateY(10px); transition: all .25s; }
.toast.show { opacity: 1; transform: none; }
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-warn { background: #d97706; }

