/* ==========================================================================
   VIVIENDA — SISTEMA DE DISEÑO SAAS PROFESIONAL
   Paleta: Azul Petróleo (#0A2540 / #0F3557) + Turquesa Esmeralda (#00B4A6)
   ========================================================================== */

:root {
  --petrol-950: #06182c;
  --petrol-900: #0A2540;
  --petrol-800: #0F3557;
  --petrol-700: #164873;
  --petrol-600: #1E5D91;

  --teal-600: #009688;
  --teal-500: #00B4A6;
  --teal-400: #26C6DA;
  --teal-50:  #E6F8F6;

  --bg-body: #F3F6FA;
  --bg-card: #FFFFFF;
  --bg-subtle: #F8FAFC;

  --text-main: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;

  --border-color: #E2E8F0;
  --border-focus: #00B4A6;

  --status-success-bg: #DCFCE7;
  --status-success-tx: #15803D;
  --status-warning-bg: #FEF3C7;
  --status-warning-tx: #B45309;
  --status-danger-bg:  #FEE2E2;
  --status-danger-tx:  #B91C1C;
  --status-info-bg:    #E0F2FE;
  --status-info-tx:    #0369A1;
  --status-neutral-bg: #F1F5F9;
  --status-neutral-tx: #475569;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(10, 37, 64, 0.06), 0 1px 2px rgba(10, 37, 64, 0.04);
  --shadow-md: 0 4px 12px rgba(10, 37, 64, 0.08);
  --shadow-lg: 0 12px 28px rgba(10, 37, 64, 0.14);
}

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

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

a {
  color: var(--petrol-700);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  color: var(--teal-600);
}

/* ==========================================================================
   LAYOUT PRINCIPAL (SIDEBAR + MAIN + MOBILE BOTTOM NAV)
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: 264px;
  background: linear-gradient(180deg, var(--petrol-900) 0%, var(--petrol-950) 100%);
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  box-shadow: 2px 0 16px rgba(6, 24, 44, 0.18);
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--teal-500) 0%, #10B981 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: var(--petrol-950);
  box-shadow: 0 4px 12px rgba(0, 180, 166, 0.35);
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #FFFFFF;
}

.brand-text span {
  display: block;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 500;
}

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

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.45);
  padding: 12px 12px 4px;
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.78);
  font-weight: 500;
  font-size: 13.8px;
  transition: all 0.15s ease;
}

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

.nav-link.active {
  background: rgba(0, 180, 166, 0.18);
  color: #FFFFFF;
  border-left: 3px solid var(--teal-500);
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  height: 18px;
  opacity: 0.9;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.15);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.app-main {
  flex: 1;
  margin-left: 264px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-bottom: 40px;
}

/* ==========================================================================
   TOPBAR
   ========================================================================== */

.app-topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 80;
}

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

.page-heading {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--petrol-900);
}

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

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--status-success-bg);
  color: var(--status-success-tx);
}

.conn-pill.offline {
  background: var(--status-warning-bg);
  color: var(--status-warning-tx);
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.app-content {
  padding: 26px 28px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* ==========================================================================
   CARDS, KPIS & GRIDS
   ========================================================================== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--petrol-800);
}

.kpi-card.accent-teal::before { background: var(--teal-500); }
.kpi-card.accent-warning::before { background: #F59E0B; }
.kpi-card.accent-danger::before { background: #EF4444; }
.kpi-card.accent-success::before { background: #10B981; }

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 23px;
  font-weight: 800;
  color: var(--petrol-900);
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 22px;
  overflow: hidden;
}

.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: #FFFFFF;
}

.card-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  color: var(--petrol-900);
}

.card-body {
  padding: 20px 22px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* ==========================================================================
   STATUS BADGES
   ========================================================================== */

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--status-success-bg); color: var(--status-success-tx); }
.badge-warning { background: var(--status-warning-bg); color: var(--status-warning-tx); }
.badge-danger  { background: var(--status-danger-bg);  color: var(--status-danger-tx); }
.badge-info    { background: var(--status-info-bg);    color: var(--status-info-tx); }
.badge-primary { background: var(--teal-50);           color: var(--teal-600); }
.badge-neutral { background: var(--status-neutral-bg); color: var(--status-neutral-tx); }

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

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

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

.data-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  font-size: 13.5px;
  vertical-align: middle;
}

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

/* ==========================================================================
   FORMS & BUTTONS
   ========================================================================== */

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

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

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

.form-control {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #CBD5E1;
  font-size: 13.8px;
  font-family: inherit;
  color: var(--text-main);
  background: #FFFFFF;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(0, 180, 166, 0.15);
}

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

.btn-primary {
  background: var(--petrol-900);
  color: #FFFFFF;
}
.btn-primary:hover {
  background: var(--petrol-800);
  color: #FFFFFF;
}

.btn-teal {
  background: var(--teal-500);
  color: var(--petrol-950);
}
.btn-teal:hover {
  background: var(--teal-600);
  color: #FFFFFF;
}

.btn-outline {
  background: #FFFFFF;
  border-color: #CBD5E1;
  color: var(--petrol-900);
}
.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: var(--petrol-700);
}

.btn-danger {
  background: #DC2626;
  color: #FFFFFF;
}
.btn-danger:hover {
  background: #B91C1C;
  color: #FFFFFF;
}

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

/* ==========================================================================
   TABS & ALERTS
   ========================================================================== */

.tabs-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-secondary);
  border-bottom: 3px solid transparent;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--petrol-900);
}

.tab-btn.active {
  color: var(--petrol-900);
  border-bottom-color: var(--teal-500);
}

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

.alert {
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-weight: 500;
  font-size: 13.8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-success { background: var(--status-success-bg); color: var(--status-success-tx); border: 1px solid #BBF7D0; }
.alert-error   { background: var(--status-danger-bg);  color: var(--status-danger-tx);  border: 1px solid #FECACA; }
.alert-warning { background: var(--status-warning-bg); color: var(--status-warning-tx); border: 1px solid #FDE68A; }
.alert-info    { background: var(--status-info-bg);    color: var(--status-info-tx);    border: 1px solid #BAE6FD; }

/* ==========================================================================
   MODALS
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 24, 44, 0.6);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-body {
  padding: 20px 22px;
}

/* ==========================================================================
   AUTH LAYOUT (PANTALLA DE ACCESO)
   ========================================================================== */

.auth-wrapper {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  background: var(--petrol-950);
}

.auth-hero {
  background: radial-gradient(circle at 20% 20%, rgba(0, 180, 166, 0.22), transparent 55%),
              linear-gradient(135deg, var(--petrol-900) 0%, var(--petrol-950) 100%);
  color: #FFFFFF;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-panel {
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

/* ==========================================================================
   MOBILE BOTTOM NAVIGATION (PWA MOBILE-FIRST)
   ========================================================================== */

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--petrol-900);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 120;
  justify-content: space-around;
  align-items: center;
  padding: 0 6px;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 10.5px;
  font-weight: 500;
  gap: 3px;
  padding: 6px 8px;
  border-radius: 8px;
}

.mobile-nav-item.active {
  color: var(--teal-400);
  font-weight: 700;
}

@media (max-width: 960px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .app-sidebar.mobile-open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
    padding-bottom: 76px;
  }
  .app-topbar {
    padding: 0 16px;
  }
  .app-content {
    padding: 18px 14px;
  }
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .auth-wrapper {
    grid-template-columns: 1fr;
  }
  .auth-hero {
    padding: 28px 22px;
  }
  .mobile-bottom-nav {
    display: flex;
  }
}

@media print {
  .app-sidebar, .app-topbar, .mobile-bottom-nav, .no-print {
    display: none !important;
  }
  .app-main {
    margin: 0 !important;
    padding: 0 !important;
  }
  body {
    background: #FFFFFF;
  }
}
