:root {
  --accent: #e50914;
  --accent-hi: #ff3b47;
  --accent-soft: rgba(229, 9, 20, 0.18);
  --accent-grad: linear-gradient(135deg, #e50914 0%, #b20710 100%);
  --bg: #070d18;
  --panel-bg: rgba(16, 23, 38, 0.88);
  --panel-border: rgba(255, 255, 255, 0.1);
  --input-bg: #090e17;
  --input-border: #233044;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --radius-lg: 20px;
  --radius-md: 12px;
  --shadow-panel: 0 24px 48px rgba(0, 0, 0, 0.5);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-main);
  background: var(--bg);
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100dvh; background: var(--bg); }
body {
  background: radial-gradient(circle at 80% -20%, rgba(229, 9, 20, 0.12) 0%, transparent 45%),
              radial-gradient(circle at 15% 110%, rgba(36, 215, 238, 0.06) 0%, transparent 45%),
              #070d18;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); touch-action: manipulation; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 3px; }
a { color: #5fdbed; text-decoration: none; transition: color 0.15s; }
a:hover { color: #9feaff; }

/* Intro Overlay */
.web-intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(5, 9, 17, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.4s ease, transform 0.4s ease;
  overflow: hidden;
}
.web-intro-overlay.out {
  opacity: 0;
  transform: scale(1.03);
  pointer-events: none;
}

/* Compact Intro Card Container */
.intro-card {
  position: relative;
  width: min(640px, 90vw);
  aspect-ratio: 16 / 9;
  background: #090e17;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(229, 9, 20, 0.15);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Loader Box */
.intro-loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 5;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.intro-loader-box.fade-out {
  opacity: 0;
  transform: scale(0.94);
  pointer-events: none;
}
.intro-logo-glow {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: contain;
  animation: introPulse 2s ease-in-out infinite;
  box-shadow: 0 0 25px rgba(229, 9, 20, 0.4);
}
.intro-spinner-ring {
  position: relative;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.intro-spinner-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent-hi);
  border-right-color: var(--accent);
  animation: introSpin 0.85s linear infinite;
  box-shadow: 0 0 12px rgba(229, 9, 20, 0.5);
}
.intro-loader-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  animation: introPulse 1.8s ease-in-out infinite;
}

@keyframes introSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes introPulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

.intro-media-box {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  opacity: 0;
  transition: opacity 0.35s ease;
}
.intro-media-box.active {
  opacity: 1;
}
.intro-media-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 20px;
}
.intro-skip-btn {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  background: rgba(16, 23, 38, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 99px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.6);
}
.intro-skip-btn:hover {
  background: var(--accent);
  border-color: var(--accent-hi);
}

/* Shell & Corporate Header */
.shell { max-width: 1240px; margin: auto; }
.header {
  height: 84px;
  background: rgba(12, 19, 32, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--panel-border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { width: 52px; height: 52px; border-radius: 14px; object-fit: contain; }
.brand-title-wrap { display: flex; flex-direction: column; }
.brand-name { font-size: 24px; font-weight: 900; letter-spacing: -0.5px; color: #fff; }
.brand-name span { color: var(--accent-hi); }
.brand-subtitle { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.divider { width: 1px; height: 26px; background: rgba(255,255,255,0.12); }
.header strong { font-size: 18px; font-weight: 700; color: var(--text-main); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.header-url { color: var(--text-muted); font-size: 14px; font-weight: 500; }

/* Language Switcher & Intro Trigger */
.lang-switcher {
  display: inline-flex;
  align-items: center;
  background: #090e17;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.lang-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 7px;
  min-height: 32px;
}
.lang-btn.active {
  background: rgba(229, 9, 20, 0.2);
  color: #ff5260;
  border: 1px solid rgba(229, 9, 20, 0.4);
}
.lang-btn:hover:not(.active) { color: #fff; }
.intro-replay-btn {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  min-height: 38px;
}
.intro-replay-btn:hover { color: #fff; border-color: rgba(255,255,255,0.25); background: rgba(255,255,255,0.05); }

/* Main Layout & Panels */
main { padding: 28px 24px; }
.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 30px;
  box-shadow: var(--shadow-panel);
}
h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.8px; margin: 0 0 12px; }
h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; margin: 0 0 10px; }
h3 { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
p { color: var(--text-muted); line-height: 1.6; margin: 0 0 20px; }

/* Buttons & Inputs */
.primary {
  background: var(--accent-grad);
  color: #fff;
  border: 0;
  border-radius: var(--radius-md);
  font-weight: 700;
  padding: 14px 26px;
  min-height: 48px;
  box-shadow: 0 8px 20px rgba(229, 9, 20, 0.35);
}
.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 25px rgba(229, 9, 20, 0.48);
}
.secondary {
  background: #141d2e;
  border: 1px solid var(--input-border);
  color: var(--text-main);
  border-radius: var(--radius-md);
  font-weight: 600;
  min-height: 46px;
  padding: 11px 18px;
}
.secondary:hover:not(:disabled) {
  background: #1b273e;
  border-color: rgba(255, 255, 255, 0.2);
}
input {
  border-radius: var(--radius-md);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: #edf5ff;
  min-height: 48px;
  padding: 0 16px;
  font-size: 15px;
  width: 100%;
}
input:focus {
  border-color: var(--accent-hi);
  box-shadow: 0 0 12px rgba(229, 9, 20, 0.25);
}

/* Management Nav Bar */
.management-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  background: rgba(12, 19, 32, 0.8);
  backdrop-filter: blur(12px);
  padding: 6px;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
}
.management-nav button {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  border-radius: 11px;
  padding: 12px 24px;
  font-weight: 700;
  min-height: 46px;
  font-size: 15px;
}
.management-nav button[aria-pressed=true] {
  background: rgba(229, 9, 20, 0.18);
  color: #ff5260;
  border: 1px solid rgba(229, 9, 20, 0.4);
}
.management-nav #connection-state {
  margin-left: auto;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.management-nav #connection-state:before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #778497;
  border-radius: 50%;
}
.management-nav #connection-state.online:before {
  background: #28d6a0;
  box-shadow: 0 0 10px #28d6a0;
}

/* Grid & Form Cards */
.pair-grid { display: grid; grid-template-columns: 1fr 1.35fr; gap: 24px; }
.pair-grid .panel { min-width: 0; }
.pair-grid label, .form-card label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
  color: #dce4f4;
  font-size: 14px;
  font-weight: 700;
}

/* TV Demo Preview */
.tv-demo { width: 390px; margin: 12px auto 0; text-align: center; }
.tv-screen {
  border: 7px solid #28374e;
  border-bottom: 11px solid #28374e;
  background: linear-gradient(125deg, #111a32, #080e1c);
  height: 185px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 18px;
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
}
.tv-screen > span { align-self: flex-start; font-size: 18px; font-weight: 900; }
.qr-demo { background: #fff; color: #0b1020; width: 82px; height: 82px; display: grid; place-items: center; font-size: 55px; border-radius: 8px; }
.tv-stand { width: 140px; height: 14px; border-bottom: 8px solid #28374e; clip-path: polygon(35% 0, 65% 0, 75% 100%, 25% 100%); margin: auto; }

/* Editor Grid */
.editor-grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 24px; }
.form-card, .list-card { background: #0b121d; border: 1px solid var(--panel-border); border-radius: 16px; padding: 22px; }
.type-tabs { display: flex; background: #060b13; border: 1px solid var(--input-border); border-radius: 12px; padding: 4px; gap: 4px; margin-top: 18px; }
.type-tabs button { flex: 1; border-radius: 8px; color: var(--text-muted); padding: 10px 16px; border: 0; background: transparent; font-weight: 600; }
.type-tabs button.selected { background: rgba(229, 9, 20, 0.18); color: #ff5260; border: 1px solid rgba(229, 9, 20, 0.4); font-weight: 700; }
.source-list { min-height: 140px; }
.source-row { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; padding: 16px 8px; border-bottom: 1px solid var(--panel-border); }
.source-row strong { font-size: 16px; }
.source-row small { color: var(--text-muted); margin-top: 4px; display: block; }

/* Category Section */
#category-section { margin-top: 0; }
.category-search { display: block; margin: 20px 0 16px; }
.category-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.category-summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 18px 0 14px; font-size: 14px; }
.category-summary p { margin: 0; }
#category-dirty { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.is-dirty #category-dirty { color: #f4c983; }

#category-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 24px; }
.category-option {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 16px 18px;
  background: #121a29;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
}
.category-option:hover { border-color: rgba(255,255,255,0.2); }
.category-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; }
.visibility-label { font-size: 13px; font-weight: 700; color: #48dab1; }
.category-option.hidden-category { background: #0c121e; border-color: rgba(255,255,255,0.05); color: #78879e; }
.hidden-category .visibility-label { color: #78879e; }
.category-option input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; z-index: 1; cursor: pointer; margin: 0; }
.switch-track { width: 46px; height: 26px; flex: none; background: #28d6a0; border-radius: 20px; position: relative; }
.switch-track:after { content: ""; position: absolute; top: 4px; left: 24px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: left 0.15s; }
.hidden-category .switch-track { background: #2a374c; }
.hidden-category .switch-track:after { left: 4px; }

/* Sticky Savebar */
.category-savebar {
  position: sticky;
  bottom: 0;
  z-index: 50;
  background: rgba(12, 19, 32, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px max(18px, env(safe-area-inset-bottom));
  margin: 24px -30px -30px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Footer */
footer { text-align: center; color: var(--text-muted); font-size: 13px; padding: 32px 0 20px; }
footer a { color: var(--text-muted); font-weight: 600; }
footer a:hover { color: #fff; }

/* Responsive Adjustments */
@media (max-width: 850px) {
  .header { padding: 0 16px; height: auto; min-height: 72px; flex-wrap: wrap; gap: 10px; }
  .header-url { display: none; }
  main { padding: 16px 12px; }
  .panel { padding: 22px 18px; }
  .pair-grid, .editor-grid { grid-template-columns: 1fr; }
  #category-list { grid-template-columns: 1fr; }
  .category-savebar { margin: 20px -18px -22px; padding: 16px 18px; flex-direction: column; align-items: stretch; }
  .category-savebar button { width: 100%; }
}
