/* ==========================================
   DESIGN SYSTEM & CSS VARIABLES
   ========================================== */
:root {
  /* Light Mode Palette (Default) */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-sidebar: #0f172a;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --card-hover-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(226, 232, 240, 0.8);
  --modal-bg: rgba(15, 23, 42, 0.4);

  /* Accents */
  --accent-cyan: #0ea5e9;
  --accent-cyan-hover: #0284c7;
  --accent-cyan-light: rgba(14, 165, 233, 0.12);
  
  --accent-emerald: #10b981;
  --accent-emerald-hover: #059669;
  --accent-emerald-light: rgba(16, 185, 129, 0.12);

  --accent-purple: #8b5cf6;
  --accent-purple-light: rgba(139, 92, 246, 0.12);

  --accent-red: #ef4444;
  --accent-red-hover: #dc2626;
  --accent-red-light: rgba(239, 68, 68, 0.12);

  --accent-yellow: #f59e0b;
  --accent-yellow-light: rgba(245, 158, 11, 0.12);
  
  --border-radius-sm: 6px;
  --border-radius-md: 10px;
  --border-radius-lg: 16px;
  --transition-speed: 0.25s;
}

/* Dark Mode Overrides */
body.dark-mode {
  --bg-primary: #0b0f19;
  --bg-secondary: #161e2e;
  --bg-sidebar: #050811;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #273549;
  
  --card-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  --card-hover-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
  --glass-bg: rgba(22, 30, 46, 0.85);
  --glass-border: rgba(39, 53, 73, 0.85);
  --modal-bg: rgba(0, 0, 0, 0.65);
}

/* ==========================================
   BASE STYLES & RESET
   ========================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Outfit', 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

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

ul {
  list-style: none;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--border-radius-sm);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================
   LAYOUT STRUCTURE
   ========================================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: width var(--transition-speed);
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px;
  border-radius: var(--border-radius-md);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.brand-logo {
  max-width: 100%;
  height: auto;
  max-height: 50px;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 12px;
}

.sidebar-nav ul {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
  font-size: 15px;
  border-radius: var(--border-radius-md);
  transition: all var(--transition-speed);
}

.nav-item a i {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

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

.nav-item.active a {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent-cyan) 0%, #0c4a6e 100%);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.btn-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  padding: 10px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition-speed);
}

.btn-theme-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
}

.avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-emerald) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
}

.user-info .user-name {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}

.user-info .user-role {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
}

/* Main Content Layout */
.main-content {
  margin-left: 260px;
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

/* Content Header */
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.header-title-area h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.date-badge {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  padding: 10px 16px;
  border-radius: var(--border-radius-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================
   PANEL SECTIONS (Visibility Control)
   ========================================== */
.panel-section {
  display: none;
  animation: fadeIn 0.3s ease;
}

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

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

/* ==========================================
   DASHBOARD / WIDGET METRICS
   ========================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.metric-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.metric-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-hover-shadow);
}

/* Decorative side stripe based on type */
.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 5px;
}
.metric-card.cyan::before { background-color: var(--accent-cyan); }
.metric-card.blue::before { background-color: #2563eb; }
.metric-card.emerald::before { background-color: var(--accent-emerald); }
.metric-card.purple::before { background-color: var(--accent-purple); }

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 16px;
}
.metric-card.cyan .metric-icon { background-color: var(--accent-cyan-light); color: var(--accent-cyan); }
.metric-card.blue .metric-icon { background-color: rgba(37, 99, 235, 0.1); color: #2563eb; }
.metric-card.emerald .metric-icon { background-color: var(--accent-emerald-light); color: var(--accent-emerald); }
.metric-card.purple .metric-icon { background-color: var(--accent-purple-light); color: var(--accent-purple); }

.metric-details .metric-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 4px;
}

.metric-details .metric-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.metric-trend {
  margin-top: 14px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.metric-trend.upward { color: var(--accent-emerald); }
.metric-trend.text-muted { color: var(--text-muted); }

/* Dashboard Rows Layout */
.dashboard-rows {
  display: flex;
  gap: 24px;
}

.col-8 { flex: 2; min-width: 0; }
.col-4 { flex: 1; min-width: 280px; }

/* ==========================================
   CARDS & CONTAINERS
   ========================================== */
.content-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--card-shadow);
  padding: 24px;
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.card-header h2 {
  font-size: 18px;
  font-weight: 700;
}

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

.card-header-with-action h3 {
  font-size: 16px;
  font-weight: 700;
}

.section-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--border-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-cyan-hover) 100%);
  color: white;
  box-shadow: 0 4px 10px rgba(14, 165, 233, 0.2);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-cyan-hover) 0%, #0369a1 100%);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-primary);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-text {
  background: transparent;
  color: var(--accent-cyan);
  padding: 6px 12px;
}
.btn-text:hover {
  background-color: var(--accent-cyan-light);
}

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

.btn-danger-outline {
  background-color: transparent;
  border-color: var(--accent-red);
  color: var(--accent-red);
}
.btn-danger-outline:hover {
  background-color: var(--accent-red-light);
}

.btn-icon-square {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-speed);
}
.btn-icon-square:hover {
  background-color: var(--border-color);
  color: var(--text-primary);
}

.btn-sm {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
}

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

.btn-full-width {
  width: 100%;
}

/* Quick Action Tiles */
.quick-actions-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-action-tile {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 12px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-speed);
}

.btn-action-tile:hover {
  transform: translateX(4px);
  background-color: var(--bg-secondary);
  box-shadow: var(--card-shadow);
  border-color: var(--accent-cyan);
}

.tile-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.icon-cyan { background-color: var(--accent-cyan-light); color: var(--accent-cyan); }
.icon-emerald { background-color: var(--accent-emerald-light); color: var(--accent-emerald); }
.icon-purple { background-color: var(--accent-purple-light); color: var(--accent-purple); }
.icon-grey { background-color: var(--border-color); color: var(--text-secondary); }

.tile-content h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--text-primary);
}

.tile-content p {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==========================================
   TABLES STYLING
   ========================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.table th {
  padding: 14px 16px;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  background-color: var(--bg-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  padding: 14px 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background-color: rgba(226, 232, 240, 0.15);
}

body.dark-mode .table tbody tr:hover td {
  background-color: rgba(39, 53, 73, 0.15);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.25px;
}

.badge-success { background-color: var(--accent-emerald-light); color: var(--accent-emerald); }
.badge-info { background-color: var(--accent-cyan-light); color: var(--accent-cyan); }
.badge-warning { background-color: var(--accent-yellow-light); color: var(--accent-yellow); }
.badge-danger { background-color: var(--accent-red-light); color: var(--accent-red); }

/* Table Action Buttons */
.table-btn-group {
  display: flex;
  gap: 6px;
}

.btn-table-action {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition-speed);
}

.btn-table-action:hover {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.btn-table-action.view-btn:hover { color: var(--accent-cyan); border-color: var(--accent-cyan); }
.btn-table-action.edit-btn:hover { color: var(--accent-purple); border-color: var(--accent-purple); }
.btn-table-action.delete-btn:hover { color: var(--accent-red); border-color: var(--accent-red); }

/* ==========================================
   FORMS & INPUTS
   ========================================== */
.form-grid-2x1 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  align-items: start;
}

.form-column {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.form-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  box-shadow: var(--card-shadow);
}

.form-card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 18px;
}

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  min-width: 0; /* Prevents overflow in flexbox */
}

.form-group.flex-2 { flex: 2; }
.form-group.flex-1 { flex: 1; }

.select-with-button {
  display: flex;
  gap: 8px;
}

.select-with-button select {
  flex: 1;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.required {
  color: var(--accent-red);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  transition: all var(--transition-speed);
  width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

input.input-readonly {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  cursor: not-allowed;
}

textarea {
  resize: vertical;
}

/* Client Detail Preview inside Invoice Form */
.client-detail-preview {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 16px;
  margin-bottom: 16px;
  animation: fadeIn 0.25s ease;
}

.client-detail-preview.hidden {
  display: none;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.preview-header h4 {
  font-size: 14px;
  font-weight: 700;
}

.preview-body-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.preview-body-grid p i {
  width: 16px;
  color: var(--accent-cyan);
}

/* Custom Table Forms (items entry) */
.table-form td {
  padding: 8px 6px;
}

.table-form td:first-child {
  padding-left: 0;
}

.table-form td:last-child {
  padding-right: 0;
}

.table-form select,\n.table-form input {
  padding: 8px 10px;
}

.table-actions-under {
  margin-top: 12px;
  display: flex;
  justify-content: flex-start;
}

/* Switch styling */
.switch-small {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.switch-small input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-emerald);
}

input:checked + .slider:before {
  transform: translateX(14px);
}

.iva-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================
   VIEW SUB-PANELS (Notes list vs New note Form)
   ========================================== */
.view-sub-panel {
  display: none;
}
.view-sub-panel.active {
  display: block;
}

.view-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-input-wrapper i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

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

/* ==========================================
   CALCULATION CARD & BOX (STICKY SUMMARY)
   ========================================== */
.sticky-calc-card {
  position: sticky;
  top: 32px;
}

.totals-summary-box {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
}

.discount-row {
  color: var(--accent-red);
}

.discount-input-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.discount-input-inline label {
  font-size: 12px;
  font-weight: 600;
}

.discount-input-inline input {
  width: 65px;
  padding: 4px 6px;
  font-size: 12px;
}

.total-row {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 4px;
}

.margin-top-lg {
  margin-top: 24px;
}

.form-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

/* ==========================================
   SETTINGS SPECIFICS
   ========================================== */
.settings-actions-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.action-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  gap: 20px;
}

.action-text h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
}

.action-text p {
  font-size: 12px;
  color: var(--text-secondary);
}

.action-item.danger-zone {
  border-left: 4px solid var(--accent-red);
}

.hidden-file-input {
  display: none;
}

/* ==========================================
   MODALS LAYOUT
   ========================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--modal-bg);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  width: 100%;
  max-width: 600px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.glassmorphism {
  background-color: var(--glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  font-weight: 300;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--transition-speed);
}
.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* ==========================================
   INVOICE / NOTE SHEET STYLING
   ========================================== */
.invoice-modal-content {
  max-width: 850px;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.invoice-print-area {
  overflow-y: auto;
  background-color: #f1f5f9;
  padding: 32px;
  display: flex;
  justify-content: center;
}

/* Paper Container standard A4/Letter Aspect */
.invoice-container {
  background-color: #ffffff;
  color: #1e293b;
  width: 100%;
  max-width: 780px;
  min-height: 1000px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  padding: 40px;
  font-size: 12px;
  line-height: 1.4;
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: 'Outfit', 'Inter', Arial, sans-serif;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
  gap: 20px;
}

.company-block {
  flex: 1;
}

.print-logo-wrapper {
  max-width: 250px;
  height: 60px;
  margin-bottom: 12px;
}

.company-details {
  font-size: 11px;
  color: #64748b;
  margin: 1px 0;
}
.company-details.font-bold {
  font-weight: 700;
  color: #1e293b;
}

.document-block {
  width: 280px;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.document-badge-red {
  border: 3px solid #ef4444;
  border-radius: 4px;
  width: 100%;
  padding: 12px;
  text-align: center;
  background-color: #fef2f2;
}

.doc-rut {
  font-size: 14px;
  font-weight: 800;
  color: #ef4444;
}

.doc-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  margin: 4px 0;
  color: #1e293b;
}

.doc-number {
  font-size: 16px;
  font-weight: 800;
  color: #ef4444;
}

.doc-meta {
  font-size: 11px;
  color: #475569;
  text-align: right;
}

.doc-meta p {
  margin: 2px 0;
}

/* Sections */
.invoice-section {
  margin-bottom: 24px;
}

.section-title-bar {
  background-color: #f1f5f9;
  border-left: 4px solid var(--accent-cyan);
  padding: 6px 12px;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: #334155;
  margin-bottom: 10px;
}

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

.info-table td {
  padding: 4px 6px;
  vertical-align: top;
}

.info-table td strong {
  color: #475569;
}

/* Items Print Table */
.print-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.print-items-table th {
  background-color: #1e293b;
  color: #ffffff;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  padding: 8px 10px;
  text-align: left;
}

.print-items-table th.text-center { text-align: center; }
.print-items-table th.text-right { text-align: right; }

.print-items-table td {
  padding: 10px;
  border-bottom: 1px solid #e2e8f0;
  color: #334155;
}

.print-items-table td.text-center { text-align: center; }
.print-items-table td.text-right { text-align: right; }

.print-items-table tbody tr:nth-child(even) {
  background-color: #f8fafc;
}

.invoice-footer-grid {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  gap: 20px;
}

.terms-block {
  flex: 1.2;
}

.terms-title {
  font-weight: 700;
  font-size: 11px;
  margin-bottom: 6px;
  color: #475569;
}

.terms-content {
  font-size: 10px;
  color: #64748b;
  text-align: justify;
  margin-bottom: 16px;
}

/* Barcode */
.barcode-container {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background-color: #ffffff;
  padding: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.barcode-lines {
  display: flex;
  height: 24px;
  align-items: stretch;
}

.b-line {
  background-color: #000000;
  margin-right: 1px;
}
.b-line.w1 { width: 1px; }
.b-line.w2 { width: 2px; }
.b-line.w3 { width: 3px; }
.b-line.w4 { width: 4px; }

.barcode-text {
  font-size: 8px;
  font-family: monospace;
  color: #64748b;
  margin-top: 2px;
}

.totals-block {
  flex: 0.8;
}

.print-totals-table {
  width: 100%;
  border-collapse: collapse;
}

.print-totals-table td {
  padding: 6px 10px;
  color: #475569;
  border-bottom: 1px solid #f1f5f9;
}

.print-totals-table td.text-right {
  text-align: right;
  font-weight: 600;
  color: #1e293b;
}

.print-totals-table .total-row-highlight {
  font-size: 13px;
  font-weight: 800;
  background-color: #fef2f2;
}

.print-totals-table .total-row-highlight td {
  color: #ef4444;
  border-top: 2px solid #ef4444;
  border-bottom: 2px solid #ef4444;
  padding: 8px 10px;
}

.print-totals-table .total-row-highlight td.text-right {
  font-size: 15px;
  font-weight: 800;
  color: #ef4444;
}

/* Signatures */
.signature-section {
  display: flex;
  justify-content: space-around;
  margin-top: 60px;
  gap: 40px;
}

.signature-box {
  text-align: center;
  width: 200px;
}

.sig-line {
  border-bottom: 1px dashed #94a3b8;
  height: 30px;
  margin-bottom: 6px;
}

.sig-label {
  font-size: 10px;
  color: #64748b;
}

.print-footer-notice {
  margin-top: auto;
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
  text-align: center;
  font-size: 9px;
  color: #94a3b8;
}

/* ==========================================
   PRINT MEDIA QUERY STYLES
   ========================================== */
@media print {
  /* Hide absolutely everything else */
  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
  }
  
  .app-container,
  .sidebar,
  .main-content,
  .content-header,
  .modal-header,
  .hide-on-print {
    display: none !important;
  }
  
  .modal-overlay {
    display: none !important;
  }
  
  .modal-overlay.active {
    position: static !important;
    display: block !important;
    background: none !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    z-index: auto !important;
  }
  
  .invoice-modal-content {
    border: none !important;
    max-width: 100% !important;
    max-height: 100% !important;
    box-shadow: none !important;
    background: none !important;
    overflow: visible !important;
  }
  
  .invoice-print-area {
    padding: 0 !important;
    background: none !important;
    overflow: visible !important;
    display: block !important;
  }
  
  .invoice-container {
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    background: #ffffff !important;
  }

  .document-badge-red {
    background-color: #ffffff !important;
    border-color: #000000 !important;
    color: #000000 !important;
  }
  .doc-rut, .doc-title, .doc-number {
    color: #000000 !important;
  }

  .section-title-bar {
    background-color: #f1f5f9 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    border-left-color: #0ea5e9 !important;
  }

  .print-items-table th {
    background-color: #1e293b !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-totals-table .total-row-highlight {
    background-color: #fef2f2 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-totals-table .total-row-highlight td {
    color: #000000 !important;
    border-color: #000000 !important;
  }

  .print-totals-table .total-row-highlight td.text-right {
    color: #000000 !important;
  }

  /* Force print page size and margin */
  @page {
    size: letter;
    margin: 1.5cm;
  }
}

/* ==========================================
   RESPONSIVE DESIGN (SCREENS)
   ========================================== */
@media (max-width: 1024px) {
  .form-grid-2x1 {
    grid-template-columns: 1fr;
  }
  .sticky-calc-card {
    position: static;
  }
}

@media (max-width: 900px) {
  .sidebar {
    width: 70px;
  }
  .sidebar .sidebar-header,\n  .sidebar .sidebar-footer span,\n  .sidebar .nav-item span,\n  .sidebar .user-info {
    display: none;
  }
  .sidebar-nav {
    padding: 20px 6px;
  }
  .nav-item a {
    justify-content: center;
    padding: 12px;
  }
  .main-content {
    margin-left: 70px;
    padding: 20px;
  }
  .dashboard-rows {
    flex-direction: column;
  }
  .col-8, .col-4 {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .content-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .btn-quick-note {
    width: 100%;
  }
}

/* ==========================================
   ERP CUSTOM STYLES & ENHANCEMENTS
   ========================================== */
.warehouse-toggle-container button {
  font-family: 'Outfit', sans-serif;
  transition: all var(--transition-speed) ease;
  border: 1px solid var(--border-color);
}
.warehouse-toggle-container button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.stock-tab-btn {
  font-family: 'Outfit', sans-serif;
  outline: none;
}
.stock-tab-btn:hover {
  color: var(--text-primary) !important;
  border-bottom-color: var(--border-color) !important;
}
.stock-tab-btn.active {
  color: var(--text-primary) !important;
}

.email-checkbox-grid label {
  transition: background-color 0.15s ease;
  padding: 6px 10px;
  border-radius: var(--border-radius-sm);
}
.email-checkbox-grid label:hover {
  background-color: var(--border-color);
}
.email-checkbox-grid input[type="checkbox"] {
  accent-color: var(--accent-purple);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Custom file uploads */
input[type="file"] {
  background: var(--bg-primary);
  border: 1px dashed var(--border-color);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  width: 100%;
}
input[type="file"]::-webkit-file-upload-button {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  margin-right: 10px;
  transition: background 0.2s;
}
input[type="file"]::-webkit-file-upload-button:hover {
  background: var(--border-color);
}

/* User Registration / Login Overlay */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}
.login-overlay.active {
  display: flex;
}
.login-card {
  width: 100%;
  max-width: 450px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
  padding: 40px;
  text-align: center;
  animation: slideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.login-logo-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.login-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}
.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.5;
}
.login-card .form-group {
  text-align: left;
  margin-bottom: 20px;
}
.login-card label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}
.login-card select, .login-card input {
  font-size: 14px;
  padding: 10px 14px;
}
.btn-logout-small {
  transition: all 0.2s ease;
}
.btn-logout-small:hover {
  color: var(--accent-red) !important;
  transform: scale(1.1);
}

/* User Registration / Login Overlay Tabs */
.login-tab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 16px;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}
.login-tab-btn.active {
  color: var(--text-primary) !important;
  border-bottom: 2px solid var(--accent-cyan) !important;
}

/* ==========================================
   HAMBURGER MENU & DRAWER OVERLAY
   ========================================== */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 8px;
  margin-right: 12px;
  border-radius: var(--border-radius-sm);
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-speed);
}

.hamburger-btn:hover {
  background-color: var(--border-color);
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 9998;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ==========================================
   MOBILE RESPONSIVE MEDIA QUERIES (<= 768px)
   ========================================== */
@media (max-width: 768px) {
  .hamburger-btn {
    display: flex;
  }

  /* Slide-out Sidebar Drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    height: 100vh;
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.15);
    background-color: var(--bg-secondary);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  /* Make sure sidebar elements are shown properly inside mobile drawer */
  .sidebar .sidebar-header,
  .sidebar .sidebar-footer span,
  .sidebar .nav-item span,
  .sidebar .user-info {
    display: flex !important;
  }

  .sidebar-footer {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px;
  }

  .sidebar-footer .user-profile {
    display: flex !important;
    width: 100% !important;
  }

  .sidebar-nav {
    padding: 20px 16px;
  }

  .nav-item a {
    justify-content: flex-start;
    padding: 12px 16px;
  }

  /* Content area full width */
  .main-content {
    margin-left: 0 !important;
    padding: 16px;
  }

  /* Stacking metrics and grid items */
  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 20px;
  }

  .dashboard-rows {
    gap: 16px;
  }

  /* Table responsiveness scrolling */
  .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--border-radius-md);
  }

  /* Form layouts */
  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .form-grid-2x1 {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .form-column {
    width: 100% !important;
  }

  .sticky-calc-card {
    position: static;
  }

  /* Button alignment stack */
  .view-header-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .view-header-bar > div {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }

  .view-header-bar button, 
  .view-header-bar .search-input-wrapper {
    width: 100% !important;
  }

  .search-input-wrapper input {
    width: 100%;
  }

  /* Modals sizing and stack */
  .modal-content {
    width: 95% !important;
    max-width: 100% !important;
    padding: 20px !important;
    margin: 10px auto;
  }

  .modal-body form .form-row {
    flex-direction: column;
    gap: 0;
  }

  /* Print preview modal overrides to prevent breaking inside app container */
  .invoice-modal-content {
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
}

/* ==========================================
   LABEL PREVIEW & PRINT STYLES
   ========================================== */
.label-modal-content {
  max-width: 420px !important;
}

.label-print-area {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px !important;
  background: var(--bg-primary);
}

.label-container {
  width: 10cm;
  height: 6.5cm;
  padding: 14px;
  box-sizing: border-box;
  background: #ffffff;
  color: #000000;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.label-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-company {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.5px;
  color: #1958a7;
}

.label-title {
  font-size: 11px;
  font-weight: 700;
  color: #2cb53b;
  border: 1px solid #2cb53b;
  padding: 2px 6px;
  border-radius: 4px;
}

.label-divider {
  border: none;
  border-top: 1px dashed #cbd5e1;
  margin: 6px 0;
}

.label-barcode-wrapper {
  text-align: center;
  margin: 4px 0;
}

.barcode-font {
  font-family: 'Libre Barcode 39', cursive, sans-serif;
  font-size: 48px;
  line-height: 1.0;
  margin: 0;
  padding: 0;
}

.barcode-text {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-top: 2px;
  color: #000000;
}

.label-details {
  font-size: 11px;
  line-height: 1.4;
  color: #000000;
  text-align: left;
}

.label-details p {
  margin: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================
   ADDITIONAL LABEL PRINT OVERRIDES
   ========================================== */
@media print {
  
  
  .modal-overlay#modal-label-print .label-modal-content {
    border: none !important;
    max-width: 100% !important;
    max-height: 100% !important;
    box-shadow: none !important;
    background: none !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .modal-overlay#modal-label-print .label-print-area {
    padding: 0 !important;
    background: none !important;
    overflow: visible !important;
    display: block !important;
    margin: 0 !important;
  }
  
  .modal-overlay#modal-label-print .label-container {
    border: none !important;
    box-shadow: none !important;
    width: 10cm !important;
    height: 6.5cm !important;
    margin: 0 !important;
    padding: 10px !important;
    box-sizing: border-box !important;
    background: #ffffff !important;
    page-break-inside: avoid;
  }
}

