:root {
  --primary: #00A8B5;
  --primary-hover: #008C99;
  --primary-light: #E0F7FA;
  --secondary: #1E3A8A;
  --secondary-hover: #172554;
  --bg-app: #F8FAFC;
  --bg-card: #FFFFFF;
  --border: #E2E8F0;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ================= LAYOUT ================= */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-sidebar {
  width: 260px;
  background: #FFFFFF;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  height: 44px;
  display: block;
}

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

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  width: 100%;
}

.nav-btn:hover {
  background: var(--bg-app);
  color: var(--secondary);
}

.nav-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.nav-icon {
  font-size: 1.25rem;
}

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
}

.user-info {
  flex-grow: 1;
  overflow: hidden;
}

.user-name {
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.btn-logout {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}

.btn-logout:hover {
  color: var(--danger);
}

/* ================= MAIN CONTENT ================= */
.app-main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-topbar {
  height: 70px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--secondary);
}

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

.btn-refresh {
  background: none;
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
}

.view-content {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.view-panel {
  display: block;
}

.hidden {
  display: none !important;
}

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

.metric-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.bg-cyan { background: #E0F2FE; }
.bg-red { background: #FEE2E2; }
.bg-green { background: #DCFCE7; }
.bg-blue { background: #E0E7FF; }

.metric-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-val {
  font-size: 1.7rem;
  font-weight: 900;
  color: var(--secondary);
  line-height: 1.1;
}

.metric-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.text-red { color: var(--danger) !important; }
.text-green { color: var(--success) !important; }

/* ================= PANELS & TABLES ================= */
.dashboard-columns {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
}

.panel-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

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

.panel-card-header h3 {
  font-size: 1.1rem;
  color: var(--secondary);
  font-weight: 800;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.85rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

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

.data-table th {
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:hover td {
  background: #F8FAFC;
}

/* ================= BADGES & BUTTONS ================= */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-success { background: #DCFCE7; color: #166534; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-info { background: #E0F2FE; color: #075985; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text-main); }
.btn-outline:hover { background: var(--bg-app); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ================= TOOLBAR ================= */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.toolbar-search {
  flex-grow: 1;
  max-width: 400px;
}

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

.form-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
  background: #fff;
  width: 100%;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 181, 0.15);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-main);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ================= COBRANZA & CORTE DE CAJA ================= */
.billing-header-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 24px;
}

.cash-cut-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-app);
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
}

.cash-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

/* ================= NETWORK STATUS ================= */
.network-status-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-app);
  border-radius: var(--radius-sm);
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-indicator.online { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.6); }

.status-item strong {
  display: block;
  font-size: 0.9rem;
  color: var(--secondary);
}

.status-item small {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.status-item .badge {
  margin-left: auto;
}

/* ================= PORTAL CLIENTE ================= */
.portal-card {
  max-width: 800px;
  margin: 0 auto;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 32px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

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

.portal-balance {
  text-align: right;
}

.portal-balance small {
  display: block;
  color: var(--text-muted);
}

.portal-balance strong {
  font-size: 1.8rem;
  color: var(--secondary);
}

.portal-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  background: var(--bg-app);
  padding: 20px;
  border-radius: var(--radius-md);
}

.portal-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ================= MODAL & DIALOGS ================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  padding: 20px;
}

.modal-box {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 500px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-lg { max-width: 700px; }

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-header {
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 1.25rem;
  color: var(--secondary);
}

.modal-header p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ================= POTENCIA ÓPTICA DISPLAY ================= */
.optical-display {
  background: var(--bg-app);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
}

.optical-metric {
  margin-bottom: 20px;
}

.optical-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.optical-val {
  font-size: 3rem;
  font-weight: 900;
  color: var(--primary);
  display: block;
}

.optical-subgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  font-size: 0.85rem;
}

/* ================= RECIBO TÉRMICO (80mm/58mm) ================= */
.thermal-receipt {
  background: #FFFFFF;
  padding: 16px;
  border: 1px dashed #CBD5E1;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  line-height: 1.35;
  color: #000;
}

.receipt-header {
  text-align: center;
}

.receipt-logo {
  height: 38px;
  margin-bottom: 6px;
}

.receipt-header h4 {
  font-size: 14px;
  margin-bottom: 2px;
}

.receipt-divider {
  border: none;
  border-top: 1px dashed #000;
  margin: 8px 0;
}

.r-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.r-row.total {
  font-size: 14px;
  font-weight: bold;
}

.receipt-footer {
  text-align: center;
  font-size: 10px;
  margin-top: 10px;
}

/* REGLAS DE IMPRESIÓN EXCLUSIVA DEL RECIBO */
@media print {
  body * {
    visibility: hidden;
  }
  #printableReceipt, #printableReceipt * {
    visibility: visible;
  }
  #printableReceipt {
    position: absolute;
    left: 0;
    top: 0;
    width: 80mm;
    margin: 0;
    padding: 0;
    border: none;
  }
}

/* ================= MOBILE BOTTOM NAV (PWA) ================= */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #FFFFFF;
  border-top: 1px solid var(--border);
  height: 60px;
  z-index: 1000;
  justify-content: space-around;
  align-items: center;
}

.m-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

.m-nav-item.active {
  color: var(--primary);
}

.m-icon {
  font-size: 1.25rem;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 900px) {
  .app-sidebar {
    display: none;
  }
  .mobile-bottom-nav {
    display: flex;
  }
  .view-content {
    padding: 16px;
    padding-bottom: 80px;
  }
  .dashboard-columns, .billing-header-grid {
    grid-template-columns: 1fr;
  }
}
