/* ==========================================================================
   PrimeERP Demo — Design Tokens
   Brand green: #2CA01C | Dark mode: deep blue | Font: Poppins
   ========================================================================== */

:root {
  /* Brand */
  --primary: #2CA01C;
  --primary-dark: #238016;
  --primary-light: #E7F5E3;

  /* Light theme */
  --bg: #F7FAF6;
  --surface: #FFFFFF;
  --surface-alt: #F0F5EE;
  --border: #E1E8DE;
  --text: #16241A;
  --text-muted: #5C6B60;

  /* Status */
  --warning: #E8A33D;
  --warning-bg: #FDF3E3;
  --danger: #D14343;
  --danger-bg: #FBE9E9;
  --success: #2CA01C;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(20, 40, 20, 0.06);
  --shadow-lg: 0 12px 32px rgba(20, 40, 20, 0.10);
  --transition: 180ms ease;
}

[data-theme="dark"] {
  --bg: #0B1729;
  --surface: #11213A;
  --surface-alt: #16294A;
  --border: #22334F;
  --text: #E8ECF3;
  --text-muted: #8FA0BC;

  --primary: #3DBF2A;
  --primary-dark: #2CA01C;
  --primary-light: #16294A;

  --warning-bg: #3A2C15;
  --danger-bg: #3A1A1A;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  transition: background var(--transition), color var(--transition);
}

a { color: inherit; text-decoration: none; }

button {
  font-family: 'Poppins', sans-serif;
  cursor: pointer;
}

h1, h2, h3, h4 { font-weight: 600; margin: 0; }
p { margin: 0; }

/* ---------- Theme toggle (shared) ---------- */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition);
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Live pulse signature element ---------- */
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}
.pulse-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  animation: pulse-ring 2s ease-out infinite;
}
@keyframes pulse-ring {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(1.8); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .pulse-dot::after { animation: none; }
}

/* ==========================================================================
   LOGIN PAGE
   ========================================================================== */

.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.login-brand {
  background: linear-gradient(155deg, var(--primary-dark) 0%, var(--primary) 55%, #1F7A13 100%);
  color: #FFFFFF;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: "";
  position: absolute;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12);
  top: -180px;
  right: -180px;
}
.login-brand::after {
  content: "";
  position: absolute;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.10);
  bottom: -140px;
  right: -60px;
}

.login-brand-top { display: flex; align-items: center; gap: 12px; z-index: 1; }
.login-logo-slot {
  background: #FFFFFF;
  border-radius: 10px;
  padding: 10px 18px;
  display: inline-flex;
  align-items: center;
}
.login-logo-slot img {
  height: 36px;
  width: auto;
  display: block;
}
.login-logo-fallback {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #16241A;
}

.login-brand-mid { z-index: 1; max-width: 420px; }
.login-brand-mid h1 {
  font-size: 34px;
  line-height: 1.25;
  font-weight: 600;
  margin-bottom: 14px;
}
.login-brand-mid p {
  font-size: 15px;
  color: rgba(255,255,255,0.85);
  line-height: 1.6;
}

.login-brand-bottom {
  display: flex;
  gap: 28px;
  z-index: 1;
  font-size: 13px;
  color: rgba(255,255,255,0.75);
}
.login-brand-bottom .stat b {
  display: block;
  font-size: 20px;
  color: #fff;
  font-weight: 600;
}

.login-form-side {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: relative;
}

.login-form-side .theme-toggle {
  position: absolute;
  top: 28px;
  right: 32px;
}

.login-box { width: 100%; max-width: 380px; }
.login-box h2 { font-size: 24px; margin-bottom: 6px; }
.login-box .sub { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  transition: border-color var(--transition);
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-btn {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
  transition: background var(--transition), transform var(--transition);
}
.login-btn:hover { background: var(--primary-dark); }
.login-btn:active { transform: scale(0.98); }

.demo-creds {
  margin-top: 22px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
}
.demo-creds b { color: var(--text); }

.login-error {
  display: none;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
}
@media (max-width: 420px) {
  .login-form-side { padding: 24px; }
  .login-form-side .theme-toggle { top: 16px; right: 16px; }
}

/* ==========================================================================
   DASHBOARD
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar — fixed dark green, independent of light/dark content theme */
.sidebar {
  background: #173B12;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
}
.sidebar-brand img { height: 26px; }
.sidebar-logo-slot {
  background: #FFFFFF;
  border-radius: 8px;
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
}
.sidebar-logo-slot img { height: 20px; width: auto; display: block; }
.sidebar-brand .fallback-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.sidebar-brand span { font-weight: 600; font-size: 15px; color: #fff; }

.sidebar-group-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  padding: 16px 12px 6px;
}
.sidebar-group-label:first-of-type { padding-top: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.75);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

.nav-item.soon {
  opacity: 0.55;
  cursor: default;
}
.nav-soon-tag {
  margin-left: auto;
  font-size: 9.5px;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
  padding: 2px 6px;
  border-radius: 999px;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.12);
}
.sidebar-bottom .theme-toggle {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
}
.sidebar-bottom .theme-toggle:hover { border-color: #fff; color: #fff; }

/* Main area */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-left h1 { font-size: 18px; }
.topbar-left .date { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}
[data-theme="dark"] .avatar { background: var(--primary); color: #fff; }

.content {
  padding: 28px 32px 48px;
  flex: 1;
  overflow-y: auto;
}

.content-section { display: none; }
.content-section.active-section { display: block; }

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 36px 0 16px;
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.section-title:first-child { margin-top: 0; }

/* Summary cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.card-value { font-size: 24px; font-weight: 600; }
.card-delta { font-size: 12px; margin-top: 6px; font-weight: 500; }
.card-delta.up { color: var(--primary); }
.card-delta.down { color: var(--danger); }
.card-delta.warn { color: var(--warning); }

/* Panels */
.panels-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.panel-head h3 { font-size: 15px; }
.panel-head .tag {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 3px 9px;
  border-radius: 999px;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }

.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-block;
}
.status-pill.paid { background: var(--primary-light); color: var(--primary); }
[data-theme="dark"] .status-pill.paid { color: #7EDD6B; background: #123018; }
.status-pill.pending { background: var(--warning-bg); color: var(--warning); }
.status-pill.low { background: var(--warning-bg); color: var(--warning); }
.status-pill.out { background: var(--danger-bg); color: var(--danger); }
.status-pill.ok { background: var(--primary-light); color: var(--primary); }
[data-theme="dark"] .status-pill.ok { color: #7EDD6B; background: #123018; }

.stock-bar-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}
.stock-bar-fill { height: 100%; border-radius: 999px; background: var(--primary); }
.stock-bar-fill.low { background: var(--warning); }
.stock-bar-fill.out { background: var(--danger); }

.top-product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.top-product-row:last-child { border-bottom: none; }
.top-product-rank {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-right: 10px;
}

.btn-outline {
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  transition: all var(--transition);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-primary {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--primary-dark); }

.chart-wrap { position: relative; height: 220px; }

.finance-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}
.finance-box {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.finance-box .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.finance-box .amount { font-size: 19px; font-weight: 600; }
.finance-box.income .amount { color: var(--primary); }
.finance-box.expense .amount { color: var(--danger); }

/* POS Sales */
.pos-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
}
.pos-products {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.pos-product {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  text-align: left;
  transition: border-color var(--transition);
}
.pos-product:hover { border-color: var(--primary); }
.pos-product .name { font-size: 13.5px; font-weight: 500; margin-bottom: 4px; }
.pos-product .price { font-size: 12.5px; color: var(--text-muted); }

.pos-cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.pos-cart-item:last-child { border-bottom: none; }
.pos-cart-total {
  display: flex;
  justify-content: space-between;
  padding-top: 14px;
  margin-top: 6px;
  border-top: 2px solid var(--border);
  font-size: 15px;
  font-weight: 600;
}

/* Login view -> Dashboard view swap (single page) */
#dashboardView { display: none; }
#dashboardView.visible { display: grid; }

.menu-btn {
  display: none;
  background: transparent;
  border: none;
  padding: 6px;
  color: var(--text);
  border-radius: var(--radius-sm);
}
.menu-btn svg { width: 22px; height: 22px; display: block; }
.menu-btn:hover { background: var(--surface-alt); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
}
.sidebar-backdrop.open { display: block; }

/* Document creation template (Proforma / Invoice style form) */
.doc-form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}

.items-table-wrap { overflow-x: auto; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table thead tr { background: #173B12; }
.items-table thead th {
  color: #fff;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-align: left;
}
.items-table tbody tr { border-bottom: 1px solid var(--border); }
.items-table td { padding: 6px; vertical-align: middle; }
.items-table input,
.items-table select,
.items-table textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: 'Poppins', sans-serif;
  background: var(--surface);
  color: var(--text);
}
.items-table input:focus,
.items-table select:focus,
.items-table textarea:focus { outline: none; border-color: var(--primary); }
.items-table textarea { resize: vertical; min-height: 38px; height: 38px; }
.items-table .row-total { background: var(--surface-alt); font-weight: 600; }
.no-col { text-align: center; font-weight: 700; color: var(--text-muted); }

.btn-remove {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
}
.btn-remove:hover { background: #A93434; }

.vat-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 0 4px;
}
.switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border-strong, var(--border));
  border-radius: 28px;
  transition: background var(--transition);
}
.slider::before {
  position: absolute; content: "";
  height: 20px; width: 20px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%;
  transition: transform var(--transition);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.vat-label { font-size: 13.5px; font-weight: 500; color: var(--text-muted); }
.vat-label span { font-weight: 700; color: var(--primary); }

.totals-wrap { display: flex; justify-content: flex-end; margin-top: 16px; }
.totals-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.totals-box .tl {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.totals-box .tl:last-child { border-bottom: none; }
.totals-box .tl input {
  width: 130px;
  padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  text-align: right;
}
.totals-box .tl.grand {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14.5px;
}
@media (max-width: 1100px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .panels-grid { grid-template-columns: 1fr; }
  .pos-layout { grid-template-columns: 1fr; }
  .doc-form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .doc-form-grid { grid-template-columns: 1fr; }
  .totals-box { max-width: 100%; }
  .totals-box .tl input { width: 110px; }
  .app-shell { grid-template-columns: 1fr; }
  .cards-grid { grid-template-columns: 1fr; }
  .pos-products { grid-template-columns: repeat(2, 1fr); }
  .finance-split { grid-template-columns: 1fr; }
  .content { padding: 20px 16px 40px; }
  .topbar { padding: 14px 16px; }
  .panel { overflow-x: auto; }
  .menu-btn { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
}
@media (max-width: 480px) {
  .pos-products { grid-template-columns: 1fr 1fr; }
  .cards-grid .card-value { font-size: 20px; }
  .topbar-right span[style*="pulse-dot"] { display: none; }
  .theme-toggle { padding: 6px 10px; font-size: 12px; }
}