/* ============================================================
   Franzbiz App — White Theme Design System
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&family=Anuphan:wght@500;600;700;800&display=swap');

:root {
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --surface2:  #f8f9fb;
  --surface3:  #f0f2f5;
  --border:    #e4e7ec;
  --border2:   #d0d5de;
  --text:      #111827;
  --text2:     #374151;
  --muted:     #6b7280;
  --muted2:    #9ca3af;
  --accent:    #d97706;
  --accent2:   #b45309;
  --accent-bg: #fffbeb;
  --accent-border: #fde68a;
  --green:     #059669;
  --green-bg:  #ecfdf5;
  --green-bd:  #a7f3d0;
  --red:       #dc2626;
  --red-bg:    #fef2f2;
  --red-bd:    #fecaca;
  --blue:      #2563eb;
  --blue-bg:   #eff6ff;
  --blue-bd:   #bfdbfe;
  --yellow:    #d97706;
  --yellow-bg: #fffbeb;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.1);
  --radius:    10px;
  --radius-lg: 14px;
}

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

body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── TOPBAR ── */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.tb-logo {
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
  padding-right: 20px;
  border-right: 1px solid var(--border);
  margin-right: 4px;
  line-height: 1.1;
  white-space: nowrap;
}
.tb-logo span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  display: block;
  letter-spacing: 0.5px;
}
.tb-tabs { display: flex; flex: 1; height: 100%; overflow-x: auto; }
.tb-tab {
  padding: 0 14px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  gap: 5px;
  user-select: none;
}
.tb-tab:hover { color: var(--text); }
.tb-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tb-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.tb-user {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}
.tb-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.tb-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Sarabun', sans-serif;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.tb-btn:hover { border-color: var(--border2); color: var(--text); }
.tb-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-btn.primary:hover { background: var(--accent2); }
.tb-btn.danger:hover { border-color: var(--red); color: var(--red); }

/* ── LAYOUT ── */
.page { max-width: 1000px; margin: 0 auto; padding: 28px 20px; }
.page-wide { max-width: 1200px; margin: 0 auto; padding: 28px 20px; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-family: 'Anuphan', sans-serif; font-size: 22px; font-weight: 700; color: var(--text); }
.page-header p { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}
.card-title {
  font-family: 'Anuphan', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-body { padding: 20px; }

/* ── FORMS ── */
.fg { margin-bottom: 16px; }
.fl {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.fi, .fselect, .ftextarea {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
}
.fi:focus, .fselect:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217,119,6,0.1); }
.fi[readonly] { background: var(--surface2); cursor: default; }
.ftextarea { resize: vertical; min-height: 80px; }
.fgrid  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fgrid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.fcol2  { grid-column: 1 / -1; }

/* Slider */
.slider-wrap { display: flex; align-items: center; gap: 10px; }
.slider-wrap input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-val { min-width: 42px; text-align: right; font-weight: 700; color: var(--accent); font-size: 14px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  cursor: pointer;
  font-family: 'Sarabun', sans-serif;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-outline { background: transparent; color: var(--text2); border-color: var(--border2); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: var(--surface2); color: var(--text2); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--border2); color: var(--text); }
.btn-green { background: var(--green-bg); color: var(--green); border-color: var(--green-bd); }
.btn-green:hover { background: #d1fae5; }
.btn-red { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }
.btn-red:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── DIVIDER ── */
.sdiv {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 20px 0 14px;
  display: flex; align-items: center; gap: 10px;
}
.sdiv::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── INFO BOXES ── */
.info-box { border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.info-blue   { background: var(--blue-bg);   color: var(--blue);  border: 1px solid var(--blue-bd); }
.info-amber  { background: var(--accent-bg); color: var(--accent2); border: 1px solid var(--accent-border); }
.info-green  { background: var(--green-bg);  color: var(--green); border: 1px solid var(--green-bd); }

/* ── TABLES ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--surface2); }
.num { text-align: right; font-weight: 600; }

/* ── BADGES ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge-sale      { background: var(--blue-bg);   color: var(--blue);  border: 1px solid var(--blue-bd); }
.badge-brand     { background: var(--accent-bg); color: var(--accent2); border: 1px solid var(--accent-border); }
.badge-approved  { background: var(--green-bg);  color: var(--green); border: 1px solid var(--green-bd); }
.badge-submitted { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--accent-border); }
.badge-rejected  { background: var(--red-bg);    color: var(--red);   border: 1px solid var(--red-bd); }
.badge-draft     { background: var(--surface2);  color: var(--muted); border: 1px solid var(--border); }
.badge-pending   { background: #fef9c3; color: #92400e; border: 1px solid #fde68a; }

/* ── COMMISSION ENTRIES ── */
.entry {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}
.entry-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
  font-family: 'Anuphan', sans-serif; font-weight: 700; font-size: 13px;
}
.entry-remove {
  background: none; border: none; color: var(--muted2);
  cursor: pointer; font-size: 16px; line-height: 1;
  padding: 2px 4px; border-radius: 4px;
  transition: all 0.15s;
}
.entry-remove:hover { background: var(--red-bg); color: var(--red); }

/* Commission summary */
.comm-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}
.comm-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px; gap: 12px;
}
.comm-row:last-child { border-bottom: none; }
.comm-row.total {
  font-family: 'Anuphan', sans-serif; font-size: 18px; font-weight: 700;
  color: var(--accent); padding-top: 16px;
}
.comm-section-head {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 12px 0 6px;
}

/* ── STAT CARDS ── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
}
.stat-accent::before { background: var(--accent); }
.stat-green::before  { background: var(--green); }
.stat-blue::before   { background: var(--blue); }
.stat-red::before    { background: var(--red); }
.stat-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
.stat-val { font-family: 'Anuphan', sans-serif; font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-sub { font-size: 12px; color: var(--muted2); margin-top: 4px; }
.stat-accent .stat-val { color: var(--accent); }
.stat-green .stat-val  { color: var(--green); }
.stat-blue .stat-val   { color: var(--blue); }
.stat-red .stat-val    { color: var(--red); }

/* ── TREND BARS ── */
.trend-bars {
  display: flex; align-items: flex-end;
  gap: 6px; height: 80px; padding: 0 4px;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.bar-fill { width: 100%; border-radius: 3px 3px 0 0; background: var(--accent); opacity: 0.5; transition: opacity 0.2s; min-height: 4px; }
.bar-fill:hover { opacity: 1; }
.bar-fill.current { opacity: 0.9; }
.bar-label { font-size: 10px; color: var(--muted2); }
.bar-amt   { font-size: 10px; color: var(--accent); font-weight: 700; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.97) translateY(8px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: none; }
.modal-head {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal-title { font-family: 'Anuphan', sans-serif; font-size: 16px; font-weight: 700; }
.modal-close {
  background: var(--surface2); border: none;
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; font-size: 14px; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--red-bg); color: var(--red); }
.modal-body { padding: 24px; }
.modal-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── SAVE BAR ── */
.save-bar {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; gap: 10px; z-index: 200;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.save-btn {
  padding: 11px 20px;
  border-radius: 10px; border: none;
  cursor: pointer; font-family: 'Sarabun', sans-serif;
  font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow);
  transition: all 0.15s;
}
.save-draft  { background: var(--surface); color: var(--text2); border: 1.5px solid var(--border2); }
.save-draft:hover { border-color: var(--accent); }
.save-submit { background: var(--accent); color: #fff; }
.save-submit:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(217,119,6,0.3); }

/* ── HISTORY ITEMS ── */
.hist-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 6px;
  font-size: 13px;
  transition: border 0.15s;
  cursor: pointer;
}
.hist-item:hover { border-color: var(--accent); }

/* ── COST TABLE ── */
.cost-table-wrap {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 12px;
}
.cost-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--border);
}
.cost-row:last-of-type { border-bottom: none; }
.cost-row .fi { padding: 5px 9px; font-size: 13px; }
.cost-total-row {
  display: flex; justify-content: space-between;
  padding: 10px 0 2px; font-weight: 700; font-size: 14px;
}

/* ── COMM RESULT BOX ── */
.comm-result-box {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 10px; margin-top: 14px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: 10px; padding: 14px;
}
.crb-item { text-align: center; }
.crb-label { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.crb-val { font-family: 'Anuphan', sans-serif; font-size: 18px; font-weight: 700; }
.crb-val.blue   { color: var(--blue); }
.crb-val.green  { color: var(--green); }
.crb-val.accent { color: var(--accent); }

/* ── CALL ITEMS ── */
.call-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 8px; margin-bottom: 10px; }
.call-item { display: flex; align-items: center; gap: 6px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
.call-item .fi { flex: 1; padding: 5px 8px; font-size: 13px; }
.call-num { font-size: 11px; color: var(--muted2); min-width: 18px; }

/* ── IMAGE UPLOAD ── */
.upload-zone {
  border: 2px dashed var(--border2);
  border-radius: 10px; padding: 24px;
  text-align: center; cursor: pointer;
  transition: all 0.15s; background: var(--surface2);
}
.upload-zone:hover { border-color: var(--accent); background: var(--accent-bg); }
.upload-zone.drag  { border-color: var(--accent); background: var(--accent-bg); }
.upload-zone input[type=file] { display: none; }
.upload-icon  { font-size: 28px; margin-bottom: 6px; }
.upload-label { font-size: 13px; color: var(--muted); }
.image-previews { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.img-thumb {
  width: 90px; height: 90px; border-radius: 8px;
  object-fit: cover; border: 1px solid var(--border);
  position: relative; display: inline-block;
}
.img-thumb-wrap { position: relative; display: inline-block; }
.img-remove {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; border: none;
  font-size: 12px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* ── ROI SPECIFIC ── */
.roi-results {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.roi-result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.roi-rl { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
.roi-rv { font-family: 'Anuphan', sans-serif; font-size: 22px; font-weight: 700; }
.roi-rv.accent { color: var(--accent); }
.roi-rv.green  { color: var(--green); }
.roi-rv.blue   { color: var(--blue); }
.roi-rv.red    { color: var(--red); }

/* ── P&L TABLE ── */
.pl-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.pl-tbl th { background: var(--surface2); padding: 9px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; border-bottom: 1px solid var(--border); }
.pl-tbl td { padding: 9px 14px; border-bottom: 1px solid var(--border); }
.pl-tbl .sub td { background: #fafafa; font-weight: 700; }
.pl-tbl .profit td { background: var(--green-bg); color: var(--green); font-weight: 700; }
.pl-tbl .loss td   { background: var(--red-bg);   color: var(--red);   font-weight: 700; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text); color: #fff;
  padding: 10px 20px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: all 0.25s; z-index: 1000;
  box-shadow: var(--shadow-lg); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── UTILITIES ── */
.no-data { text-align: center; padding: 40px; color: var(--muted2); font-size: 14px; }
.loading { text-align: center; padding: 40px; color: var(--muted); font-size: 13px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.section-divider { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 18px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
