:root {
  --navy: #0b3d5c;
  --navy-deep: #072a40;
  --maroon: #6b1d2a;
  --maroon-deep: #4a1220;
  --cream: #f4f1ec;
  --surface: #ffffff;
  --ink: #1a2330;
  --muted: #5c6b7a;
  --line: rgba(11, 61, 92, 0.12);
  --up: #1f7a45;
  --map-1: #d6e9f5;
  --map-2: #9ec9e6;
  --map-3: #5a9ec8;
  --map-4: #2f6f9a;
  --map-5: #0b3d5c;
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
}
button, input, select { font: inherit; }
#app { min-height: 100vh; }

/* Auth */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--navy-deep), var(--navy) 55%, #1a5a7a);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  text-align: center;
}
.auth-card .logo { width: 96px; height: 96px; object-fit: contain; margin: 0 auto 12px; display: block; }
.auth-card h1 {
  font-family: var(--font-display);
  color: var(--maroon);
  font-size: 2rem;
  margin: 0 0 4px;
}
.auth-card .lede { color: var(--muted); margin: 0 0 20px; font-size: .95rem; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; border: 1px solid var(--line); background: transparent;
  border-radius: 999px; padding: 10px; cursor: pointer; color: var(--muted);
}
.tab.active { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.field { text-align: left; display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field input {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; width: 100%;
}
.btn {
  border: none; border-radius: 10px; padding: 12px 16px; cursor: pointer; font-weight: 700;
}
.btn-primary { background: var(--maroon); color: #fff; width: 100%; }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; }
.btn-ghost.dark { border-color: var(--line); color: var(--ink); }
.error { color: #b42318; min-height: 1.2em; font-size: .9rem; margin: 0 0 8px; }

/* Shell */
.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  background: #061c2e;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 22px;
  min-height: 72px;
}
.brand-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}
.brand-left .emblem {
  width: 46px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}
.brand-left h1 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  margin: 0;
  letter-spacing: .02em;
  white-space: nowrap;
  font-weight: 700;
}
.brand-divider {
  width: 1px;
  align-self: stretch;
  min-height: 42px;
  background: rgba(255,255,255,.45);
  flex-shrink: 0;
}
.brand-divider.thin { min-height: 28px; }
.top-sub {
  font-size: .78rem;
  line-height: 1.35;
  color: rgba(255,255,255,.9);
  max-width: 420px;
  margin: 0;
  font-weight: 400;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
.icon-btn {
  position: relative;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  font-size: 1.15rem;
  line-height: 1;
}
.notif-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e11d48;
  border: 1.5px solid #061c2e;
}
.admin-menu { position: relative; }
.admin-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  padding: 4px 2px;
  font-size: .95rem;
}
.admin-chip .chevron {
  font-size: .75rem;
  opacity: .85;
  margin-left: 2px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
}
.admin-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  min-width: 140px;
  overflow: hidden;
  z-index: 50;
}
.admin-dropdown button {
  width: 100%;
  border: none;
  background: transparent;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}
.admin-dropdown button:hover { background: #f4f1ec; }

.body { display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.sidebar {
  background: var(--maroon);
  color: #fff;
  padding: 18px 12px;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.03) 0 2px, transparent 2px 10px),
    linear-gradient(180deg, var(--maroon), var(--maroon-deep));
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  border: none; background: transparent; color: rgba(255,255,255,.9);
  padding: 12px 14px; border-radius: 10px; cursor: pointer; margin-bottom: 4px;
  font-weight: 600;
}
.nav-item:hover { background: rgba(0,0,0,.12); }
.nav-item.active { background: rgba(0,0,0,.28); }
.nav-item .ico { width: 18px; opacity: .95; }

.main { padding: 18px; overflow: auto; }
.page-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin: 0 0 14px;
  color: var(--navy);
}

.looms-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.kpi-stack { display: grid; gap: 10px; }
.kpi-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(11,61,92,.04);
}
.kpi-card .label {
  font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; margin-bottom: 6px;
}
.kpi-card .value {
  font-size: 1.7rem; font-weight: 700; color: var(--ink); line-height: 1.1;
}
.kpi-card .delta { color: var(--up); font-size: .82rem; margin-top: 4px; font-weight: 600; }
.kpi-card .meta { color: var(--muted); font-size: .82rem; margin-top: 4px; }

.map-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
  min-height: 520px;
  display: flex;
  flex-direction: column;
}
.map-panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; gap: 10px; flex-wrap: wrap;
}
.map-panel-head h2 { margin: 0; font-size: 1rem; color: var(--navy); }
.map-frame {
  flex: 1; min-height: 420px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: #e8f1f6;
}
#india-map { width: 100%; height: 100%; min-height: 420px; }
.map-legend {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: .75rem; color: var(--muted);
}
.map-legend span { display: inline-flex; align-items: center; gap: 4px; }
.map-legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }

.bottom-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.stat-card .label { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.stat-card .value { font-size: 1.4rem; font-weight: 700; margin-top: 4px; }
.stat-card .pct { color: var(--maroon); font-weight: 700; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; color: var(--navy); }
.chart-wrap { height: 240px; position: relative; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .04em; padding: 0 8px 10px 0; border-bottom: 1px solid var(--line);
}
.table td { padding: 10px 8px 10px 0; border-bottom: 1px solid var(--line); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.active { background: #1f8a4c; }
.dot.idle { background: #b45309; }
.dot.offline { background: #8a9390; }
.empty { color: var(--muted); padding: 12px 0; }
.updated { color: var(--muted); font-size: .8rem; margin-top: 8px; }

.marker-pin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.marker-pin.active { background: #1f8a4c; }
.marker-pin.idle { background: #b45309; }
.marker-pin.offline { background: #8a9390; }

@media (max-width: 1100px) {
  .looms-layout { grid-template-columns: 1fr; }
  .bottom-stats { grid-template-columns: 1fr 1fr; }
  .body { grid-template-columns: 1fr; }
  .sidebar { display: flex; gap: 4px; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .brand-left { flex-wrap: wrap; }
  .top-sub { max-width: 100%; }
}
@media (max-width: 640px) {
  .bottom-stats { grid-template-columns: 1fr; }
  .brand-left h1 { font-size: 1.45rem; }
  .brand-divider:not(.thin) { display: none; }
}
