/* ==========================================================================
   rotis Industrial Energy Intelligence Platform — Base Styles (app-base.css)
   Pristine Light SCADA/Dashboard Theme for Enterprise Cold Storage
   ========================================================================== */

:root {
  /* Colors */
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-alt: #F1F5F9;
  --bg-surface-elevated: #FFFFFF;
  
  --border-subtle: #E2E8F0;
  --border-strong: #CBD5E1;
  --border-focus: #3B82F6;
  
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-dim: #94A3B8;
  --text-inverse: #FFFFFF;

  /* Brand Accents */
  --brand-primary: #2563EB;
  --brand-primary-hover: #1D4ED8;
  --brand-primary-subtle: #EFF6FF;
  --brand-primary-border: #BFDBFE;

  --accent-cyan: #0284C7;
  --accent-cyan-subtle: #E0F2FE;

  --status-success: #10B981;
  --status-success-subtle: #ECFDF5;
  --status-success-border: #A7F3D0;

  --status-warning: #F59E0B;
  --status-warning-subtle: #FFFBEB;
  --status-warning-border: #FDE68A;

  --status-danger: #EF4444;
  --status-danger-subtle: #FEF2F2;
  --status-danger-border: #FECACA;

  --status-info: #6366F1;
  --status-info-subtle: #EEF2FF;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  /* Dimensions */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 80px;
  --header-height: 72px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
  --shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.15);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
}

/* Monospace Metrics */
.metric-value, .mono, [data-mono] {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1, "zero" 1;
}

/* ==========================================================================
   App Structure Layout
   ========================================================================== */

.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg-app);
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: width var(--transition-normal);
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.sidebar-brand img {
  height: 26px;
  width: auto;
}

.brand-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--brand-primary-subtle);
  color: var(--brand-primary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--brand-primary-border);
  letter-spacing: 0.05em;
}

/* Facility Selector Box */
.facility-selector {
  padding: 16px 16px 8px 16px;
}

.facility-card {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.facility-card:hover {
  border-color: var(--brand-primary-border);
  background: #F8FAFC;
}

.facility-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.facility-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.facility-status {
  font-size: 11px;
  color: var(--status-success);
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-success);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  padding: 12px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 12px 10px 6px 10px;
  letter-spacing: 0.05em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-surface-alt);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--brand-primary-subtle);
  color: var(--brand-primary);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  stroke-width: 1.8;
}

.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  color: var(--text-muted);
}

.nav-badge.alert {
  background: var(--status-danger-subtle);
  color: var(--status-danger);
}

/* Sidebar Footer & User Profile */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.user-profile-card:hover {
  background: var(--bg-surface-alt);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: #E2E8F0;
  color: var(--brand-primary);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-details {
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  font-size: 11px;
  color: var(--brand-primary);
  display: inline-block;
  font-weight: 500;
}

/* Role Quick Switcher */
.role-pill-selector {
  display: flex;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  gap: 2px;
}

.role-btn {
  flex: 1;
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-align: center;
  transition: all var(--transition-fast);
}

.role-btn.active {
  background: var(--bg-surface);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Main Content Area & Top Header
   ========================================================================== */

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.app-header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.page-title-box {
  display: flex;
  flex-direction: column;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Live Telemetry Pills in Header */
.telemetry-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
}

.telemetry-pill.tariff-t2 {
  background: #FEF3C7;
  border-color: #FDE68A;
  color: #B45309;
}

.telemetry-pill.tariff-t3 {
  background: #FEE2E2;
  border-color: #FECACA;
  color: #B91C1C;
}

.telemetry-pill.tariff-t1 {
  background: #ECFDF5;
  border-color: #A7F3D0;
  color: #047857;
}

.impulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-success);
  transition: transform 0.1s ease, background 0.1s ease;
}

.impulse-dot.flash {
  transform: scale(1.6);
  background: #059669;
  box-shadow: 0 0 10px #10B981;
}

.header-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.header-btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.header-btn-secondary:hover {
  background: var(--bg-surface-alt);
  border-color: var(--border-strong);
}

.header-btn-primary {
  background: var(--brand-primary);
  color: var(--text-inverse);
}

.header-btn-primary:hover {
  background: var(--brand-primary-hover);
}

/* Main Content Body */
.app-content {
  padding: 28px 32px 60px 32px;
  flex: 1;
}


/* ==========================================================================
   Mobile Controls & Drawer Navigation
   ========================================================================== */

.mobile-sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  flex-shrink: 0;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mobile-sidebar-toggle:hover {
  background: #E2E8F0;
  color: var(--brand-primary);
}

.sidebar-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: all var(--transition-fast);
  margin-left: auto;
}

.sidebar-close-btn:hover {
  background: #FEE2E2;
  color: #DC2626;
  border-color: #FECACA;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* Mobile Bottom Navigation Dock */
.app-mobile-dock {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #FFFFFF;
  border-top: 1px solid var(--border-subtle);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  z-index: 95;
  justify-content: space-around;
  align-items: center;
  padding: 0 4px;
  box-sizing: border-box;
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-decoration: none;
  flex: 1;
  padding: 6px 0;
  transition: color 0.15s ease;
}

.dock-item:hover, .dock-item.active {
  color: var(--brand-primary);
}

.dock-item svg {
  flex-shrink: 0;
}

/* Top Demo Banner Styling */
.demo-topbar-banner {
  background: #064E3B;
  color: #ECFDF5;
  padding: 8px 24px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 9999;
  border-bottom: 1px solid #047857;
  gap: 12px;
}

.demo-banner-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}
.demo-banner-left span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.demo-pill-badge {
  background: #10B981;
  color: #FFFFFF;
  font-size: 9.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.demo-tg-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.25);
  border: 1px solid #10B981;
  color: #FFFFFF;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
  white-space: nowrap;
}

.demo-tg-link:hover {
  background: #10B981;
}

/* ==========================================================================
   Full Responsive Breakpoints (Tablet & Mobile SCADA)
   ========================================================================== */

@media (max-width: 1024px) {
  .app-sidebar {
    width: var(--sidebar-collapsed-width);
  }
  .sidebar-brand span,
  .facility-info,
  .nav-item span,
  .nav-badge,
  .nav-section-title,
  .user-details,
  .role-pill-selector {
    display: none;
  }
  .app-main {
    margin-left: var(--sidebar-collapsed-width);
  }
  .app-header {
    padding: 0 16px;
  }
  .app-content {
    padding: 18px 16px;
  }
}

@media (max-width: 860px) {
  .mobile-sidebar-toggle {
    display: inline-flex;
  }
  .sidebar-close-btn {
    display: inline-flex;
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: none;
    overflow-y: auto;
  }
  .app-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.4);
  }
  .app-sidebar.mobile-open .sidebar-brand span,
  .app-sidebar.mobile-open .facility-info,
  .app-sidebar.mobile-open .nav-item span,
  .app-sidebar.mobile-open .nav-badge,
  .app-sidebar.mobile-open .nav-section-title,
  .app-sidebar.mobile-open .user-details,
  .app-sidebar.mobile-open .role-pill-selector {
    display: block;
  }
  .app-sidebar.mobile-open .nav-item {
    display: flex;
  }
  .app-sidebar.mobile-open .role-pill-selector {
    display: flex;
  }
  
  .app-main {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  /* Two-row header on mobile: Row 1 = Toggle + Title, Row 2 = Horizontal scrolling telemetry strip */
  .app-header {
    height: auto;
    min-height: 56px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 90;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }
  
  .header-left {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    gap: 10px;
    min-width: 0;
  }

  .page-title {
    font-size: 15.5px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-subtitle {
    display: none;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .header-right::-webkit-scrollbar {
    display: none;
  }

  .telemetry-pill {
    padding: 4px 10px;
    font-size: 11px;
    gap: 6px;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .header-btn {
    padding: 5px 10px;
    font-size: 11.5px;
    flex-shrink: 0;
    white-space: nowrap;
  }
}

@media (max-width: 640px) {
  .app-mobile-dock {
    display: flex;
  }
  .app-content {
    padding: 12px 10px 76px 10px;
    max-width: 100vw;
    box-sizing: border-box;
  }
  .demo-topbar-banner {
    padding: 6px 12px;
    flex-direction: column;
    text-align: center;
    gap: 6px;
    max-width: 100vw;
    box-sizing: border-box;
  }
  .demo-banner-left {
    white-space: normal;
    justify-content: center;
    font-size: 11px;
    text-align: center;
  }
}
