/* Copied from Battery_management static CSS to unify styling across apps.
   Note: If there are differences, adjust selectors accordingly. */
/* Placeholder: the actual CSS from Battery_management/static/css/dashboard.css will be referenced.
   Since direct copying line-by-line isn't shown here, ensure this file exists and is served. */
:root, [data-theme="dark"] {
  --bg: #0b0f1a;
  --bg-grad-1: #0b0f1a;
  --bg-grad-2: #0f172a;
  --panel: rgba(255,255,255,0.06);
  --panel-border: rgba(255,255,255,0.12);
  --panel-hover: rgba(255,255,255,0.08);
  --text: #e6e8ef;
  --text-muted: #9aa4b2;
  --primary: #f97316;
  --primary-600: #ea580c;
  --primary-400: #fb923c;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --ring: rgba(249, 115, 22, 0.45);
}

/* Light theme variables */
[data-theme="light"] {
  --bg: #f7f8fb;
  --bg-grad-1: #eef2f7;
  --bg-grad-2: #e5eaf3;
  --panel: rgba(255,255,255,0.85);
  --panel-border: rgba(0,0,0,0.08);
  --panel-hover: rgba(0,0,0,0.05);
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #f97316;
  --primary-600: #ea580c;
  --primary-400: #fb923c;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --ring: rgba(234, 88, 12, 0.35);
}

/* Adjust overlays for light */
[data-theme="light"] body::before { opacity: 0.08; }
[data-theme="light"] body::after { background: #ffffff; opacity: 0.6; }

html { overflow-x: hidden; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, rgba(249,115,22,0.10) 0%, rgba(249,115,22,0) 60%),
              radial-gradient(900px 500px at 100% 10%, rgba(59,130,246,0.10) 0%, rgba(59,130,246,0) 60%),
              linear-gradient(180deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow-x: hidden;
  min-height: 100%;
}

.glass-card { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px; backdrop-filter: blur(12px); }
.card-header-gradient { padding: 12px 16px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%); color: #fff; border-top-left-radius: 16px; border-top-right-radius: 16px; }
.stat-card { box-shadow: 0 8px 30px rgba(0,0,0,0.35); }
.stat-label { color: var(--text-muted); font-size: 0.9rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.progress-custom { height: 8px; background: var(--panel-hover); border-radius: 8px; overflow: hidden; }
.progress-bar-custom { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-400)); color: #fff; font-size: 0.75rem; text-align: right; padding-right: 6px; }

.theme-toggle { position: fixed; top: 20px; right: 20px; width: 50px; height: 50px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 1000; transition: all 0.3s ease; }
.theme-toggle:hover { transform: rotate(180deg); box-shadow: 0 10px 40px rgba(249, 115, 22, 0.25); }
.theme-toggle i { color: var(--primary); font-size: 20px; }

/* Back Button - same style as theme toggle */
.back-button { position: fixed; top: 20px; left: 20px; width: 50px; height: 50px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 1000; transition: all 0.3s ease; text-decoration: none; }
.back-button:hover { transform: translateX(-3px); box-shadow: 0 10px 40px rgba(249, 115, 22, 0.25); border-color: var(--primary); }
.back-button i { color: var(--primary); font-size: 20px; }

.user-menu { position: fixed; top: 20px; left: 20px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; padding: 10px 12px; }
.user-menu .user-info { display:flex; align-items:center; gap:8px; color: var(--text); }
.user-menu .user-dropdown { display:flex; gap:12px; margin-top:8px; }

/* Ensure media scales and doesn't overflow */
img, svg, canvas, video { max-width: 100%; height: auto; display: block; }

/* Tables and pre/code blocks responsiveness */
.table { width: 100%; max-width: 100%; }
.table-responsive, .table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
pre, code, .code-block { max-width: 100%; overflow-x: auto; display: block; }

/* Container sizing */
.container, .container-fluid { width: 100%; max-width: 100%; box-sizing: border-box; }
/* Ensure page content offsets fixed sidebar */
.content-with-sidebar { margin-left: 240px; max-width: calc(100vw - 240px); overflow-x: hidden; padding-right: 12px; padding-left: 12px; box-sizing: border-box; }
.page-content.content-with-sidebar { margin-left: 240px; }
@media (max-width: 992px) { .content-with-sidebar, .page-content.content-with-sidebar { margin-left: 220px; max-width: calc(100vw - 220px); } }
@media (max-width: 768px) { .content-with-sidebar, .page-content.content-with-sidebar { margin-left: 0; max-width: 100vw; } }

/* Page content should offset the fixed sidebar when it is present */
.page-content.content-with-sidebar { margin-left: 240px; }
@media (max-width: 992px) { .page-content.content-with-sidebar { margin-left: 220px; } }
@media (max-width: 768px) { .page-content.content-with-sidebar { margin-left: 0; } }

/* Sidebar adjustments on smaller screens */
@media (max-width: 992px) {
  .sidebar { width: 220px; }
  .content-with-sidebar { margin-left: 220px; max-width: calc(100vw - 220px); }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; width: 200px; }
  .content-with-sidebar { margin-left: 0; max-width: 100vw; }
}

/* Background pattern overlay for pages that need it */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-image: url('../images/background_pattern.png');
  background-size: cover; background-position: center; background-repeat: no-repeat;
  opacity: 0.25; z-index: -2; pointer-events: none;
}

/* Dark overlay */
body::after {
  content: "";
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg); opacity: 0.35; z-index: -1; pointer-events: none;
}

/* Login page styles */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; overflow-x: hidden; }
.login-container { background: var(--panel); backdrop-filter: blur(12px); border: 1px solid var(--panel-border); border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,0.35); overflow: hidden; width: 100%; max-width: 420px; z-index: 1; margin: auto; }
.login-header { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%); color: #fff; padding: 35px 25px; text-align: center; }
.header-icon { width: 70px; height: 70px; background: rgba(255, 255, 255, 0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 15px; backdrop-filter: blur(10px); }
.header-icon i { font-size: 32px; color: white; }
.login-header h1 { font-size: 26px; margin-bottom: 8px; font-weight: 700; }
.login-header p { font-size: 14px; opacity: 0.95; }
.login-body { padding: 35px 30px; background: var(--bg); }
.form-group { margin-bottom: 22px; }
.form-group label { display: flex; align-items: center; margin-bottom: 8px; color: var(--text); font-weight: 500; font-size: 14px; }
.form-group label i { margin-right: 8px; color: var(--primary); width: 16px; text-align: center; }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"] { width: 100%; padding: 13px 16px; border: 2px solid var(--panel-border); border-radius: 8px; font-size: 14px; background: var(--panel); color: var(--text); transition: all 0.3s; }
.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus,
.form-group input[type="email"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); background: var(--bg); }
.btn-login { width: 100%; padding: 14px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-login:hover { transform: translateY(-2px); box-shadow: 0 10px 40px rgba(249, 115, 22, 0.25); }
.btn-login:active { transform: translateY(0); }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; font-size: 14px; border: 1px solid; }
.alert-success { background: rgba(16, 185, 129, 0.15); color: var(--success); border-color: rgba(16, 185, 129, 0.3); }
.alert-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.alert-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }
.alert-info { background: rgba(59, 130, 246, 0.15); color: var(--info); border-color: rgba(59, 130, 246, 0.3); }
.login-footer { text-align: center; padding: 20px; background: var(--panel-hover); color: var(--text-muted); font-size: 12px; }

/* Sidebar */
.sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: 240px; background: var(--panel); border-right: 1px solid var(--panel-border); backdrop-filter: blur(10px); z-index: 100; overflow-y: auto; }
.sidebar .brand { height: 64px; display: flex; align-items: center; padding: 0 16px; gap: 10px; border-bottom: 1px solid var(--panel-border); color: var(--text); }
.sidebar .nav { list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; }
.sidebar .nav a { display: flex; flex-direction: row; align-items: center; gap: 10px; color: var(--text); text-decoration: none; padding: 10px 12px; border-radius: 8px; margin-bottom: 4px; transition: all 0.2s; width: 100%; }
.sidebar .nav a:hover { background: var(--panel-hover); }
.sidebar .nav a i { width: 20px; text-align: center; flex-shrink: 0; }
.sidebar .nav a span { flex-grow: 1; }
.content-with-sidebar { margin-left: 240px; max-width: calc(100vw - 240px); overflow-x: hidden; padding-right: 12px; padding-left: 12px; box-sizing: border-box; }

/* Prevent horizontal scroll */
body { overflow-x: hidden; max-width: 100vw; margin: 0; padding: 0; }
.container-fluid { max-width: 100%; padding-right: 15px; padding-left: 15px; box-sizing: border-box; }
.row { margin-left: 0; margin-right: 0; }
.col, [class*="col-"] { padding-left: 12px; padding-right: 12px; box-sizing: border-box; }

/* Glass cards responsive */
.glass-card { max-width: 100%; box-sizing: border-box; }
.stat-card { max-width: 100%; box-sizing: border-box; }

/* Table responsive wrapper */
.table-responsive { overflow-x: auto; margin-left: 0; margin-right: 0; }

/* Theme toggle overrides to avoid overlap with sidebar */
.theme-toggle { right: 20px; top: 20px; z-index: 1000; transition: all 0.3s; }
.theme-toggle:hover { transform: rotate(180deg); box-shadow: 0 10px 40px rgba(249, 115, 22, 0.25); }
.theme-toggle i { color: var(--primary); font-size: 20px; }

/* Card styles for profile and settings */
.card { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; color: var(--text); }
.card-header { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%); color: #fff; border-bottom: 1px solid var(--panel-border); padding: 12px 16px; border-top-left-radius: 12px; border-top-right-radius: 12px; }
.card-body { padding: 20px; background: var(--panel); }
.card h5, .card h6 { color: var(--text); }
.form-control { background: var(--panel); border: 1px solid var(--panel-border); color: var(--text); }
.form-control:focus { background: var(--bg); border-color: var(--primary); color: var(--text); box-shadow: 0 0 0 3px var(--ring); }
.form-control:disabled { background: var(--panel-hover); color: var(--text-muted); }
.form-label { color: var(--text); font-weight: 500; }
.form-select { background: var(--panel); border: 1px solid var(--panel-border); color: var(--text); }
.form-select:focus { background: var(--bg); border-color: var(--primary); color: var(--text); box-shadow: 0 0 0 3px var(--ring); }
.text-muted { color: var(--text-muted) !important; }
.list-group-item { background: var(--panel); border-color: var(--panel-border); color: var(--text); }
.badge { font-weight: 500; }
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%); border: none; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(249, 115, 22, 0.3); }
.btn-secondary { background: var(--panel); border: 1px solid var(--panel-border); color: var(--text); }
.btn-secondary:hover { background: var(--panel-hover); color: var(--text); }
.btn-success { background: linear-gradient(135deg, var(--success) 0%, #059669 100%); border: none; color: #fff; }
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(16, 185, 129, 0.3); }
.btn-outline-secondary { color: var(--text); border-color: var(--panel-border); }
.btn-outline-secondary:hover { background: var(--panel); color: var(--text); border-color: var(--panel-border); }
.btn-outline-danger { color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }
.table { color: var(--text); }
.table-hover tbody tr:hover { background: var(--panel-hover); }
.form-check-input { background-color: var(--panel); border-color: var(--panel-border); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-label { color: var(--text); }

* { box-sizing: border-box; }

/* Cards grid helper for pages with multiple cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; align-items: stretch; }

/* Prevent cards from exceeding container width */
.card, .glass-card, .stat-card { width: 100%; max-width: 100%; overflow: hidden; }
.card-body, .card-header, .card-footer { max-width: 100%; overflow-wrap: anywhere; }

/* Images inside cards scale properly */
.card img { max-width: 100%; height: auto; display: block; }

/* Ensure Bootstrap rows wrap instead of forcing overflow */
.row { display: flex; flex-wrap: wrap; margin-left: 0; margin-right: 0; }

/* Prevent nested rows from adding overflow due to negative margins */
.row { margin-left: 0; margin-right: 0; }
.col, [class*="col-"] { padding-left: 12px; padding-right: 12px; box-sizing: border-box; }

/* Flash messages and alerts should wrap */
.alert { word-wrap: break-word; overflow-wrap: anywhere; }

/* App shell layout */
.app-shell { display: flex; flex-direction: row; align-items: stretch; width: 100vw; max-width: 100vw; overflow-x: hidden; }
.page-content { flex: 1 1 auto; min-width: 0; /* allow flex item to shrink and wrap */ }

/* Sidebar is already fixed; ensure consistent width and no horizontal scroll */
.sidebar { flex: 0 0 240px; }
@media (max-width: 992px) { .sidebar { flex-basis: 220px; } }
@media (max-width: 768px) { .sidebar { display: none; } .page-content { flex: 1 1 auto; min-width: 0; } }

/* Remove previous override that forced margin-left: 0 and caused overlap */
/* .content-with-sidebar { margin-left: 0; max-width: 100%; } */

/* Themed table styles to blend with design */
.table, .table-dark { background-color: var(--panel); color: var(--text); border-color: var(--panel-border); }
.table thead, .table-dark thead { background-color: var(--panel-hover); }
.table-striped > tbody > tr:nth-of-type(odd) { --bs-table-accent-bg: var(--panel-hover); background-color: var(--panel-hover); }
.table-hover > tbody > tr:hover { --bs-table-accent-bg: var(--panel-hover); background-color: var(--panel-hover); }
/* Ensure page section backgrounds are cohesive and not pure black */
.section-bg, .card-body, .container-fluid { background: transparent; }

/* Mobile menu toggle button */
.mobile-menu-toggle { position: fixed; left: 16px; top: 16px; z-index: 1001; background: var(--panel); border: 1px solid var(--panel-border); color: var(--text); padding: 8px 12px; border-radius: 8px; }
.mobile-menu-toggle i { font-size: 18px; }
@media (min-width: 769px) { .mobile-menu-toggle { display: none !important; } }

/* Off-canvas sidebar for mobile */
@media (max-width: 768px) {
  .sidebar { display: block; transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 0 6px 24px rgba(0,0,0,0.35); }
  .sidebar.sidebar-open { transform: translateX(0); }
}

/* Improve touch targets */
@media (max-width: 768px) {
  .sidebar .nav a { padding: 12px 14px; font-size: 16px; }
  .theme-toggle { top: 72px; right: 16px; }
}

/* Ensure tables scroll smoothly on small screens */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Reduce padding for containers on small screens */
@media (max-width: 576px) {
  .container-fluid { padding-left: 10px; padding-right: 10px; }
  .card-body { padding: 16px; }
  .card-header { padding: 10px 14px; }
}
