@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;700;800&display=swap');

/* ---------- Theme ---------- */
:root{
  --bg: #09090b;
  --panel: rgba(24, 24, 27, 0.65);
  --panel2: rgba(39, 39, 42, 0.45);

  --border: rgba(255,255,255,0.12);
  --border2: rgba(255,255,255,0.18);

  --text: rgba(255,255,255,0.95);
  --muted: rgba(255,255,255,0.65);
  --muted2: rgba(255,255,255,0.45);
  --faint: rgba(255,255,255,0.30);

  --accent: #38bdf8;
  --accent2: #818cf8;
  --link: #60a5fa;

  --ok: #34d399;
  --good: #10b981;
  --bad: #f43f5e;
  --warn: #fbbf24;

  --shadow: 0 16px 40px rgba(0,0,0,0.6);
  --radius: 20px;
  --radius2: 14px;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --display: 'Outfit', var(--sans);
}

/* ---------- Base ---------- */
*{ box-sizing:border-box; }
html, body { height:100%; }

body{
  margin:0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 20% 0%, rgba(76,194,255,.10), transparent 60%),
    radial-gradient(900px 600px at 80% 20%, rgba(53,208,127,.10), transparent 60%),
    var(--bg);
}

a{ color: var(--link); text-decoration:none; }
a:hover{ text-decoration:underline; }

/* ============================================================
   App Layout
   ============================================================ */
.app{
  display:grid;
  grid-template-columns: 270px 1fr;
  min-height:100vh;
}

/* Main needs to be a constrained column so panels can fill height */
.main{
  display:flex;
  flex-direction:column;
  min-height:0;
  padding:22px 24px 26px;
}

/* Some pages use .wrap as an inner container */
.wrap{
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar{
  border-right:1px solid var(--border);
  background: linear-gradient(180deg, rgba(10,16,30,.85), rgba(8,12,22,.92));
  padding:18px 14px;
  position:sticky;
  top:0;
  height:100vh;
}

.brand{
  display:flex;
  gap:12px;
  align-items:center;
  padding:10px 10px 18px;
}

.brand .logo{
  width:38px;height:38px;border-radius:12px;
  background: linear-gradient(135deg, rgba(76,194,255,.25), rgba(53,208,127,.18));
  border:1px solid var(--border);
  display:flex;align-items:center;justify-content:center;
  box-shadow: var(--shadow);
}

.brand h1{ font-size:18px; margin:0; line-height:1.1; }
.brand .sub{ color:var(--muted); font-size:12px; margin-top:2px; }

.nav{
  margin-top:6px;
  display:flex;
  flex-direction:column;
  gap:6px;
  padding:0 6px;
}

.nav a{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:12px;
  color:var(--muted);
  border:1px solid transparent;
  user-select:none;
}

.nav a:hover{
  color:var(--text);
  background: rgba(255,255,255,.04);
  border-color: rgba(255,255,255,.06);
}

.nav a.active{
  color:var(--text);
  background: rgba(76,194,255,.10);
  border-color: rgba(76,194,255,.20);
}

.nav .dot{
  width:8px;height:8px;border-radius:50%;
  background: rgba(255,255,255,.22);
}

.nav a.active .dot{ background: var(--accent); }

/* ============================================================
   Topbar + Pills
   ============================================================ */
.topbar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  padding:8px 4px 18px;
}

.title h1, .title h2{
  margin:0;
  letter-spacing:.2px;
}
.title h1{ font-size:22px; }
.title h2{ font-size:28px; }

.title p, .title .sub{
  margin:6px 0 0;
  color:var(--muted);
  font-size:13px;
  line-height:1.35;
  max-width: 900px;
}

.top-right{
  display:flex;
  align-items:center;
  gap:12px;
  color:var(--muted);
  font-size:13px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--muted);
  font-size:12px;
}

.status-dot{
  width:8px;height:8px;border-radius:50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(53,208,127,.12);
}

/* ============================================================
   Buttons / Inputs
   ============================================================ */
.btn{
  cursor:pointer;
  padding:8px 10px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  color:var(--text);
  font-size:12px;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
  display:inline-flex;
  align-items:center;
  gap:8px;
  user-select:none;
}

.btn:hover{ background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.12); }
.btn:active{ transform: translateY(1px); }

.btn.primary{
  background: rgba(76,194,255,.14);
  border-color: rgba(76,194,255,.28);
}
.btn.primary:hover{ background: rgba(76,194,255,.20); }

.btn.danger{
  background: rgba(239,68,68,.14);
  border-color: rgba(239,68,68,.28);
}
.btn.danger:hover{ background: rgba(239,68,68,.20); }

.btn.small{
  padding:7px 10px;
  border-radius:10px;
  font-size:12px;
}

.btn:disabled{ opacity:.55; cursor:not-allowed; }

label{
  display:block;
  font-size:12px;
  color: var(--muted);
  margin-bottom:6px;
}

input[type="text"], textarea, select{
  width:100%;
  border:1px solid var(--border2);
  background: rgba(0,0,0,.22);
  color: var(--text);
  border-radius: 10px;
  padding:10px 10px;
  font-size:13px;
  outline:none;
  transition: border-color .15s ease, background .15s ease;
}

input[type="text"]:focus, textarea:focus, select:focus{
  border-color: rgba(76,194,255,.55);
  background: rgba(0,0,0,.28);
}

textarea{
  resize: vertical;
  min-height: 130px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.35;
}

.toggle{
  display:inline-flex;
  align-items:center;
  gap:10px;
  padding:10px 10px;
  border:1px solid var(--border2);
  background: rgba(0,0,0,.22);
  border-radius:10px;
  height:40px;
  user-select:none;
}

.toggle input{ width:16px; height:16px; }

.divider{
  height:1px;
  background: var(--border);
  margin: 14px 0;
}

.smallNote{
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.kbd{
  font-family: var(--mono);
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  color: rgba(255,255,255,.86);
}

/* ============================================================
   Cards / Panels
   ============================================================ */
.card,
.panel{
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.card:hover{
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.25);
}

.card::after{
  content:"";
  position:absolute;
  inset:-2px;
  background:
    radial-gradient(420px 220px at 30% 0%, rgba(76,194,255,.10), transparent 60%),
    radial-gradient(360px 240px at 90% 30%, rgba(53,208,127,.08), transparent 60%);
  pointer-events:none;
  opacity:.65;
}

/* Avoid ::after overlay affecting everything: only apply when explicitly used */
.card { position: relative; }
.panel { position: relative; }
.panel::after { content:none; } /* dashboard panels usually don't need the overlay */

.card .hd, .panel-header{
  padding:14px 16px;
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}

.card .hd h2{
  margin:0;
  font-size:14px;
  letter-spacing:.3px;
}

.card .hd .hint{
  margin:6px 0 0;
  color: var(--muted);
  font-size:12px;
  line-height:1.35;
}

.card .bd{
  padding:14px;
}

.rightButtons{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.empty{
  color: var(--muted);
  font-size: 13px;
  padding:10px;
  border: 1px dashed rgba(255,255,255,.14);
  border-radius: 12px;
  background: rgba(0,0,0,.12);
}

/* ============================================================
   Dashboard: Stats cards + lower grid
   ============================================================ */
.cards{
  display:grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap:14px;
  margin: 6px 0 16px;
}

.card .k {
  padding: 16px 16px 14px;
  position:relative;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}

.card .label{ word-wrap: break-word;  color: var(--muted); font-size:13px; }
.card .value{ font-size:30px; font-weight:800; margin-top:6px; }

.card .icon{ flex-shrink: 0; 
  width:44px;height:44px;border-radius:14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  display:flex;align-items:center;justify-content:center;
  font-weight:800;
  color: var(--accent);
}

/* IMPORTANT: full-height desktop behavior */
.lower {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-top: 6px;
  flex: 1 1 auto;
  min-height: 0;
}

/* Panel must be a column and clip children so they don't overflow */
.lower .panel{
  display:flex;
  flex-direction:column;
  min-height: 0;     /* critical */
  overflow: hidden;  /* prevents visual spill */
}

/* Standalone panels (outside .lower) should grow to fit content */
.panel:not(.lower .panel) {
  overflow: visible;
}

/* Scroll containers that fill remaining panel height */
.stores{
  padding: 8px 6px 8px;
  flex: 1;
  min-height: 400px;
  overflow: auto;
}

.activity{
  padding: 10px 12px 14px;
  flex: 1;
  min-height: 400px;
  overflow: auto;
}

/* Store rows */
.store-row{
  display:grid;
  grid-template-columns: 1fr 120px 110px 120px;
  gap:10px;
  align-items:center;
  padding:12px 10px;
  margin: 0 6px 8px;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.04);
  background: rgba(0,0,0,.12);
}

.store-row:hover{
  background: rgba(255,255,255,.04);
  border-color: rgba(255,255,255,.08);
}

.store-name{ font-weight:800; }
.store-sub{ color: var(--muted); font-size:12px; margin-top:4px; }

.stat{
  text-align:right;
  color:var(--muted);
  font-size:12px;
}
.stat b{ display:block; color:var(--text); font-size:13px; margin-bottom:2px; }

/* Dashboard pill badge used in store list */
.badge{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:7px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.02);
  font-size:12px;
  color: var(--muted);
  justify-content:center;
  width: 100%;
}

.badge .s{
  width:15px;height:8px;border-radius:50%;
  background: rgba(255,255,255,.25);
}

.badge.ok{
  color: rgba(53,208,127,.95);
  border-color: rgba(53,208,127,.25);
  background: rgba(53,208,127,.06);
}
.badge.ok .s{ background: var(--ok); box-shadow:0 0 0 3px rgba(53,208,127,.10); }

.badge.bad{
  color: rgba(255,77,77,.95);
  border-color: rgba(255,77,77,.25);
  background: rgba(255,77,77,.06);
}
.badge.bad .s{ background: var(--bad); box-shadow:0 0 0 3px rgba(255,77,77,.10); }

.badge.unk{ color: var(--muted); }

/* Activity rows */
.activity-row{
  display:flex;
  justify-content:space-between;
  gap:16px;
  padding:12px;
  border:1px solid rgba(255,255,255,.08);
  border-radius:14px;
  background: rgba(0,0,0,.12);
  margin: 0 0 10px;
}

.activity-left{
  display:flex;
  gap:12px;
  min-width:0;
}

.thumb{
  width:56px;height:56px;
  object-fit:cover;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
}

.activity-text{ min-width:0; }
.activity-title{
  font-weight:700;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.activity-meta{
  opacity:.75;
  font-size:12px;
}

.activity-actions{
  display:flex;
  gap:8px;
  align-items:center;
  flex-shrink:0;
}
.activity-actions .btn{
  padding:6px 10px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.03);
}
.activity-actions .btn:hover{ background: rgba(255,255,255,.06); }

/* ============================================================
   Notifications: grids, list items, phrases, chips
   ============================================================ */
.grid,
.grid2{
  display:grid;
  grid-template-columns: 420px 1fr;
  gap:14px;
  align-items: stretch;
  grid-auto-rows: 1fr;
}
.grid > *,
.grid2 > *{
  height:100%;
}

@media (max-width: 980px){
  .grid, .grid2{ grid-template-columns: 1fr; }
}

/* Lists on notifications page */
.list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.item{
  border:1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.18);
  border-radius: var(--radius2);
  padding:12px;
  display:grid;
  grid-template-columns: 1fr auto;
  gap:10px;
  align-items:start;
}

.item:hover{ border-color: rgba(255,255,255,.14); }

.meta{
  margin-top:8px;
  color: var(--muted);
  font-size:12px;
  line-height:1.35;
}

/* Make dashboard .badge not blow up inside notifications items */
.item .badge{
  width:auto;
  justify-content:flex-start;
  display:inline-flex;
  margin-right:8px;
}

/* Chips for enabled/mode/id on notifications */
.chips{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:10px;
}

.chip{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size:12px;
  white-space:nowrap;
}

.chip code{
  font-family: var(--mono);
  font-size:11px;
  color: rgba(255,255,255,0.86);
  margin-left:4px;
}

.chip.on{
  border-color: rgba(34,197,94,0.35);
  background: rgba(34,197,94,0.12);
  color: rgba(220,252,231,0.92);
}

.chip.off{
  border-color: rgba(239,68,68,0.35);
  background: rgba(239,68,68,0.12);
  color: rgba(254,226,226,0.92);
}

/* Phrases code block */
.phrases{
  margin-top:10px;
  padding:10px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.18);
  font-family: var(--mono);
  font-size:12px;
  line-height:1.45;
  white-space: pre-wrap;
  color: rgba(255,255,255,0.85);
}

/* Forms layout helpers used in notifications */
.row{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  margin-bottom:10px;
}
.row.one{ grid-template-columns: 1fr; }

/* ============================================================
   Toast
   ============================================================ */
.toast{
  position: fixed;
  bottom: 18px;
  right: 18px;
  min-width: 260px;
  max-width: 420px;
  border: 1px solid var(--border);
  background: rgba(16,24,42,0.96);
  color: var(--text);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 12px;
  display: none;
  z-index: 9999;
}

.toast.show{ display:block; animation: pop .12s ease; }
@keyframes pop{
  from{ transform: translateY(6px); opacity:0; }
  to{ transform: translateY(0); opacity:1; }
}

.toast .t{ font-weight:700; font-size:13px; margin-bottom:4px; }
.toast .m{ color: var(--muted); font-size:12px; line-height:1.35; }

/* ============================================================
   Responsive Mobile Overhaul
   ============================================================ */
.mobile-hamburger {
  display: none; /* strictly hidden on desktop */
}

@media (max-width: 1100px){
  .cards{ grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .lower{ grid-template-columns: 1fr; }
  .app{ grid-template-columns: 1fr; }

  /* Hamburger Toggle */
  .mobile-hamburger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    margin-right: 12px;
    cursor: pointer;
  }

  /* Off-Canvas Sidebar */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  
  .app.menu-open .sidebar {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(0,0,0,0.8);
  }
  
  /* Mobile Background Blur Extinguisher */
  .mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  .app.menu-open .mobile-overlay {
    display: block;
    opacity: 1;
  }

  /* Component Reflows */
  .store-row{
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 14px;
    align-items: flex-start;
  }
  .stat {
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding-bottom: 6px;
  }
  .stat:last-child { border-bottom: none; padding-bottom: 0; }
  .stat b { margin: 0; display: inline; }

  /* Expand all Inputs and Forms cleanly */
  input[type="text"], input[type="number"], select, textarea {
    width: 100% !important;
    max-width: 100% !important;
  }

  .main { padding: 18px 12px 20px; }
  .topbar { padding: 4px 0 16px; }

  /* On mobile, main should NOT be fixed viewport height — let content flow */
  .main {
    height: auto !important;
    overflow-x: hidden;
  }

  /* Prevent width overflow on all direct children */
  .main > * {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Grids go single column on small screens */
  .grid, .grid2 {
    grid-template-columns: 1fr !important;
  }
  .row {
    grid-template-columns: 1fr !important;
  }

  /* ---- Mobile Tab Bar for Lower Panels ---- */
  .mobile-tab-bar {
    display: flex !important;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    gap: 0;
    margin: 8px 0 0;
  }

  .mobile-tab-bar button {
    flex: 1;
    padding: 12px 8px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color .15s, border-color .15s;
  }
  .mobile-tab-bar button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  /* Lower becomes a stacked container, panels toggle visibility */
  .lower {
    display: block !important;
    grid-template-columns: none !important;
  }

  .lower > .panel {
    min-height: calc(100vh - 60px);
    min-height: calc(100dvh - 60px);
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important;
  }

  /* Hidden panel on mobile (toggled by JS) */
  .lower > .panel.mobile-hidden {
    display: none !important;
  }

  /* Panel headers stick to top when scrolling */
  .panel-header,
  .card .hd {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  /* Scroll containers fill available space */
  .stores, .activity {
    max-height: none !important;
    flex: 1;
    min-height: 100vh;
    overflow: auto !important;
  }

  /* Cards get full height on config pages (non-dashboard) */
  .card {
    min-height: auto;
  }

  /* Tables and scroll panels get full-screen height on mobile */
  .scan-table-wrap,
  .chart-panel,
  .card .bd {
    min-height: 80vh;
    overflow-y: auto;
  }

  /* ---- Notifications / list items mobile reflow ---- */
  .item {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .item .rightButtons {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .chips {
    gap: 6px;
  }
  .chip {
    font-size: 11px;
    padding: 3px 8px;
  }
  .phrases {
    font-size: 11px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
  }
  .card .hd {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .card .hd .rightButtons {
    justify-content: flex-start;
  }
}

/* ===== Mobile tab bar hidden on desktop ===== */
.mobile-tab-bar {
  display: none;
}

/* ===== Small phones: stat cards go 1-per-row ===== */
@media (max-width: 600px) {
  .cards { grid-template-columns: 1fr !important; }
}

/* ===== Desktop height chain: dashboard fills viewport and scrolls internally ===== */
/* Only lock to viewport when .lower grid is present (dashboard page) */
html, body { height: 100%; }

.app { min-height: 100vh !important; }

/* Pages WITH .lower (dashboard): lock to viewport for internal scrolling */
.main:has(.lower) {
  height: 100vh !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
}

/* Pages WITHOUT .lower: flow naturally so all content is visible */
.main:not(:has(.lower)) {
  height: auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow-y: auto;
}

.main > .topbar,
.main > .cards {
  flex: 0 0 auto !important;
}

.main > .lower {
  flex: 1 1 auto !important;
  min-height: 0 !important;
}

.lower {
  min-height: 0 !important;
}

.lower > .panel {
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

.lower > .panel > .stores,
.lower > .panel > .activity {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: auto !important;
}

@media (min-width: 1101px) {
  .stores, .activity { max-height: none !important; }
}

/* ===== Global overflow prevention ===== */
*, *::before, *::after { box-sizing: border-box; }
body { overflow-x: hidden; }

/* Custom map markers */
.custom-map-icon {
  background: white;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.5);
  overflow: hidden;
}
.custom-map-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}
