:root {
  --bg-main: #f5f5f0;
  --bg-card: #ffffff;
  --bg-panel: #fafaf7;
  --bg-dark: #1a1a1a;
  --border-default: #e8e6df;
  --border-hover: #ccc;
  --text-primary: #1a1a1a;
  --text-secondary: #888;
  --text-tertiary: #aaa;
  --text-on-dark: #f5f5f0;
  --success: #22c55e;
  --info: #3b82f6;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  --header-h: 56px;
  --nav-h: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

.mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
}

/* ---------- TOP HEADER (dark bar) ---------- */
.app-header {
  height: var(--header-h);
  background: var(--bg-dark);
  color: var(--text-on-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 82px;
  height: 22px;
  border-radius: 6px;
  background: var(--bg-card);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-text {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.brand-text .sub {
  color: #888;
  font-weight: 400;
  margin-left: 6px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.live-stamp {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #bbb;
}

.live-stamp .live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 1.6s ease-in-out infinite;
}

.live-stamp.offline .live-dot {
  background: var(--danger);
  animation: none;
}

.live-stamp .ts {
  font-family: var(--font-mono);
  color: #f5f5f0;
}

/* ---------- ALARM BELL ---------- */
.bell-wrap {
  position: relative;
}
.bell-btn {
  appearance: none;
  position: relative;
  width: 34px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f5f0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    color 0.15s;
}
.bell-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}
.bell-btn svg {
  width: 16px;
  height: 16px;
}
.bell-btn.warn {
  background: rgba(245, 158, 11, 0.24);
  color: #fcd34d;
}
.bell-btn.crit {
  background: rgba(239, 68, 68, 0.28);
  color: #fecaca;
  animation: bell-pulse 1.2s ease-in-out infinite;
}
@keyframes bell-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.42);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
  }
}
.bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border: 1.5px solid var(--bg-dark);
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  line-height: 13px;
}
.bell-badge.warn {
  background: var(--warning);
}
.bell-badge.hidden {
  display: none;
}
.bell-panel {
  display: none;
  position: absolute;
  z-index: 30;
  top: 38px;
  right: 0;
  width: min(340px, calc(100vw - 24px));
  max-height: 420px;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
}
.bell-panel.open {
  display: flex;
  flex-direction: column;
}
.bell-panel-head,
.bell-foot {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-default);
}
.bell-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bell-panel-head .t {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.bell-panel-head .c {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
}
.bell-panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.bell-item {
  display: flex;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--bg-panel);
}
.bell-item:last-child {
  border-bottom: 0;
}
.bell-item .sev {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-top: 5px;
  border-radius: 50%;
}
.bell-item .sev.crit {
  background: var(--danger);
}
.bell-item .sev.warn {
  background: var(--warning);
}
.bell-item .sev.info {
  background: var(--info);
}
.bell-item .body {
  min-width: 0;
  flex: 1;
}
.bell-item .src {
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.35px;
  text-transform: uppercase;
}
.bell-item .msg {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
}
.bell-item .when {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 10px;
}
.bell-empty {
  padding: 25px;
  color: var(--text-tertiary);
  font-size: 12px;
  text-align: center;
}
.bell-foot {
  border-top: 1px solid var(--border-default);
  border-bottom: 0;
  text-align: center;
}
.bell-foot a {
  color: var(--info);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.bell-foot a:hover {
  text-decoration: underline;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f5f0;
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.logout-btn svg {
  width: 14px;
  height: 14px;
}

/* ---------- SITE BAR ---------- */
.site-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-default);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.back-link {
  color: #888;
  text-decoration: none;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.2s;
}

.back-link:hover {
  color: #3b82f6;
}

.sep {
  color: #ccc;
  font-size: 12px;
}

.site-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--info);
  font-size: 11px;
  font-weight: 500;
}

.site-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.site-loc {
  font-size: 12px;
  color: var(--text-secondary);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
  font-size: 11px;
  font-weight: 500;
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.status-pill.offline {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.status-pill.offline .dot {
  background: var(--danger);
}

.site-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.client-logos {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.client-logos img {
  height: 28px;
  width: auto;
  display: block;
  object-fit: contain;
  background: #fff;
  padding: 2px 4px;
  border-radius: 6px;
  border: 1px solid var(--border-default);
}

@media (max-width: 600px) {
  .client-logos img {
    height: 22px;
    padding: 1px 3px;
  }
}

@media (max-width: 420px) {
  .client-logos img {
    height: 18px;
  }
}

/* ---------- NAV TABS ---------- */
.nav-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-default);
  height: var(--nav-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.nav-bar::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.12s,
    color 0.12s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover {
  background: var(--bg-panel);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--bg-dark);
  color: #fff;
}

.nav-btn .ico {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-btn .ico svg {
  width: 100%;
  height: 100%;
}

/* ---------- MAIN IFRAME ---------- */
.app-main {
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

.app-main > .site-bar {
  flex: 0 0 auto;
}

.app-main > .nav-bar {
  flex: 0 0 auto;
}

.frame-wrap {
  flex: 1 1 auto;
  background: var(--bg-main);
  overflow: hidden;
  min-height: 0;
}

.frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--bg-main);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1024px) {
  .nav-btn {
    padding: 7px 12px;
  }
}

@media (max-width: 768px) {
  .brand-text .sub {
    display: none;
  }

  .site-bar {
    padding: 8px 12px;
  }

  .nav-bar {
    padding: 0 12px;
    gap: 2px;
  }

  .nav-btn {
    padding: 6px 11px;
    font-size: 12px;
  }

  .logout-btn {
    padding: 5px 10px;
    font-size: 11px;
  }
}

@media (max-width: 600px) {
  :root {
    --header-h: 44px;
    --nav-h: 40px;
  }

  .app-header {
    padding: 0 10px;
  }

  .brand-logo {
    width: 66px;
    height: 18px;
  }

  .brand-text {
    font-size: 12px;
  }

  .live-stamp .ts {
    font-size: 10px;
  }

  .live-stamp .label {
    display: none;
  }

  .site-loc {
    display: none;
  }

  .site-bar {
    padding: 7px 10px;
    gap: 6px;
  }

  .site-name {
    font-size: 13px;
  }

  .type-badge,
  .status-pill {
    font-size: 10px;
    padding: 2px 7px;
  }

  .nav-bar {
    padding: 0 10px;
    gap: 2px;
  }

  .nav-btn {
    padding: 5px 10px;
    font-size: 12px;
    gap: 5px;
  }

  .nav-btn .ico {
    width: 12px;
    height: 12px;
  }

  .logout-btn {
    padding: 5px 9px;
  }

  .logout-btn svg {
    width: 13px;
    height: 13px;
  }
}

@media (max-width: 420px) {
  .brand-text {
    font-size: 11px;
  }

  .live-stamp {
    gap: 4px;
  }

  .live-stamp .ts {
    font-size: 9px;
  }

  .logout-btn {
    padding: 6px 8px;
    font-size: 0;
  }

  .logout-btn svg {
    width: 14px;
    height: 14px;
  }

  .nav-btn {
    padding: 5px 9px;
    font-size: 11px;
  }
}


/* Mobile Header Fixes */
.brand-title {
  font-size: clamp(12px, 3vw, 1.1rem) !important;
  white-space: nowrap !important;
}
.header-right {
  gap: clamp(6px, 2vw, 16px) !important;
}
.app-header img[alt="Leonics Logo"] {
  height: clamp(20px, 4vw, 28px) !important;
}
.app-header img[alt="Digital Logo"] {
  height: clamp(14px, 3vw, 22px) !important;
}
@media (max-width: 850px) {
  .desktop-only { display: none !important; }
}
@media (max-width: 768px) {
  .header-right .ts { display: none !important; }
  body, html { overflow-x: hidden !important; width: 100%; }
}
@media (max-width: 600px) {
  :root { --header-h: 56px !important; }
}

