/* ==========================================================================
   Branch Sales Application - Corporate Design System & Theme Styling
   Corporate Color Scheme: Corporate Navy Blue, Snow White, Emerald Green
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
  /* Corporate Palette Tokens */
  --primary-950: #0f172a;
  --primary-900: #1e3a8a; /* Corporate Navy Blue */
  --primary-800: #1e40af;
  --primary-700: #1d4ed8;
  --primary-600: #2563eb;
  --primary-500: #3b82f6;
  --primary-50:  #eff6ff;

  --accent-green: #10b981; /* Corporate Emerald Green */
  --accent-green-dark: #059669;
  --accent-green-light: #ecfdf5;

  --accent-purple: #7c3aed;
  --accent-gold: #d97706;
  --accent-rose: #e11d48;

  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-white: #ffffff;

  --border-light: #e2e8f0;
  --border-focus: #2563eb;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: 'Plus Jakarta Sans', 'Prompt', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Layout Shell */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
  width: 275px;
  background: var(--bg-sidebar);
  color: var(--text-white);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 1.5rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary-600), var(--accent-green-dark));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-subtitle {
  font-size: 0.7rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  list-style: none;
  flex-grow: 1;
}

.nav-item button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: left;
}

.nav-item button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #f1f5f9;
}

.nav-item button.active {
  background: var(--primary-600);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

/* User Account Profile Card in Sidebar */
.user-profile-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: auto;
}

.avatar-circle {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-green-dark), var(--primary-600));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 0.9rem;
}

.user-info {
  flex-grow: 1;
  overflow: hidden;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  display: inline-block;
  font-size: 0.68rem;
  color: #60a5fa;
  font-weight: 500;
}

.btn-logout {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.btn-logout:hover {
  color: var(--accent-rose);
  background: rgba(225, 29, 72, 0.1);
}

/* Main Workspace */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Top Header Bar */
.top-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.page-title-group h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
}

.page-title-group p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* THAI HELP TOOLTIP ITEM [ ? ] */
.help-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.72rem;
  font-weight: 800;
  border-radius: 50%;
  cursor: help;
  margin-left: 0.35rem;
  transition: var(--transition-fast);
  user-select: none;
}

.help-tooltip:hover {
  background: var(--primary-600);
  color: #ffffff;
}

/* Tooltip Popover Card */
.help-tooltip .tooltip-card {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: 135%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: 240px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  pointer-events: none;
  transition: all 0.2s ease;
  text-align: left;
}

.help-tooltip .tooltip-card::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #0f172a transparent transparent transparent;
}

.help-tooltip:hover .tooltip-card {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* View Section Containers */
.view-section {
  display: none;
  padding: 2rem;
  animation: fadeIn 0.25s ease-in-out;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Control Bar Filters */
.control-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-item label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.select-control, .input-control {
  padding: 0.5rem 0.85rem;
  font-size: 0.88rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--text-main);
  outline: none;
  font-family: inherit;
  transition: var(--transition-fast);
}

.select-control:focus, .input-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* KPI Cards Grid */
.kpi-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  transition: var(--transition-fast);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-info-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.kpi-info-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.kpi-info-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.kpi-icon-box {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.icon-blue { background: var(--primary-50); color: var(--primary-600); }
.icon-green { background: #ecfdf5; color: var(--accent-green-dark); }
.icon-purple { background: #f3e8ff; color: var(--accent-purple); }
.icon-gold { background: #fffbeeb; color: var(--accent-gold); }

/* Dashboard Chart Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

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

.chart-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Data Tables */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.table-card-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
}

.table-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th {
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-mono { font-family: monospace; }
.text-gray { color: var(--text-muted); }
.text-blue { color: var(--primary-600); }
.text-green { color: var(--accent-green-dark); }
.text-purple { color: var(--accent-purple); }
.text-gold { color: #d97706; }

/* Status Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-approved { background: #dcfce7; color: #15803d; }
.badge-pending { background: #fef9c3; color: #a16207; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-rejected { background: #ffe4e6; color: #be123c; }
.badge-green { background: #ecfdf5; color: #047857; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

/* Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary-600);
  color: white;
}
.btn-primary:hover { background: var(--primary-700); }

.btn-success {
  background: var(--accent-green-dark);
  color: white;
}
.btn-success:hover { background: #047857; }

.btn-secondary {
  background: white;
  border-color: var(--border-light);
  color: var(--text-main);
}
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-danger {
  background: var(--accent-rose);
  color: white;
}
.btn-danger:hover { background: #be123c; }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
}

/* Upload Dropzone Styling */
.dropzone-container {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 2.5rem;
  text-align: center;
  background: #ffffff;
  cursor: pointer;
  transition: var(--transition-fast);
  margin-bottom: 1.5rem;
}

.dropzone-container:hover, .dropzone-container.dragover {
  border-color: var(--primary-500);
  background: var(--primary-50);
}

.dropzone-icon {
  font-size: 2.5rem;
  color: var(--primary-600);
  margin-bottom: 0.75rem;
}

/* Login Page View Overlay */
.auth-page-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 999999;
}

.auth-card {
  background: white;
  width: 100%;
  max-width: 440px;
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-xl);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
}

.quick-login-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.chip-btn {
  background: #f1f5f9;
  border: 1px solid var(--border-light);
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition-fast);
}

.chip-btn:hover {
  background: var(--primary-50);
  border-color: var(--primary-500);
  color: var(--primary-700);
}

/* Print Documents & PDF Formatting */
@media print {
  .sidebar, .top-header, .control-bar, .no-print, .top-actions {
    display: none !important;
  }

  body, .main-content, .view-section {
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-document {
    padding: 2rem !important;
    box-shadow: none !important;
  }
}

.print-document {
  background: white;
  border-radius: var(--radius-md);
  padding: 2.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

.report-header, .slip-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid #0f172a;
  margin-bottom: 1.5rem;
}

.company-logo-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-badge {
  width: 48px;
  height: 48px;
  background: #0f172a;
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.logo-badge-gold {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #d97706, #f59e0b);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.company-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sub-title {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.85rem;
}

.report-table th, .report-table td {
  border: 1px solid #cbd5e1;
  padding: 0.6rem 0.85rem;
}

.report-table th {
  background: #f1f5f9;
  font-weight: 700;
}

.table-total-row td {
  background: #f8fafc;
  font-weight: 800;
}

.commission-calculation-box {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin: 1.5rem 0;
}

.calc-step {
  text-align: center;
}

.calc-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.calc-value {
  font-size: 1.2rem;
  font-weight: 700;
}

.calc-value-grand {
  font-size: 1.6rem;
  font-weight: 800;
}

.calc-operator {
  font-size: 1.5rem;
  font-weight: 700;
  color: #94a3b8;
}

.signature-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 3rem;
  padding-top: 1rem;
}

.sign-box {
  text-align: center;
  width: 220px;
}

.sign-line {
  border-bottom: 1px solid #0f172a;
  height: 40px;
  margin-bottom: 0.5rem;
}

.sign-title { font-weight: 700; font-size: 0.85rem; }
.sign-sub { font-size: 0.75rem; color: var(--text-muted); }

.stamp-badge {
  border: 3px double #15803d;
  color: #15803d;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transform: rotate(-5deg);
  font-weight: 800;
  text-align: center;
}
