/* ==========================================================================
   DESIGN SYSTEM & VARIABLES - ÓTICA REALCE
   ========================================================================== */

:root {
  /* Fonts */
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Theme: Dark (Default) */
  --bg-app: #0f1115;
  --bg-sidebar: #16181e;
  --bg-panel: #1b1f27;
  --bg-panel-hover: #212631;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-glow: rgba(0, 155, 158, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Brand Colors */
  --teal-brand: #009B9E;
  --teal-brand-hover: #008184;
  --teal-brand-glow: rgba(0, 155, 158, 0.15);
  
  /* Status Colors */
  --color-success: #10b981;
  --color-success-bg: rgba(16, 185, 129, 0.1);
  --color-pending: #f59e0b;
  --color-pending-bg: rgba(245, 158, 11, 0.1);
  --color-danger: #ef4444;
  --color-danger-bg: rgba(239, 68, 68, 0.1);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-premium: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Transition */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light Theme overrides */
[data-theme="light"] {
  --bg-app: #f4f6f9;
  --bg-sidebar: #ffffff;
  --bg-panel: #ffffff;
  --bg-panel-hover: #f8fafc;
  --border-color: rgba(15, 23, 42, 0.08);
  --border-color-glow: rgba(0, 155, 158, 0.2);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --shadow-premium: 0 10px 30px rgba(0, 155, 158, 0.05), 0 1px 3px rgba(0, 0, 0, 0.02);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */

.app-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar Styling */
.sidebar {
  width: 280px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
  padding: 0 8px;
}

.logo-wrapper {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.brand-svg-logo {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 10px rgba(0, 155, 158, 0.3));
}

.brand-text h2 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  line-height: 1.1;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--teal-brand);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.menu-item {
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  width: 100%;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.menu-item:hover {
  background-color: var(--bg-panel-hover);
  color: var(--text-primary);
}

.menu-item.active {
  background-color: var(--teal-brand);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 155, 158, 0.25);
}

.menu-item i {
  width: 20px;
  height: 20px;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
}

.theme-toggle-btn:hover {
  background-color: var(--bg-panel-hover);
  color: var(--text-primary);
  border-color: var(--teal-brand);
}

/* Main Content Styling */
.main-content {
  flex-grow: 1;
  padding: 36px 40px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  max-width: 1400px;
  margin: 0 auto;
  width: calc(100% - 280px);
}

/* Header Area */
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
}

.header-title h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
}

.header-title p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
}

.btn-primary {
  background-color: var(--teal-brand);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--teal-brand-hover);
  box-shadow: 0 4px 15px rgba(0, 155, 158, 0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-panel-hover);
  border-color: var(--teal-brand);
}

.btn-text {
  background: none;
  color: var(--teal-brand);
  padding: 6px 12px;
  font-weight: 600;
}

.btn-text:hover {
  background-color: var(--teal-brand-glow);
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 10px;
  aspect-ratio: 1;
}

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

.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close:hover {
  color: var(--text-primary);
}

/* ==========================================================================
   DASHBOARD / WIDGET CARDS
   ========================================================================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.stat-card {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-color-glow);
}

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

.stat-icon.clients {
  background-color: rgba(14, 165, 233, 0.1);
  color: #0ea5e9;
}

.stat-icon.orders {
  background-color: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
}

.stat-icon.revenue {
  background-color: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.stat-icon.pending {
  background-color: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.stat-icon i {
  width: 26px;
  height: 26px;
}

.stat-info h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
  color: var(--text-primary);
}

/* Dashboard Panels Layout */
.dashboard-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  align-items: start;
}

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

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

.panel-header h2 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 600;
}

/* Financial Widget (Donut Chart representation) */
.financial-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.financial-chart-container {
  position: relative;
  width: 160px;
  height: 160px;
}

.circular-progress-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.circular-progress {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(var(--teal-brand) 0deg, var(--border-color) 0deg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.5s ease;
}

.progress-inner-val {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 700;
  background-color: var(--bg-panel);
  width: 80%;
  height: 80%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  box-shadow: inset var(--shadow-sm);
}

.financial-details {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.fin-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background-color: rgba(255, 255, 255, 0.02);
}

.fin-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.fin-item .dot.paid {
  background-color: var(--teal-brand);
}

.fin-item .dot.unpaid {
  background-color: var(--color-pending);
}

.fin-text {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.fin-text .label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.fin-text .val {
  font-size: 0.95rem;
  font-weight: 700;
}

/* ==========================================================================
   TAB PANES CONTROL
   ========================================================================== */

.tab-pane {
  display: none;
  animation: fadeIn var(--transition-normal);
}

.tab-pane.active {
  display: block;
}

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

/* ==========================================================================
   TABLES
   ========================================================================== */

.panel-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
}

.filter-row {
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex-grow: 1;
  max-width: 450px;
}

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

.search-box input {
  width: 100%;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px 10px 42px;
  font-size: 0.9rem;
  outline: none;
  transition: all var(--transition-fast);
}

.search-box input:focus {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--teal-brand);
  box-shadow: 0 0 0 2px var(--teal-brand-glow);
}

.filters-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.filters-group select, .filters-group input[type="date"] {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filters-group select:focus, .filters-group input[type="date"]:focus {
  border-color: var(--teal-brand);
}

.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  background-color: rgba(255, 255, 255, 0.02);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.phone-col {
  white-space: nowrap;
  width: 175px;
}

.data-table tbody tr {
  transition: background-color var(--transition-fast);
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.01);
}

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

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px !important;
}

.empty-state i {
  display: block;
  margin: 0 auto 10px;
  width: 32px;
  height: 32px;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.paid {
  background-color: var(--color-success-bg);
  color: var(--color-success);
}

.status-badge.unpaid {
  background-color: var(--color-danger-bg);
  color: var(--color-danger);
}

/* ==========================================================================
   FORMS & INPUTS (NOVA O.S. & CLIENTS)
   ========================================================================== */

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

.form-left-col,
.form-right-col {
  width: 100%;
}

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

.form-panel + .form-panel {
  margin-top: 24px;
}

.form-group-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.margin-top {
  margin-top: 14px;
}

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

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.9rem;
  outline: none;
  transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--teal-brand);
  background-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 2px var(--teal-brand-glow);
}

.form-group textarea {
  resize: vertical;
}

select option {
  background-color: var(--bg-panel);
  color: var(--text-primary);
}

.required {
  color: var(--color-danger);
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-3 { flex: 3; }

.action-align {
  align-self: flex-end;
}

.flex-grow {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Autocomplete combo box wrapper */
.autocomplete-wrapper select {
  width: 100%;
  cursor: pointer;
}

/* ==========================================================================
   PRESCRIPTION GRID (GRADE OFTÁLMICA)
   ========================================================================== */

.prescription-grid-container {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 8px;
}

.prescription-grid-header {
  display: grid;
  grid-template-columns: 1fr 0.7fr 1.2fr 1.2fr 1.2fr 1.2fr;
  background-color: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.prescription-grid-header .cell {
  padding: 10px;
  text-align: center;
}

.prescription-grid-row {
  display: grid;
  grid-template-columns: 1fr 0.7fr 1.2fr 1.2fr 1.2fr 1.2fr;
  border-bottom: 1px solid var(--border-color);
}

.prescription-grid-row:last-child {
  border-bottom: none;
}

.prescription-grid-row.border-double {
  border-bottom: 3px double var(--border-color);
}

.prescription-grid-row .cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border-color);
}

.prescription-grid-row .cell:last-child {
  border-right: none;
}

.prescription-grid-row .cell.row-span {
  grid-row: span 2;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background-color: rgba(255, 255, 255, 0.01);
  text-transform: uppercase;
  border-right: 1px solid var(--border-color);
}

.prescription-grid-row .cell.eye {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.02);
}

.prescription-grid-row input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 8px 10px;
  text-align: center;
  font-size: 0.9rem;
  outline: none;
}

.prescription-grid-row input:focus {
  background-color: var(--teal-brand-glow);
}

/* ==========================================================================
   SERVICES & PRODUCTS PANEL
   ========================================================================== */

.services-list-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.service-row-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.service-row-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.service-fields {
  display: flex;
  gap: 8px;
}

.service-fields .input-qty {
  width: 70px;
  text-align: center;
}

.service-fields .input-desc {
  flex-grow: 1;
}

.service-fields .input-val {
  width: 120px;
}

/* Financial Summary inside O.S. creation */
.financial-summary-panel {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.payment-toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.payment-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.payment-badge.paid {
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.payment-badge.unpaid {
  background-color: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
}

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

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

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

.toggle-switch input:checked + .slider {
  background-color: var(--color-success);
}

.toggle-switch input:checked + .slider:before {
  transform: translateX(24px);
}

.total-display {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  padding: 16px 20px;
  border-radius: var(--radius-md);
}

.total-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.total-value {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--teal-brand);
}

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

/* ==========================================================================
   MODAL DIALOG OVERLAYS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn var(--transition-fast);
}

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

.modal-content {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 550px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-premium);
  animation: slideUp var(--transition-normal);
  overflow: hidden;
}

.modal-content.wide {
  max-width: 900px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex-grow: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* History Details Banner inside Client History Modal */
.client-info-banner {
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.client-info-banner div strong {
  color: var(--text-secondary);
}

.client-info-banner .full-width {
  grid-column: span 2;
}

.history-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.history-column h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.table-container.compact .data-table td {
  padding: 10px 12px;
}

.table-container.compact .data-table th {
  padding: 8px 12px;
}

.history-prescription-box {
  background-color: rgba(0, 155, 158, 0.03);
  border: 1px solid var(--border-color-glow);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.history-prescription-box .row-spec {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.85rem;
  margin-top: 10px;
}

.history-prescription-box .row-spec div {
  background: rgba(255,255,255,0.02);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.history-prescription-box .row-spec div.full {
  grid-column: span 2;
}

.history-prescription-box h4 {
  font-size: 0.85rem;
  color: var(--teal-brand);
  text-transform: uppercase;
  margin-bottom: 10px;
  font-weight: 700;
}

/* ==========================================================================
   RECEIPT VIEW MODAL & PRINTING
   ========================================================================== */

.receipt-modal-content {
  max-width: 680px;
  background-color: #ffffff;
  color: #121214;
}

.receipt-modal-content .modal-header {
  border-color: #e2e8f0;
}

.receipt-modal-content h2 {
  color: #0f172a;
}

.header-action-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.receipt-printable-container {
  padding: 30px;
  background-color: #ffffff;
  color: #000000;
  font-family: var(--font-main);
  max-height: 80vh;
  overflow-y: auto;
}

.receipt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.receipt-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.receipt-logo {
  flex-shrink: 0;
}

.receipt-title-details h1 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #000000;
  line-height: 1.1;
}

.receipt-title-details p {
  font-size: 0.75rem;
  color: #475569;
  margin-top: 4px;
  font-weight: 500;
}

.receipt-os-badge {
  text-align: right;
  border: 2px solid #000000;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background-color: #f8fafc;
}

.receipt-os-badge .os-badge-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #475569;
}

.receipt-os-badge .os-badge-number {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 800;
  color: #e11d48; /* Highlight red like physical stamp */
  margin-top: 2px;
}

.receipt-divider {
  border: none;
  border-top: 1px solid #000000;
  margin: 16px 0;
}

.receipt-meta-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 10px;
  font-size: 0.85rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

.receipt-meta-grid .full-row {
  grid-column: span 2;
}

.receipt-table-header-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  border-left: 3px solid #000000;
  padding-left: 8px;
  margin-bottom: 10px;
  margin-top: 18px;
  text-transform: uppercase;
}

/* Eye Prescription Table - Printable Style */
.receipt-prescription-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.8rem;
}

.receipt-prescription-table th, 
.receipt-prescription-table td {
  border: 1px solid #000000;
  padding: 6px 10px;
  text-align: center;
}

.receipt-prescription-table th {
  background-color: #f1f5f9;
  font-weight: 700;
}

.receipt-prescription-table td.row-label-side {
  font-weight: 800;
  background-color: #f8fafc;
  vertical-align: middle;
  width: 75px;
}

.receipt-prescription-table td.eye-label {
  font-weight: 800;
  background-color: #f1f5f9;
  width: 50px;
}

.receipt-prescription-table tr.border-thick-bottom td {
  border-bottom: 2px solid #000000;
}

.receipt-specs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.receipt-specs-grid .full-row {
  grid-column: span 2;
}

/* Services and Products - Printable Table Style */
.receipt-services-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 0.85rem;
}

.receipt-services-table th, 
.receipt-services-table td {
  border: 1px solid #000000;
  padding: 8px 12px;
}

.receipt-services-table th {
  background-color: #f1f5f9;
  font-weight: 700;
}

.receipt-services-table .col-desc { text-align: left; }
.receipt-services-table .col-qty { text-align: center; width: 60px; }
.receipt-services-table .col-val { text-align: right; width: 120px; }

.receipt-services-table td.center-text { text-align: center; }
.receipt-services-table td.right-text { text-align: right; font-weight: 500; }

.receipt-footer-billing {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  border-top: 2px solid #000000;
  padding-top: 14px;
}

.receipt-payment-status {
  font-size: 0.85rem;
  font-weight: 800;
  border: 2px solid #000000;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.payment-status-tag {
  font-size: 0.85rem;
  font-weight: 800;
  border: 2px solid #000000;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.payment-status-tag.pago {
  border-color: #16a34a;
  color: #16a34a;
  background-color: rgba(22, 163, 74, 0.05);
}

.payment-status-tag.a-pagar {
  border-color: #dc2626;
  color: #dc2626;
  background-color: rgba(220, 38, 38, 0.05);
}

.total-os-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.total-os-label {
  font-size: 0.9rem;
  font-weight: 800;
  color: #475569;
}

.total-os-price {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 900;
  color: #000000;
  background-color: #f1f5f9;
  padding: 6px 16px;
  border: 1px solid #000000;
  border-radius: var(--radius-sm);
}

.receipt-legal-notice {
  margin-top: 30px;
  text-align: center;
  font-size: 0.7rem;
  color: #64748b;
  font-style: italic;
  border-top: 1px dashed #cbd5e1;
  padding-top: 12px;
}

/* ==========================================================================
   RESPONSIVE LAYOUT (MEDIA QUERIES)
   ========================================================================== */

@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    height: auto;
  }

  .sidebar-header {
    margin-bottom: 16px;
  }
  
  .sidebar-menu {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .menu-item {
    width: auto;
    padding: 8px 14px;
    font-size: 0.85rem;
  }
  
  .sidebar-footer {
    display: none; /* Hide toggle theme in mobile sidebar, or move it */
  }
  
  .main-content {
    width: 100%;
    padding: 24px;
  }

  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .content-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .header-actions {
    width: 100%;
  }
  
  .header-actions .btn {
    flex: 1;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .panel-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: 100%;
  }

  .filters-group {
    width: 100%;
  }

  .filters-group select, .filters-group input[type="date"] {
    flex: 1;
  }

  .form-group-row {
    flex-direction: column;
    gap: 12px;
  }

  .action-align {
    align-self: stretch;
  }

  .prescription-grid-header {
    font-size: 0.7rem;
  }

  .prescription-grid-row input {
    padding: 6px 4px;
    font-size: 0.8rem;
  }
}

/* ==========================================================================
   PRINT MEDIA STYLES (window.print())
   ========================================================================== */

@media print {
  /* Hide all elements that are not the receipt */
  body, html {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt !important;
  }

  .app-container,
  aside.sidebar,
  main.main-content,
  .modal-overlay,
  .no-print {
    display: none !important;
  }

  /* Show ONLY the printable receipt */
  #modal-receipt {
    display: block !important;
    position: relative !important;
    background: #ffffff !important;
    width: 100% !important;
    height: auto !important;
    top: 0 !important;
    left: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }

  .receipt-modal-content {
    border: none !important;
    max-width: 100% !important;
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
  }

  .receipt-printable-container {
    max-height: none !important;
    overflow-y: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }

  /* Ensure correct page breaks and sizing */
  @page {
    size: A4portrait;
    margin: 1.5cm;
  }

  /* Force background colors to print */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .receipt-prescription-table th, 
  .receipt-services-table th {
    background-color: #f1f5f9 !important;
  }
}
