/* 
 * Unique Civil Engineering Laboratory Pvt. Ltd.
 * Offline Invoice Generator - Application Stylesheet
 */

:root {
  --primary-900: #0b192e;
  --primary-800: #0f2043;
  --primary-700: #1e3a8a;
  --primary-600: #2563eb;
  --primary-500: #3b82f6;
  --primary-100: #dbeafe;
  --primary-50: #eff6ff;

  --accent-amber: #d97706;
  --accent-green: #059669;
  --accent-red: #dc2626;

  --surface-bg: #f8fafc;
  --surface-card: #ffffff;
  --surface-hover: #f1f5f9;
  
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-dark: #334155;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

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

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--surface-bg);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

/* Sidebar Navigation */
.app-sidebar {
  width: 260px;
  background-color: var(--primary-900);
  color: #f1f5f9;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 3px;
  object-fit: contain;
}

.sidebar-title h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: #ffffff;
  line-height: 1.2;
}

.sidebar-title span {
  font-size: 11px;
  color: #94a3b8;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #cbd5e1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.2s ease;
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

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

.nav-item svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.offline-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background-color: rgba(5, 150, 105, 0.15);
  color: #34d399;
  border-radius: 20px;
  font-weight: 600;
  font-size: 11px;
}

.offline-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #10b981;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}

/* Header Topbar */
.app-topbar {
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
}

.page-breadcrumb {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-900);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Page Views */
.page-view {
  display: none;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

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

/* Common Card Styles */
.card {
  background: var(--surface-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Stat Cards (Dashboard) */
.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.blue { background-color: #eff6ff; color: #2563eb; }
.stat-icon.green { background-color: #ecfdf5; color: #059669; }
.stat-icon.amber { background-color: #fffbeb; color: #d97706; }
.stat-icon.purple { background-color: #f5f3ff; color: #7c3aed; }

.stat-info .stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-info .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Quick Actions Bar */
.quick-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

/* Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary-700);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--primary-800);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
  background-color: #ffffff;
  border-color: var(--border-medium);
  color: var(--text-main);
}
.btn-secondary:hover {
  background-color: var(--surface-hover);
  border-color: var(--border-dark);
}

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

.btn-danger {
  background-color: #fee2e2;
  color: var(--accent-red);
  border-color: #fca5a5;
}
.btn-danger:hover {
  background-color: var(--accent-red);
  color: #ffffff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--primary-700);
}

/* Form Styles */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
}

.form-label span.req {
  color: var(--accent-red);
}

.form-control {
  padding: 8px 12px;
  font-size: 13.5px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--text-main);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
  width: 100%;
}

.form-control:focus {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.form-control[readonly] {
  background-color: #f8fafc;
  cursor: default;
}

/* Compact Upper Meta Section in Invoice Builder */
.invoice-meta-compact-bar {
  background: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.meta-compact-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.meta-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 140px;
}

.meta-field label {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-900);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.meta-field label span.req {
  color: var(--accent-red);
}

.meta-field input.form-control-sm {
  padding: 5px 8px;
  height: 32px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.meta-field input.form-control-sm:focus {
  background-color: #ffffff;
  border-color: var(--primary-600);
}

.meta-field.field-project {
  flex: 2.2;
  min-width: 260px;
}

.meta-field.field-inv-num {
  flex: 0.9;
  min-width: 110px;
}

.meta-field.field-inv-date {
  flex: 0.9;
  min-width: 110px;
}

.meta-field.field-client {
  flex: 1.4;
  min-width: 180px;
}

.meta-field.field-contractor {
  flex: 1.3;
  min-width: 170px;
}

.meta-field.field-contract-no {
  flex: 1.2;
  min-width: 150px;
}

.meta-field.field-ref-no {
  flex: 0.8;
  min-width: 100px;
}

/* Interactive Invoice Builder Table Container */
.invoice-builder-table-wrap {
  width: 100%;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  overflow: visible !important; /* CRITICAL: Never clip floating dropdowns! */
  min-height: 320px; /* Low limit: gives ample workspace */
  position: relative;
  margin-bottom: 16px;
}

.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
}

.invoice-items-table th {
  background-color: var(--primary-900);
  color: #ffffff;
  font-weight: 700;
  font-size: 12.5px;
  padding: 9px 10px;
  border: none;
  border-bottom: 2px solid var(--primary-700);
}

.invoice-items-table th:first-child {
  border-top-left-radius: var(--radius-md);
}

.invoice-items-table th:last-child {
  border-top-right-radius: var(--radius-md);
}

.invoice-items-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  position: relative;
}

.invoice-item-row:hover {
  background-color: #f8fafc;
}

.invoice-item-row:focus-within {
  z-index: 100 !important;
  position: relative;
  background-color: #f0f7ff;
}

/* Custom Item Columns */
.invoice-items-table th.col-sn { width: 45px; text-align: center; }
.invoice-items-table th.col-desc { min-width: 300px; }
.invoice-items-table th.col-unit { width: 95px; text-align: center; }
.invoice-items-table th.col-qty { width: 95px; text-align: right; }
.invoice-items-table th.col-rate { width: 120px; text-align: right; }
.invoice-items-table th.col-total { width: 130px; text-align: right; }
.invoice-items-table th.col-remarks { width: 120px; }
.invoice-items-table th.col-actions { width: 45px; text-align: center; }

/* Searchable Autocomplete Dropdown - High Visibility Floating Portal */
.autocomplete-container {
  position: relative;
  width: 100%;
}

.autocomplete-container:focus-within {
  z-index: 9999;
}

.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 440px;
  max-width: 580px;
  width: max-content;
  background: #ffffff;
  border: 2px solid var(--primary-600);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  z-index: 999999 !important;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.25), 0 4px 10px rgba(0, 0, 0, 0.1);
  display: none;
}

.autocomplete-dropdown.show {
  display: block;
  animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.autocomplete-category-group {
  padding: 6px 12px;
  background-color: #0f2043;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: background-color 0.1s ease;
}

.autocomplete-item:hover, .autocomplete-item.highlighted {
  background-color: #eff6ff;
}

.autocomplete-item .item-title {
  font-weight: 600;
  color: #0f172a;
  font-size: 13.5px;
  line-height: 1.35;
  flex: 1;
}

.autocomplete-item .item-meta {
  font-size: 12px;
  color: #1e40af;
  font-weight: 700;
  background: #dbeafe;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.autocomplete-item:hover, .autocomplete-item.highlighted {
  background-color: var(--primary-50);
}

.autocomplete-item .item-title {
  font-weight: 500;
  color: var(--text-main);
}

.autocomplete-item .item-meta {
  font-size: 11.5px;
  color: var(--primary-600);
  font-weight: 600;
  white-space: nowrap;
}

/* Rate Overridden Badge */
.override-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-amber);
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 4px;
  padding: 1px 4px;
  margin-top: 2px;
}

/* Invoice Calculations Summary Box */
.invoice-summary-box {
  background: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-top: 20px;
  margin-left: auto;
  max-width: 480px;
  box-shadow: var(--shadow-sm);
}

.calc-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border-light);
  font-size: 14px;
}

.calc-card-row.total-row {
  border-top: 2px solid var(--border-dark);
  border-bottom: none;
  padding-top: 12px;
  margin-top: 8px;
  font-size: 18px;
  font-weight: 800;
  color: var(--primary-900);
}

.summary-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.amount-words-banner {
  background-color: #f8fafc;
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--primary-600);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 13px;
}

.amount-words-banner strong {
  color: var(--primary-900);
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 16px;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 580px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal-card {
  transform: scale(1);
}

.modal-card.modal-lg {
  max-width: 900px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-900);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background-color: #f8fafc;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  border-left: 4px solid var(--primary-600);
  animation: slideIn 0.2s ease-out;
  min-width: 280px;
  max-width: 420px;
}

.toast.toast-success { border-left-color: var(--accent-green); }
.toast.toast-error { border-left-color: var(--accent-red); }
.toast.toast-warning { border-left-color: var(--accent-amber); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Filter / Search Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-input-wrapper input {
  padding-left: 34px;
}

.search-input-wrapper svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: var(--text-muted);
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
  .app-sidebar {
    position: fixed;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .mobile-menu-toggle {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .page-view {
    padding: 16px;
  }
  .dashboard-stats-grid {
    grid-template-columns: 1fr;
  }
  .invoice-summary-box {
    max-width: 100%;
  }
}
