/* ===========================
   Admin Dashboard – Final CSS
   (Fixed + smooth sidebar slide on resize + smooth cards + skeleton charts)
   =========================== */

/* ---------- GLOBAL ---------- */
:root{
  --bg: #1d2634;
  --surface: #263043;
  --muted: #9e9ea4;
  --text: rgba(255, 255, 255, 0.95);
  --shadow-1: 0 6px 7px -3px rgba(0,0,0,0.35);
  --shadow-2: 0 6px 7px -4px rgba(0,0,0,0.20);
  --radius: 8px;
  --gap: 20px;

  --sidebar-w: 260px;
  --header-h: 70px;

  --ease-out: cubic-bezier(0.2, 0, 0, 1);
}

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

html{
  scrollbar-gutter: stable;
}

/* Disable transitions during active resizing (optional; only if JS toggles html.is-resizing) */
html.is-resizing *,
html.is-resizing *::before,
html.is-resizing *::after{
  transition: none !important;
  animation: none !important;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* optional: lock background scroll when sidebar is open on mobile */
body.sidebar-open{
  overflow: hidden;
}

.material-icons-outlined {
  vertical-align: middle;
  line-height: 1px;
  font-size: 35px;
}

:focus-visible{
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 3px;
  border-radius: 6px;
}

/* Skip link (accessibility) */
.skip-link{
  position:absolute;
  left:-999px;
  top:10px;
  background:#000;
  color:#fff;
  padding:10px 12px;
  border-radius:8px;
  z-index:9999;
}
.skip-link:focus{ left:10px; }

/* Prevent grid children from forcing overflow (important for smooth resize) */
.header,
.main-container {
  min-width: 0;
}

/* ---------- LAYOUT GRID ---------- */
/* Sidebar is fixed always. The container lays out header + main,
   reserving space for sidebar via padding-left on desktop. */
.grid-container {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "header"
    "main";
  min-height: 100vh;
  min-height: 100svh;

  /* Reserve space for fixed sidebar on desktop */
  padding-left: var(--sidebar-w);
  transition: padding-left 220ms var(--ease-out);
}

/* ---------- HEADER ---------- */
.header {
  grid-area: header;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 3vw, 30px);
  box-shadow: var(--shadow-1);
}

/* Use real buttons in HTML; remove default button styling */
.menu-icon,
#close-sidebar{
  background: none;
  border: 0;
  color: inherit;
  padding: 0;
  font: inherit;
}

.menu-icon {
  display: none;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

/* ---------- SIDEBAR ---------- */
/* Fixed ALWAYS (prevents popping when crossing breakpoints) */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 12;

  background-color: var(--surface);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;

  transform: translateX(0);
  transition: transform 220ms var(--ease-out);
  will-change: transform;
}

.sidebar-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px;
  margin-bottom: 30px;
}

.sidebar-brand {
  margin-top: 15px;
  font-size: 20px;
  font-weight: 700;
}

/* Close button hidden on desktop; shown on mobile in media query */
.sidebar-title > button { display: none; }

.sidebar-list {
  padding: 0;
  margin-top: 15px;
  list-style-type: none;
}

.sidebar-list-item {
  padding: 20px;
  font-size: 18px;
  transition: background-color 140ms ease;
}

.sidebar-list-item:hover {
  background-color: rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.sidebar-list-item > a {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  text-decoration: none;
  color: var(--muted);
  cursor: pointer; /* ensure pointer even if li hover is overridden */
}

/* Open state class (mainly used on mobile) */
.sidebar-responsive {
  z-index: 12 !important; /* above charts/backdrop */
}

/* ---------- Development Data section label ---------- */
.sidebar-section{
  padding: 12px 20px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255,255,255,0.65);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-section-title{
  white-space: nowrap;
}

.sidebar-section-divider{
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.12);
}

/* ---------- Robot Status folder fixes ---------- */
/* IMPORTANT: remove the "whole folder block" hover highlight */
.sidebar-list-item.folder:hover{
  background-color: transparent; /* stops highlighting the entire folder container */
  cursor: default;
}

/* Also prevent the top folder row from highlighting on hover */
.sidebar-list-item.folder > a:hover{
  background-color: transparent;
}

/* Folder children indent + remove nested list top margin from .sidebar-list */
.folder-children{
  margin-top: 6px;
  padding-left: 22px;
}

/* Toggle icon alignment + rotation */
.folder-toggle{
  margin-left: auto;
  font-size: 26px; /* smaller than main icons */
  line-height: 1;
  user-select: none;
  transition: transform 180ms var(--ease-out);
}

.folder-toggle[aria-expanded="true"]{
  transform: rotate(90deg);
}

/* ---------- MAIN ---------- */
.main-container {
  grid-area: main;
  overflow-y: auto;
  padding: 20px;
  color: var(--text);
  -webkit-overflow-scrolling: touch;
}

.main-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ---------- SUMMARY CARDS ---------- */
/* Keep 4 cards together and smoothly scale (no reflow jumps) */
.main-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(10px, 1.5vw, 20px);
  margin: 20px 0;
  align-items: stretch;
}

/* Cards can shrink cleanly */
.card {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  min-width: 0;
  padding: clamp(14px, 1.6vw, 25px);
  border-radius: var(--radius);

  transform: translateZ(0);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px -10px rgba(0, 0, 0, 0.45);
}

.card:first-child { background-color: #2962ff; }
.card:nth-child(2) { background-color: #ff6d00; }
.card:nth-child(3) { background-color: #2e7d32; }
.card:nth-child(4) { background-color: #d50000; }

.card-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.card-inner h2,
.card-inner h3 {
  margin: 0;
  font-size: clamp(12px, 1.05vw, 16px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Supports either <p class="card-value"> or old <h1> numbers */
.card-value,
.card h1 {
  margin: 10px 0 0;
  font-size: clamp(22px, 2.4vw, 40px);
  line-height: 1.05;
}

.card-inner > .material-icons-outlined {
  font-size: clamp(26px, 2.2vw, 45px);
}

/* If screens get extremely narrow, keep 4 together but allow horizontal scroll */
@media (max-width: 520px) {
  .main-cards {
    grid-template-columns: repeat(4, minmax(220px, 1fr));
    overflow-x: auto;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
  }
  .card { scroll-snap-align: start; }
}

/* ---------- CHARTS ---------- */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--gap);
  margin-top: 60px;
}

.charts-card {
  background-color: var(--surface);
  margin-bottom: 20px;
  padding: 25px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  contain: content; /* reduces jank when charts repaint */
}

.chart-title {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Chart containers (fade-in controlled by JS classes) */
#bar-chart,
#area-chart {
  min-height: 350px;
  position: relative;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 220ms var(--ease-out);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Skeleton shimmer while chart loads */
#bar-chart.chart-loading::after,
#area-chart.chart-loading::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04),
    rgba(255,255,255,0.09),
    rgba(255,255,255,0.04)
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

/* When ready, fade in smoothly */
#bar-chart.chart-ready,
#area-chart.chart-ready{
  opacity: 1;
  transform: translateY(0);
}

/* ---------- BACKDROP (created by JS) ---------- */
.backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease-out);
  z-index: 11; /* below sidebar (12) */
}

.backdrop.show{
  opacity: 1;
  pointer-events: auto;
}

/* ---------- MEDIA QUERIES ---------- */
@media screen and (max-width: 992px) {
  /* Content takes full width */
  .grid-container {
    padding-left: 0;
  }

  .menu-icon { display: inline; }

  /* Mobile default: sidebar off-canvas */
  #sidebar {
    transform: translateX(-105%);
    box-shadow: none;
  }

  /* Mobile open: slide in */
  #sidebar.sidebar-responsive {
    transform: translateX(0);
    box-shadow: 0 16px 35px rgba(0,0,0,0.55);
  }

  /* show close button on mobile */
  .sidebar-title > button { display: inline; }
}

@media screen and (max-width: 576px) {
  .header-left { display: none; }
}

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  #sidebar,
  .card,
  .sidebar-list-item,
  .backdrop,
  #bar-chart,
  #area-chart { transition: none !important; }

  #bar-chart.chart-loading::after,
  #area-chart.chart-loading::after { animation: none !important; }
}

/* ===========================
   Page transition (fade)
   =========================== */

/* Start hidden, then fade in when body gets .is-loaded */
.main-container {
  opacity: 0;
  transition: opacity 260ms var(--ease-out);
  will-change: opacity;
}

body.is-loaded .main-container {
  opacity: 1;
}

/* Fade out before leaving the page */
body.is-fading-out .main-container {
  opacity: 0;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .main-container {
    transition: none !important;
  }
}