:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --text: #16181d;
  --card: #f5f7fb;
  --line: #dbe2ec;
  --primary: #0d87d8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --text: #f3f7ff;
    --card: #0e1218;
    --line: #263243;
    --primary: #42b4ef;
  }
}

/* Explicit Theme Overrides - these MUST override the media query */
html[data-theme="light"],
:root[data-theme="light"] {
  --bg: #ffffff !important;
  --text: #16181d !important;
  --card: #f5f7fb !important;
  --line: #dbe2ec !important;
  --primary: #0d87d8 !important;
  color-scheme: light;
}

html[data-theme="dark"],
:root[data-theme="dark"] {
  --bg: #000000 !important;
  --text: #f3f7ff !important;
  --card: #0e1218 !important;
  --line: #263243 !important;
  --primary: #42b4ef !important;
  color-scheme: dark;
}


* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  gap: 12px;
  flex-wrap: wrap;
}

.logo-wrap {
  display: inline-block;
  width: min(260px, 60vw);
  /* Reduced from 380px/72vw per user request */
}

.logo {
  width: 100%;
  display: none;
}

.logo.is-visible {
  display: block;
}

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

.fixed-controls {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 9999;
  background: var(--card);
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.theme-btn-group {
  display: flex;
  background: rgba(0, 0, 0, 0.05);
  padding: 4px;
  border-radius: 10px;
  gap: 2px;
}

[data-theme="dark"] .theme-btn-group {
  background: rgba(255, 255, 255, 0.05);
}

.theme-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s ease;
  padding: 0;
}

.theme-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .theme-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.theme-btn.is-active {
  opacity: 1;
  background: var(--bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  color: var(--primary);
}

.theme-btn svg {
  width: 18px;
  height: 18px;
}

.lang-select {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}

.hero {
  padding: 44px 0 30px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.hero h1 {
  margin: 0 0 16px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.hero p {
  margin: 0;
  max-width: 760px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

.hero-visual {
  width: 100%;
  min-height: 220px;
  animation: heroFloat 6s ease-in-out infinite;
  will-change: transform;
}

.hero-visual .spark-svg {
  width: 100%;
  height: 100%;
  min-height: 180px;
}

.hero-visual .spark-svg polyline {
  stroke-dasharray: 760;
  stroke-dashoffset: 0;
  animation: sparkSweep 7s ease-in-out infinite;
}

.hero-visual .spark-svg g[fill] circle {
  transform-origin: center;
  animation: sparkPulse 2.6s ease-in-out infinite;
}

.hero-visual .spark-svg g[fill] circle:nth-child(2) {
  animation-delay: 0.35s;
}

.hero-visual .spark-svg g[fill] circle:nth-child(3) {
  animation-delay: 0.7s;
}

.btn {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: white;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
}

.btn.ghost {
  color: var(--text);
  background: transparent;
}

/* Button Loading State */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1em;
  height: 1em;
  margin-top: -0.5em;
  margin-left: -0.5em;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btnSpinner 0.7s linear infinite;
}

.btn.ghost.is-loading::after {
  border-color: var(--line);
  border-top-color: var(--text);
}

.btn.danger.is-loading::after,
.btn.ghost.danger.is-loading::after {
  border-color: rgba(196, 59, 59, 0.4);
  border-top-color: #c43b3b;
}

@keyframes btnSpinner {
  to {
    transform: rotate(360deg);
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 16px;
}

pre {
  overflow: auto;
  background: #0b1118;
  color: #ecf4ff;
  border-radius: 12px;
  padding: 12px;
}

.page-home pre {
  background: #000000;
}

pre.code-enhanced {
  position: relative;
  padding: 14px 14px 14px;
}

pre.code-enhanced code {
  display: block;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92rem;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(145, 170, 210, 0.45);
  background: rgba(11, 17, 24, 0.9);
  color: #d9eaff;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.code-copy-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.code-copy-btn:hover {
  border-color: rgba(66, 180, 239, 0.9);
  color: #42b4ef;
}

.code-copy-btn.is-copied {
  color: #38f29f;
  border-color: rgba(56, 242, 159, 0.9);
}

.tok-command {
  color: #42b4ef;
  font-weight: 700;
}

.tok-method {
  color: #ffb86c;
  font-weight: 700;
}

.tok-flag {
  color: #8be9fd;
}

.tok-string {
  color: #a5f3a0;
}

.tok-key {
  color: #8be9fd;
}

.tok-number {
  color: #f6d365;
}

.tok-bool {
  color: #c4b5fd;
}

.tok-punct {
  color: #8aa0bf;
}

.tok-preprocessor {
  color: #ff79c6;
}

.tok-keyword {
  color: #ff79c6;
  font-weight: 600;
}

.tok-type {
  color: #8be9fd;
}

.tok-comment {
  color: #6272a4;
  font-style: italic;
}

.footer {
  padding: 24px 0 30px;
  text-align: right;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html[dir="rtl"] .hero-actions,
html[dir="rtl"] .header-controls {
  flex-direction: row-reverse;
}

.panel {
  padding: 12px 0 32px;
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.auth-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-tabs {
  display: flex;
  gap: 8px;
}

.auth-tabs .tab {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.auth-tabs .tab.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.auth-art {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-graph {
  width: 100%;
  height: 100%;
  min-height: 180px;
  animation: heroFloat 6s ease-in-out infinite;
}

.auth-graph polyline {
  stroke-dasharray: 760;
  stroke-dashoffset: 0;
  animation: sparkSweep 7s ease-in-out infinite;
}

.auth-graph g[fill] circle {
  transform-origin: center;
  animation: sparkPulse 2.6s ease-in-out infinite;
}

.auth-graph g[fill] circle:nth-child(2) {
  animation-delay: 0.35s;
}

.auth-graph g[fill] circle:nth-child(3) {
  animation-delay: 0.7s;
}

.welcome-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, rgba(66, 180, 239, 0.12) 0%, rgba(56, 242, 159, 0.08) 100%);
  border: 1px solid rgba(66, 180, 239, 0.25);
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
}

.welcome-banner .welcome-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-banner .welcome-text {
  flex: 1;
}

@media (prefers-color-scheme: dark) {
  .welcome-banner {
    background: linear-gradient(135deg, rgba(66, 180, 239, 0.18) 0%, rgba(56, 242, 159, 0.1) 100%);
    border-color: rgba(66, 180, 239, 0.35);
  }
}

.main-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.main-tabs .tab {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.main-tabs .tab.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

#projectsCard,
#tokensCard,
#dataCard {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* Panel List (Projects) */
.panel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.project-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-card);
  transition: border-color 0.2s ease;
}

.project-row:hover {
  border-color: var(--primary);
}

.project-row.is-selected {
  border-color: var(--primary);
  background: rgba(13, 135, 216, 0.05);
  /* Highlight color */
}

[data-theme="dark"] .project-row.is-selected {
  background: rgba(66, 180, 239, 0.1);
}

@media (prefers-color-scheme: dark) {
  .project-row.is-selected {
    background: rgba(66, 180, 239, 0.1);
  }
}

.project-name-display {
  flex: 1;
  font-weight: 600;
  font-size: 1.1rem;
}

.project-selected-label {
  font-size: 0.85em;
  font-weight: 500;
  color: #ffc107;
}

.project-row:not(.is-selected) .project-selected-label {
  display: none;
}

.project-row-actions {
  display: flex;
  gap: 8px;
}

@media (prefers-color-scheme: dark) {
  .project-row {
    background: rgba(255, 255, 255, 0.03);
  }
}

.meta-box-wrap {
  margin-top: 12px;
}

.meta-box {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-top: 8px;
}

@media (prefers-color-scheme: dark) {
  .meta-box {
    background: rgba(255, 255, 255, 0.04);
  }
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.meta-row:last-child {
  border-bottom: none;
}

.meta-label {
  font-size: 0.85rem;
  color: var(--text);
  opacity: 0.8;
  margin-bottom: 2px;
}

.meta-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.meta-link.mono,
.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  word-break: break-all;
}

.json-details {
  font-size: 0.9rem;
}

.device-code-collapse summary {
  user-select: none;
}

.device-code-collapse .collapse-icon {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 0.7em;
}

.device-code-collapse[open] .collapse-icon {
  transform: rotate(90deg);
}

.json-pre {
  margin: 4px 0 0;
  padding: 8px;
  background: #0b1118;
  color: #ecf4ff;
  border-radius: 6px;
  overflow: auto;
  max-height: 200px;
}

#tokensList {
  margin-top: 12px;
}

.token-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.token-row:last-child {
  border-bottom: none;
}

.token-left {
  flex: 1;
  min-width: 0;
}

.token-left strong {
  display: block;
  margin-bottom: 4px;
}

@media (max-width: 700px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {

  .auth-graph,
  .auth-graph polyline,
  .auth-graph g[fill] circle {
    animation: none !important;
  }
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.panel-form,
.panel-form-inline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-form-inline {
  flex-direction: row;
  align-items: end;
  flex-wrap: wrap;
}

.panel-form label,
.panel-form-inline label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.panel-form input,
.panel-form-inline input {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 10px;
}

/* Panel layout */
.panel {
  flex: 1;
  padding: 12px 0;
  /* Align perfectly with header by removing side padding */
}

/* Master-Detail Workspace Styling */
#projectsListSection {
  margin-bottom: 32px;
}

.panel-section-header {
  margin-bottom: 16px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
}

.panel-section-header h2 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 600;
}

.workspace-card {
  background: var(--bg);
  border: 1px solid var(--btn-brd);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  margin-top: 16px;
  animation: slideInWorkspace 0.3s ease forwards;
}

@keyframes slideInWorkspace {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.02);
  border-bottom: 1px solid var(--line);
}

.workspace-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary);
}

.workspace-local-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
  background: var(--bg-card);
  overflow-x: auto;
}

.workspace-local-tabs .tab {
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.workspace-local-tabs .tab:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
}

.workspace-local-tabs .tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.workspace-content {
  padding: 20px;
}

.grow {
  flex: 1;
}

.panel-list:empty {
  min-height: 0;
}

.msg {
  min-height: 20px;
  font-size: 0.95rem;
}

.msg.is-ok {
  color: #1a8a46;
}

.msg.is-err {
  color: #c43b3b;
}

.token-box {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.token-box code {
  display: block;
  max-width: 100%;
  overflow: auto;
  background: #0b1118;
  color: #ecf4ff;
  border-radius: 8px;
  padding: 8px 10px;
}

.table-wrap {
  overflow: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.table th,
.table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  font-size: 0.92rem;
}

.btn-project-name {
  width: 100%;
  text-align: left;
}

.btn-danger {
  border-color: #c43b3b;
  color: #c43b3b;
}

@media (max-width: 900px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }
}

@keyframes heroFloat {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

@keyframes sparkSweep {

  0%,
  100% {
    stroke-dashoffset: 0;
    opacity: 0.9;
  }

  50% {
    stroke-dashoffset: -64;
    opacity: 1;
  }
}

@keyframes sparkPulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 0.75;
  }

  50% {
    transform: scale(1.22);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {

  .hero-visual,
  .hero-visual .spark-svg polyline,
  .hero-visual .spark-svg g[fill] circle {
    animation: none !important;
  }
}

/* Empty State / Null Page Design */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 20px;
  margin: 20px 0;
}

.empty-state-icon {
  width: 120px;
  height: 120px;
  margin-bottom: 24px;
  opacity: 0.6;
}

.empty-state-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

.empty-state-desc {
  font-size: 1rem;
  color: var(--text);
  max-width: 400px;
  opacity: 0.7;
  line-height: 1.6;
}