:root {
  --green: #0b7a34;
  --green-dark: #075b27;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5ece8;
  --bg: #f5f8f6;
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 70px;
}

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: Inter, "Segoe UI", Arial, sans-serif; -webkit-font-smoothing: antialiased; }

/* Utilities & Overrides */
.btn-primary { --bs-btn-bg: var(--green); --bs-btn-border-color: var(--green); --bs-btn-hover-bg: var(--green-dark); --bs-btn-hover-border-color: var(--green-dark); }
.content { padding: 24px; max-width: 1600px; margin: 0 auto; }

/* Typography */
h1, h2, h3, h4, h5, h6 { color: #111827; font-weight: 600; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* Login Page */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #f7fbf8, #e7f5ec); }
.login-card { width: min(430px, 92vw); background: #fff; border-radius: 16px; padding: 32px; box-shadow: 0 20px 60px rgba(11, 122, 52, 0.1); }
.login-card h1 { font-size: 22px; margin: 12px 0 6px; }
.login-card p { color: var(--muted); font-size: 14px; }
.login-logo { width: 64px; height: 64px; border-radius: 14px; background: var(--green); color: #fff; display: grid; place-items: center; font-size: 30px; font-weight: 800; }

/* App Layout */
.app-shell { display: flex; min-height: 100vh; overflow: hidden; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; scroll-behavior: smooth; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s ease;
  will-change: width, transform;
  flex-shrink: 0;
  z-index: 1040;
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); padding: 20px 10px; }

.sidebar-brand { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 32px; padding: 0 6px; }
.brand-text { transition: opacity 0.2s; white-space: nowrap; overflow: hidden; }
.sidebar.collapsed .brand-text { opacity: 0; width: 0; pointer-events: none; }
.logo-mark { background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; width: 40px; height: 40px; border-radius: 10px; font-size: 20px; flex-shrink: 0; }
.sidebar-toggle { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; border-radius: 8px; transition: transform 0.3s; }
.sidebar.collapsed .sidebar-toggle i { transform: rotate(180deg); }

.sidebar nav { padding-bottom: 24px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; margin: 4px 0;
  color: #4b5563; text-decoration: none; border-radius: 8px; font-weight: 500;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.sidebar nav a i { font-size: 1.1rem; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar.collapsed nav a { padding: 10px; justify-content: center; }
.sidebar.collapsed .nav-label { opacity: 0; width: 0; display: none; }
.sidebar nav a.active, .sidebar nav a:hover { background: #eaf6ee; color: var(--green); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.sidebar::-webkit-scrollbar { width: 4px; }

/* Overlay for Mobile */
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1030; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

/* Topbar */
.topbar { height: 68px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 1020; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 1.1rem; color: #111827; }
.logo-slot { width: 36px; height: 36px; border: 1px dashed #aacdb7; border-radius: 8px; display: grid; place-items: center; color: var(--green); font-weight: 700; overflow: hidden; }
.logo-slot img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-slot:empty::before { content: "F"; }

.topbar-search { flex: 1; max-width: 400px; background: #f4f7f5; border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; display: flex; gap: 8px; align-items: center; transition: background 0.2s; }
.topbar-search:focus-within { background: #fff; border-color: #cbd5e1; box-shadow: 0 0 0 3px rgba(11, 122, 52, 0.1); }
.topbar-search input { border: 0; background: transparent; outline: 0; width: 100%; font-size: 14px; }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line); background: #fff; border-radius: 8px; display: grid; place-items: center; color: #4b5563; transition: background 0.2s; }
.icon-btn:hover { background: #f8faf9; color: #111827; }

/* Cards & Metrics */
.app-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); overflow: hidden; }
.app-card h2, .card-header strong { font-size: 16px; margin: 0; color: #111827; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--line); background: #fff; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }

.metric-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); display: flex; flex-direction: column; gap: 6px; transition: transform 0.2s, box-shadow 0.2s; }
.metric-card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }
.metric-card i { font-size: 22px; color: var(--green); }
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 500; }
.metric-card strong { font-size: 24px; color: #111827; }

/* Table Reset & Base */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { margin: 0; width: 100%; border-collapse: separate; border-spacing: 0; }
.table thead th { background: #f8faf9; color: #4b5563; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 12px 16px; border-bottom: 1px solid var(--line); border-top: 0; white-space: nowrap; }
.table tbody td { padding: 12px 16px; vertical-align: middle; border-bottom: 1px solid var(--line); color: #374151; font-size: 14px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background-color: #fcfdfc; }

/* Quotation Form Table (Constrained Box) */
#productScrollBody {
  max-height: 55vh; overflow-x: auto; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  scrollbar-width: thin; scrollbar-color: var(--green) #f1f5f2; scrollbar-gutter: stable;
}
#productScrollBody thead th { position: sticky; top: 0; z-index: 5; background: #f8faf9; box-shadow: 0 1px 0 var(--line); }

/* Flexible Columns for Table */
.product-table, .import-table { width: 100%; min-width: 900px; table-layout: fixed; }
.product-table th:nth-child(1) { width: 40px; text-align: center; } /* SL */
.product-table th:nth-child(2) { width: 12%; } /* Category */
.product-table th:nth-child(3) { width: 18%; } /* Product Name */
.product-table th:nth-child(4) { width: 0; display: none; } /* Description (hidden in table header) */
.product-table td:nth-child(4) { width: 0; padding: 0; overflow: hidden; border: 0; } /* Description */
.product-table th:nth-child(5) { width: 10%; } /* Brand */
.product-table th:nth-child(6) { width: 10%; } /* Model */
.product-table th:nth-child(7) { width: 8%; } /* Qty */
.product-table th:nth-child(8) { width: 8%; } /* Unit */
.product-table th:nth-child(9) { width: 12%; } /* Price */
.product-table th:nth-child(10){ width: 12%; } /* Total */
.product-table th:nth-child(11){ width: 60px; text-align: center; } /* Action */

.product-table .form-control, .product-table .form-select, .import-table .form-control { width: 100%; min-width: 0; padding: 6px 10px; font-size: 13px; border-radius: 6px; }
.desc-trigger { width: 100%; text-align: left; background: #fafdf9; border: 1px dashed #cbd5e1; border-radius: 6px; padding: 6px 10px; font-size: 12px; color: #6b7280; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: all 0.2s; display: block; margin-top: 6px; }
.desc-trigger:hover { border-color: var(--green); background: #f0faf3; color: var(--green); }
.desc-trigger.has-value { border-style: solid; background: #fff; color: #374151; }

/* Pills & Forms */
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-group input { display: none; }
.pill-group span { display: block; border: 1px solid #cbd5e1; border-radius: 999px; padding: 8px 16px; background: #fff; cursor: pointer; font-size: 14px; font-weight: 500; color: #4b5563; transition: all 0.2s; }
.pill-group span:hover { background: #f8faf9; border-color: #94a3b8; }
.pill-group input:checked + span { background: #eaf6ee; border-color: var(--green); color: var(--green); }

.suggest-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.suggest-grid div { background: #f8faf9; border: 1px solid var(--line); border-radius: 8px; padding: 12px; text-align: center; }
.suggest-grid span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.suggest-grid strong { font-size: 16px; color: #111827; }

.summary-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding: 12px 0; font-size: 14px; }
.summary-row:last-child { border-bottom: 0; }
.summary-row span { color: #6b7280; }
.summary-row strong { color: #111827; }
.summary-row.total { padding-top: 16px; border-top: 2px solid #e2e8f0; border-bottom: 0; }
.summary-row.total strong { font-size: 20px; color: var(--green); }
.sticky-summary { position: sticky; top: 92px; }

.logo-preview { width: 160px; height: 100px; border: 1px dashed #cbd5e1; border-radius: 8px; background: #f8faf9; display: grid; place-items: center; overflow: hidden; padding: 8px; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Responsive Adjustments */

/* Tablet & Smaller Desktop */
@media (max-width: 1200px) {
  .product-table th:nth-child(5), /* Brand */
  .product-table td:nth-child(5),
  .product-table th:nth-child(6), /* Model */
  .product-table td:nth-child(6),
  .product-table th:nth-child(8), /* Unit */
  .product-table td:nth-child(8) {
    display: none; width: 0; padding: 0;
  }
  .product-table th:nth-child(2) { width: 15%; }
  .product-table th:nth-child(3) { width: 25%; }
  .product-table th:nth-child(7) { width: 10%; }
  .product-table th:nth-child(9) { width: 15%; }
  .product-table th:nth-child(10){ width: 15%; }
  .product-table { min-width: 700px; }
}

/* Mobile Sidebar & Layout */
@media (max-width: 767px) {
  .sidebar { position: fixed; top: 0; left: 0; z-index: 1050; transform: translateX(-100%); width: 280px; }
  .sidebar.show { transform: translateX(0); box-shadow: 2px 0 20px rgba(0,0,0,0.1); }
  .sidebar.collapsed { width: 280px; padding: 20px 14px; }
  .sidebar.collapsed .brand-text { opacity: 1; width: auto; pointer-events: auto; }
  .sidebar.collapsed .nav-label { opacity: 1; width: auto; display: inline; }
  .sidebar.collapsed nav a { padding: 10px 14px; justify-content: flex-start; }
  
  .topbar { padding: 0 16px; height: 60px; }
  .content { padding: 16px; }
  .page-head { flex-direction: column; gap: 12px; }
  .page-head h1 { font-size: 20px; }
  .sticky-summary { position: static; }
  .app-card h2 { font-size: 15px; }

  /* ─── Load Calculation Table → Vertical Mobile Cards ─── */
  #loadTable { display: block; min-width: 0; width: 100%; }
  #loadTable thead { display: none; }
  #loadTable tbody { display: flex; flex-direction: column; gap: 16px; }
  #loadTable tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    position: relative;
  }
  #loadTable td { display: flex; flex-direction: column; padding: 0; border: 0; }

  /* SL — spans full width as the card header */
  #loadTable td.sl {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    font-weight: 600;
    font-size: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
    color: var(--green);
  }
  #loadTable td.sl::before { content: "Load #"; color: #111827; margin-right: 4px; }

  /* Load Name — spans full width */
  #loadTable td:nth-child(2) { grid-column: 1 / -1; }
  #loadTable td:nth-child(2)::before { content: "Load Name"; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 4px; font-weight: 600; }

  /* Qty */
  #loadTable td:nth-child(3)::before { content: "Qty"; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 4px; font-weight: 600; }

  /* Watt Rating */
  #loadTable td:nth-child(4)::before { content: "Watt Rating"; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 4px; font-weight: 600; }

  /* Backup When No Sun */
  #loadTable td:nth-child(5)::before { content: "Backup (hrs)"; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 4px; font-weight: 600; }

  /* Total Watt */
  #loadTable td.total-watt::before { content: "Total Watt"; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 4px; font-weight: 600; }
  #loadTable td.total-watt { background: #f8faf9; border-radius: 8px; padding: 8px !important; font-weight: 600; color: var(--green); }

  /* Watt Hour */
  #loadTable td.watt-hour::before { content: "Watt Hour"; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 4px; font-weight: 600; }
  #loadTable td.watt-hour { background: #f8faf9; border-radius: 8px; padding: 8px !important; font-weight: 600; color: var(--green); }

  /* Action (Delete Button) — top right corner */
  #loadTable td:nth-child(8) { position: absolute; top: 12px; right: 16px; width: auto !important; }
  #loadTable td:nth-child(8) button { padding: 4px 8px; font-size: 12px; }

  /* Inputs in load table - full width */
  #loadTable .form-control { width: 100%; }

  /* ─── Import Table → Vertical Mobile Cards ─── */
  .import-table { display: block; min-width: 0; width: 100%; }
  .import-table thead { display: none; }
  .import-table tbody { display: flex; flex-direction: column; gap: 16px; }
  .import-table tr {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    position: relative;
  }
  .import-table td { display: flex; flex-direction: column; padding: 0; border: 0; margin-bottom: 12px; width: 100% !important; }
  .import-table td:last-child { margin-bottom: 0; }

  /* SL in import */
  .import-table td:nth-child(1) { flex-direction: row; align-items: center; font-weight: 600; font-size: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 14px; color: var(--green); }
  .import-table td:nth-child(1)::before { content: "Item"; color: #111827; margin-right: 4px; }

  /* Action (Delete) on import table */
  .import-table td:nth-child(10) { position: absolute; top: 12px; right: 16px; width: auto !important; margin: 0; }

  /* Labels on import table */
  .import-table td[data-label]::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 6px; font-weight: 600; }

  /* FOB Total highlight */
  .import-table td.fob-total { background: #f8faf9; border-radius: 8px; padding: 8px !important; font-weight: 600; color: var(--green); }

  /* ─── Product Table Mobile Cards ─── */
  #productScrollBody { max-height: none; overflow: visible; border: 0; background: transparent; }
  .product-table { display: block; min-width: 0; width: 100%; }
  .product-table thead { display: none; }
  .product-table tbody { display: flex; flex-direction: column; gap: 16px; }
  .product-table tr { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); position: relative; }
  
  .product-table td { display: flex; flex-direction: column; padding: 0; border: 0; margin-bottom: 12px; width: 100% !important; }
  .product-table td:last-child { margin-bottom: 0; }
  
  /* Bring back hidden columns on mobile */
  .product-table td:nth-child(5), .product-table td:nth-child(6), .product-table td:nth-child(8) { display: flex; }
  
  /* SL Number */
  .product-table td:nth-child(1) { flex-direction: row; align-items: center; justify-content: space-between; font-weight: 600; font-size: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 16px; color: var(--green); }
  .product-table td:nth-child(1)::before { content: "Item"; color: #111827; }
  
  /* Action Button (Delete) */
  .product-table td:nth-child(11) { position: absolute; top: 12px; right: 16px; width: auto !important; margin: 0; }
  .product-table td:nth-child(11) button { padding: 4px 8px; font-size: 12px; }
  
  /* Add labels via data-label */
  .product-table td[data-label]::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin-bottom: 6px; font-weight: 600; }
  
  /* Special layout for Category + Name + Desc */
  .product-table td:nth-child(3) { margin-bottom: 6px; }
  .product-table td:nth-child(3) .product-select { margin-bottom: 8px; }
  
  /* Qty & Unit inline */
  .product-table td:nth-child(7), .product-table td:nth-child(8) { display: inline-flex; width: 48% !important; margin-right: 2%; vertical-align: top; }
  
  /* Price & Total inline */
  .product-table td:nth-child(9), .product-table td:nth-child(10) { display: inline-flex; width: 48% !important; margin-right: 2%; vertical-align: top; }
  .product-table td:nth-child(10) { width: 50% !important; margin-right: 0; }
  .product-table td:nth-child(10) input { font-weight: 600; color: var(--green); background: #f8faf9; border-color: #cbd5e1; }

  /* ─── Suggest Grid for small screens ─── */
  .suggest-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .suggest-grid div { padding: 10px; }
  .suggest-grid span { font-size: 10px; }
  .suggest-grid strong { font-size: 14px; }

  /* Section title wrapping */
  .section-title { flex-wrap: wrap; gap: 8px; }
  .section-title h2 { flex: 1; min-width: 0; }
}

@media (max-width: 480px) {
  .metric-card { min-height: 100px; padding: 16px; }
  .metric-card i { font-size: 20px; }
  .metric-card strong { font-size: 20px; }

  /* Single column suggest-grid on very small screens */
  .suggest-grid { grid-template-columns: 1fr; }
}
