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

:root {
  --primary: #1565C0;
  --primary-dark: #0D47A1;
  --primary-light: #42A5F5;
  --primary-pale: #E3F2FD;
  --accent: #00B0FF;
  --white: #ffffff;
  --bg: #F0F6FF;
  --bg2: #E8F1FB;
  --card: rgba(255,255,255,0.95);
  --border: rgba(21,101,192,0.12);
  --text: #1A2B4A;
  --text2: #5680A8;
  --danger: #C62828;
  --danger-pale: #FFEBEE;
  --success: #2E7D32;
  --success-pale: #E8F5E9;
  --warn: #F57F17;
  --warn-pale: #FFF8E1;
  --shadow: 0 8px 40px rgba(21,101,192,0.10);
  --shadow-hover: 0 20px 60px rgba(21,101,192,0.18);
  --radius: 20px;
  --radius-sm: 12px;
  --nav-h: 72px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Prompt', 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== PARTICLES ===== */
.bg-particles { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.particle {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle, rgba(66,165,245,0.18), transparent);
  animation: floatParticle linear infinite;
}
@keyframes floatParticle {
  0%   { transform: translateY(100vh) scale(0); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.4; }
  100% { transform: translateY(-20vh) scale(1); opacity: 0; }
}

/* ===== NAVBAR ===== */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 30px rgba(21,101,192,0.08);
  transition: all 0.3s;
}
.navbar.scrolled { background: rgba(255,255,255,0.97); box-shadow: 0 4px 40px rgba(21,101,192,0.14); }
.nav-container {
  max-width: 1440px; margin: 0 auto;
  height: 100%; padding: 0 28px;
  display: flex; align-items: center; gap: 24px;
}
.nav-logo { display: flex; align-items: center; gap: 12px; text-decoration: none; flex-shrink: 0; }
.logo-icon {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px;
  box-shadow: 0 4px 16px rgba(21,101,192,0.25);
  animation: logoPulse 3s ease-in-out infinite;
}
@keyframes logoPulse {
  0%,100% { box-shadow: 0 4px 16px rgba(21,101,192,0.25); }
  50% { box-shadow: 0 4px 28px rgba(21,101,192,0.45); }
}
.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-main { font-size: 18px; font-weight: 700; color: var(--primary-dark); }
.logo-sub { font-size: 11px; font-weight: 400; color: var(--text2); }

.nav-links { display: flex; list-style: none; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.nav-link {
  display: block; padding: 8px 14px; border-radius: 10px;
  text-decoration: none; font-size: 13px; font-weight: 500; color: var(--text2);
  transition: all 0.25s; position: relative; white-space: nowrap;
}
.nav-link:hover, .nav-link.active { color: var(--primary); background: var(--primary-pale); }
.nav-link.active::after {
  content: ''; position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 18px; height: 3px; border-radius: 2px; background: var(--primary);
}
.nav-actions { display: flex; align-items: center; gap: 10px; margin-left: 12px; flex-shrink: 0; }
.btn-logout {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1.5px solid #FFCDD2; background: #FFEBEE; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #C62828;
  transition: all 0.25s;
}
.btn-logout:hover { background: #EF5350; color: white; border-color: #EF5350; transform: scale(1.05); }
.user-avatar { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 10px; border-radius: 12px; transition: 0.25s; }
.user-avatar:hover { background: var(--primary-pale); }
.avatar-img {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.user-info { display: flex; flex-direction: column; line-height: 1.3; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role { font-size: 11px; color: var(--text2); }

/* ===== MAIN ===== */
.main-content {
  max-width: 1440px; margin: 0 auto;
  padding: calc(var(--nav-h) + 32px) 28px 60px;
  position: relative; z-index: 1;
}
.section { display: none; animation: sectionIn 0.45s ease forwards; }
.section.active { display: block; }
@keyframes sectionIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px; flex-wrap: wrap; gap: 16px;
}
.section-title { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.section-subtitle { font-size: 13px; color: var(--text2); margin-top: 4px; }
.date-display { display: flex; flex-direction: column; align-items: flex-end; }
.date-display span:first-child { font-size: 13px; font-weight: 500; color: var(--text2); }
.date-display span:last-child { font-size: 20px; font-weight: 700; color: var(--primary); }

/* ===== DASHBOARD KPI ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 18px; margin-bottom: 22px; }
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  display: flex; align-items: flex-start; gap: 14px;
  box-shadow: var(--shadow);
  transition: all 0.35s cubic-bezier(0.34,1.56,0.64,1);
  opacity: 0; animation: cardIn 0.6s ease forwards;
  position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transform: scaleX(0); transform-origin: left; transition: transform 0.4s ease;
}
.kpi-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-hover); }
.kpi-card:hover::before { transform: scaleX(1); }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(28px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.kpi-icon {
  width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon.revenue  { background: linear-gradient(135deg,#1565C0,#42A5F5); color: white; }
.kpi-icon.customers { background: linear-gradient(135deg,#0277BD,#4FC3F7); color: white; }
.kpi-icon.products  { background: linear-gradient(135deg,#6A1B9A,#AB47BC); color: white; }
.kpi-icon.invoices  { background: linear-gradient(135deg,#1B5E20,#66BB6A); color: white; }
.kpi-content { flex: 1; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--text2); font-weight: 500; margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; }
.kpi-change { font-size: 11px; margin-top: 6px; display: flex; align-items: center; gap: 3px; color: var(--text2); }

/* ===== SHORTCUTS ===== */
.shortcuts { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.shortcut-btn {
  padding: 10px 18px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--card);
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--primary);
  cursor: pointer; transition: all 0.25s;
  box-shadow: 0 2px 8px rgba(21,101,192,0.08);
}
.shortcut-btn:hover { background: var(--primary); color: white; border-color: var(--primary); transform: translateY(-2px); }

/* ===== CHARTS ===== */
.charts-row { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 22px; }
.chart-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.chart-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.chart-title { font-size: 16px; font-weight: 700; color: var(--text); }
.chart-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }
.chart-legend { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.blue { background: var(--primary); }
.legend-dot.light-blue { background: var(--primary-light); }
.chart-canvas-wrap { position: relative; height: 220px; width: 100%; }
.chart-canvas-wrap.donut-wrap { height: 180px; }
.donut-legend { margin-top: 14px; display: flex; flex-direction: column; gap: 7px; }
.dl-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.dl-item strong { margin-left: auto; }
.dl-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ===== TOOLBAR / FILTER ===== */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar label { font-size: 13px; color: var(--text2); display: flex; align-items: center; gap: 6px; }
.filter-bar input[type="date"] {
  padding: 7px 10px; border-radius: 8px; border: 1.5px solid var(--border);
  background: var(--white); font-family: inherit; font-size: 13px; color: var(--text); outline: none;
  transition: border-color 0.25s;
}
.filter-bar input[type="date"]:focus { border-color: var(--primary-light); }

/* ===== BUTTONS ===== */
.btn-add {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border: none; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
  transition: all 0.25s; box-shadow: 0 4px 16px rgba(21,101,192,0.3);
}
.btn-add:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(21,101,192,0.4); }
.btn-secondary {
  padding: 9px 16px; border-radius: 10px;
  border: 1.5px solid var(--primary); background: var(--primary-pale);
  color: var(--primary); font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.25s;
}
.btn-secondary:hover { background: var(--primary); color: white; }
.btn-link {
  background: none; border: none; color: var(--primary); font-family: inherit;
  font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 0;
  transition: opacity 0.2s;
}
.btn-link:hover { opacity: 0.7; }

/* ===== PANEL / TABLE ===== */
.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel.table-panel { padding: 0; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 13px 18px; font-size: 12px; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 2px solid var(--border); text-align: left; white-space: nowrap;
  background: var(--bg);
}
.data-table td {
  padding: 13px 18px; font-size: 13px; color: var(--text);
  border-bottom: 1px solid var(--border); transition: background 0.15s;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--primary-pale); }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.actions { white-space: nowrap; }
.data-table td.actions button {
  padding: 5px 12px; border-radius: 7px; font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.2s; margin-right: 4px;
}
.data-table td.actions button.edit { background: var(--primary-pale); color: var(--primary); }
.data-table td.actions button.edit:hover { background: var(--primary); color: white; }
.data-table td.actions button.del { background: var(--danger-pale); color: var(--danger); }
.data-table td.actions button.del:hover { background: var(--danger); color: white; }
.data-table td.actions button.view-inv { background: var(--success-pale); color: var(--success); }
.data-table td.actions button.view-inv:hover { background: var(--success); color: white; }

/* Loading row */
.loading-row td { text-align: center; padding: 28px; }
.loading-cell { display: inline-flex; align-items: center; gap: 8px; color: var(--text2); font-size: 13px; }
.loading-dots { display: flex; gap: 4px; }
.loading-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--primary-light);
  animation: dotBounce 1s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce { 0%,80%,100% { transform: scale(0.7); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* Empty state */
.empty-state-row td { text-align: center; padding: 36px; color: var(--text2); font-size: 13px; }
.empty-hint { display: inline-block; margin-left: 6px; color: var(--primary); font-weight: 600; }

/* ===== TAG / STATUS ===== */
.tag {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 20px; font-size: 11px; font-weight: 600;
}
.tag.paid { background: var(--success-pale); color: var(--success); }
.tag.pending { background: var(--warn-pale); color: var(--warn); }
.tag.overdue { background: var(--danger-pale); color: var(--danger); }

/* ===== FORM ===== */
.simple-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text2); }
.field input, .field textarea, .field select {
  padding: 10px 14px; border-radius: 9px; border: 1.5px solid var(--border);
  background: var(--bg); font-family: inherit; font-size: 13px; color: var(--text);
  outline: none; transition: border-color 0.2s, box-shadow 0.2s; resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(66,165,245,0.12);
}
.row.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-field label { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text); }
.btn-save {
  padding: 11px 24px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 700;
  transition: all 0.25s; box-shadow: 0 4px 16px rgba(21,101,192,0.3); align-self: flex-start;
}
.btn-save:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(21,101,192,0.4); }
.btn-cancel {
  padding: 11px 20px; border-radius: 10px;
  border: 1.5px solid var(--border); background: transparent;
  color: var(--text2); cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600;
  transition: all 0.2s;
}
.btn-cancel:hover { background: var(--bg); }

/* ===== MODAL (dialog) ===== */
dialog.modal {
  margin: auto;
  padding: 0; border: none; border-radius: var(--radius);
  box-shadow: 0 30px 80px rgba(0,0,0,0.22);
  width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto;
  animation: modalIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
dialog.modal-wide { max-width: 700px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}
dialog.modal::backdrop { background: rgba(13,71,161,0.35); backdrop-filter: blur(4px); }
.modal-title { font-size: 17px; font-weight: 700; color: var(--primary-dark); margin-bottom: 20px; padding: 24px 24px 0; }
dialog.modal .simple-form { padding: 0 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; padding: 16px 24px 24px; }

/* Invoice modal inner */
.invoice-lines { margin-top: 4px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table th { padding: 8px 10px; background: var(--bg); color: var(--text2); font-weight: 600; border-bottom: 1px solid var(--border); text-align: left; }
.mini-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.mini-table td select, .mini-table td input { width: 100%; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-family: inherit; font-size: 12px; outline: none; }
.totals-bar { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text2); padding: 10px 0 4px; border-top: 1px solid var(--border); margin-top: 8px; }
.totals-bar .total { font-weight: 700; color: var(--primary-dark); font-size: 15px; }

/* Journal modal */
.journal-lines { margin-top: 4px; }
.balance-hint { font-size: 12px; color: var(--text2); padding: 6px 0; }
.balance-hint strong { color: var(--primary); }

/* ===== COMPANY PANEL ===== */
.panel.info-panel h3 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.panel.info-panel p { font-size: 13px; color: var(--text2); }

/* ===== REPORTS ===== */
.report-tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.report-tab {
  padding: 9px 18px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--white);
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--text2);
  cursor: pointer; transition: all 0.2s;
}
.report-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.report-panel { display: block; }
.report-panel.hidden { display: none; }
.result-cards { display: flex; gap: 14px; flex-wrap: wrap; }
.result-cards .card {
  flex: 1; min-width: 140px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 18px 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.result-cards .card .label { font-size: 12px; color: var(--text2); font-weight: 500; }
.result-cards .card span:last-child { font-size: 22px; font-weight: 800; color: var(--primary-dark); }
.page-desc { font-size: 13px; color: var(--text2); margin-bottom: 14px; }
.sub-title { font-size: 17px; font-weight: 700; color: var(--text); margin: 20px 0 10px; }

/* ===== INVOICE VIEW ===== */
.invoice-view-wrap { padding: 28px; }
.invoice-view-company { font-size: 14px; color: var(--text2); margin-bottom: 12px; line-height: 1.6; }
.invoice-view-title { font-size: 17px; font-weight: 700; color: var(--primary-dark); margin-bottom: 12px; }
.invoice-view-meta { display: flex; gap: 24px; font-size: 13px; color: var(--text2); margin-bottom: 18px; }
.invoice-view-table { width: 100%; }
.invoice-view-total { text-align: right; font-size: 16px; font-weight: 700; color: var(--primary-dark); margin-top: 12px; }

/* ===== TOAST ===== */
#toast {
  position: fixed; bottom: 28px; right: 28px; z-index: 999;
  padding: 13px 20px; border-radius: 12px;
  background: rgba(255,255,255,0.97); backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.14);
  border-left: 4px solid var(--primary);
  font-size: 14px; font-weight: 600; color: var(--text);
  transform: translateX(120%); opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  max-width: 340px;
}
#toast.show { transform: translateX(0); opacity: 1; }
#toast.success { border-color: var(--success); }
#toast.error { border-color: var(--danger); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .charts-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .nav-links { display: none; }
  .section-title { font-size: 20px; }
  .main-content { padding: calc(var(--nav-h) + 20px) 16px 40px; }
  .row.two-cols { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .charts-row { grid-template-columns: 1fr; }
}
/* Print styling */
.print-only { display: none; }

@media print {
  body { background: white !important; color: black !important; }
  .navbar, .main-content, .modal, dialog, #toast, .bg-particles { display: none !important; }
  .print-only { display: block !important; }
  
  #print-wht-cert {
    font-family: 'Sarabun', sans-serif;
    font-size: 14px;
    color: black;
    line-height: 1.6;
    padding: 20px;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
  }
  
  .cert-title { font-size: 20px; font-weight: bold; text-align: center; margin-bottom: 2px; }
  .cert-subtitle { font-size: 13px; text-align: center; margin-bottom: 25px; }
  
  .cert-box {
    border: 1.5px solid black;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
  }
  
  .cert-section {
    padding: 12px 15px;
    border-bottom: 1.5px solid black;
  }
  .cert-section:last-child { border-bottom: none; }
  .cert-section strong { display: block; margin-bottom: 5px; font-size: 14px; }
  .cert-data { margin-left: 10px; }
  
  .cert-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
  }
  .cert-table th, .cert-table td {
    border: 1.5px solid black;
    padding: 8px 12px;
    font-size: 13px;
  }
  .cert-table th { background: #f2f2f2; text-align: center; }
  .cert-table td.num { text-align: right; }
  .cert-table tr.total-row { font-weight: bold; }
  .cert-table tr.total-row td { background: #f9f9f9; }
  
  .cert-footer {
    font-size: 13px;
    margin-top: 40px;
  }
}

/* ===== COMPANY SWITCHER & MULTI-COMPANY ===== */
.company-switcher-wrap {
  display: flex;
  align-items: center;
  margin-right: 12px;
}
.select-switcher {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--primary-dark);
  font-family: 'Prompt', sans-serif;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: 0 2px 8px rgba(21,101,192,0.08);
}
.select-switcher:hover, .select-switcher:focus {
  border-color: var(--primary-light);
  box-shadow: 0 4px 16px rgba(21,101,192,0.18);
}

.hidden {
  display: none !important;
}

