/* ═══════════════════════════════════════════
   CADChain — Design System & Styles
   ═══════════════════════════════════════════ */

/* ─── Tokens ─── */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(6, 214, 160, 0.4);

  --text-primary: #f0f4f8;
  --text-secondary: rgba(240, 244, 248, 0.55);
  --text-muted: rgba(240, 244, 248, 0.3);

  --accent: #06d6a0;
  --accent-dim: rgba(6, 214, 160, 0.15);
  --blue: #118ab2;
  --pink: #ef476f;
  --yellow: #ffd166;
  --purple: #8338ec;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-glow: 0 0 20px rgba(6, 214, 160, 0.08);

  --topbar-h: 52px;
  --toolbar-w: 62px;
  --panel-w: 320px;

  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset ─── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ─── Background Effects ─── */
.bg-effects {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.12;
}

.orb1 {
  width: 600px;
  height: 600px;
  background: var(--accent);
  top: -200px;
  left: -100px;
  animation: orbFloat 20s ease-in-out infinite;
}

.orb2 {
  width: 500px;
  height: 500px;
  background: var(--purple);
  bottom: -200px;
  right: -100px;
  animation: orbFloat 25s ease-in-out infinite reverse;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(60px, 40px); }
}

/* ─── App Layout ─── */
.app-layout {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ─── Top Bar ─── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-name {
  font-weight: 700;
  font-size: 16px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.3px;
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.stats-row {
  display: flex;
  gap: 16px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat-val {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  font-family: var(--font-mono);
}

.stat-lbl {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.shape-count {
  font-size: 13px;
  color: var(--text-secondary);
}

.shape-count strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.save-chain-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #000;
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
}

.save-chain-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(6, 214, 160, 0.3);
}

.save-chain-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ─── Main Area ─── */
.main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ─── Left Toolbar ─── */
.toolbar {
  width: var(--toolbar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.tool-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
}

.tool-section-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
  width: 100%;
  text-align: center;
}

.tool-btn {
  width: 42px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
  border-color: var(--border);
}

.tool-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-active);
}

.tool-btn.danger:hover {
  background: rgba(239, 71, 111, 0.15);
  color: var(--pink);
  border-color: rgba(239, 71, 111, 0.3);
}

.icon-btn {
  width: 42px;
  height: 34px;
}

.tool-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 10px;
}

/* Color Swatches */
.color-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 100%;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--c);
  cursor: pointer;
  transition: all 0.15s;
  max-width: 20px;
  justify-self: center;
}

.color-swatch:hover {
  transform: scale(1.2);
}

.color-swatch.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 8px var(--c);
}

/* Line Width */
.line-range {
  width: 100%;
  -webkit-appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}

.line-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.line-width-val {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Canvas Container ─── */
.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.canvas-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.canvas-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 14px;
  border-radius: 20px;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

/* ─── Right Panel ─── */
.right-panel {
  width: var(--panel-w);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
}

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

.panel-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  display: none;
  flex-direction: column;
}

.panel-content.active {
  display: flex;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 13px;
  font-weight: 600;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: livePulse 2s infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(6, 214, 160, 0.5); }
  50% { opacity: 0.7; box-shadow: 0 0 0 5px rgba(6, 214, 160, 0); }
}

/* ─── Blockchain View ─── */
.blockchain-view {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block-card {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  animation: blockSlideIn 0.35s ease-out both;
  transition: border-color 0.2s;
}

.block-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.block-card.genesis {
  border-color: rgba(6, 214, 160, 0.15);
  background: rgba(6, 214, 160, 0.03);
}

@keyframes blockSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.block-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.block-num {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
}

.block-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
}

.genesis-badge {
  background: var(--accent-dim);
  color: var(--accent);
}

.cad-badge {
  background: rgba(17, 138, 178, 0.15);
  color: var(--blue);
}

.block-time {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
}

.block-name {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-thumb {
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0d1117;
}

.block-thumb img {
  width: 100%;
  height: auto;
  display: block;
}

.block-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.block-genesis-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-style: italic;
}

.load-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 10px;
}

.load-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-active);
}

.block-hashes {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hash-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}

.hash-line span {
  color: var(--text-muted);
  min-width: 24px;
  flex-shrink: 0;
}

.hash-line code {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Verify Panel ─── */
.verify-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 14px;
  padding: 10px;
  border: 1px solid var(--border-active);
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
}

.verify-btn:hover {
  background: rgba(6, 214, 160, 0.2);
}

#validationResult {
  padding: 0 14px;
}

.validation-result {
  text-align: center;
  padding: 16px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.validation-result.valid {
  background: rgba(6, 214, 160, 0.08);
  border: 1px solid rgba(6, 214, 160, 0.2);
}

.validation-result.invalid {
  background: rgba(239, 71, 111, 0.08);
  border: 1px solid rgba(239, 71, 111, 0.2);
}

.validation-icon {
  font-size: 28px;
  margin-bottom: 6px;
}

.validation-text {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.validation-detail {
  font-size: 11px;
  color: var(--text-secondary);
}

.validation-blocks {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.v-block {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-mono);
}

.v-block.valid { background: rgba(6, 214, 160, 0.05); }
.v-block.invalid { background: rgba(239, 71, 111, 0.08); }

.panel-footer {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.reset-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  border: 1px solid rgba(239, 71, 111, 0.2);
  border-radius: var(--radius-sm);
  background: rgba(239, 71, 111, 0.06);
  color: var(--pink);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s;
}

.reset-btn:hover {
  background: rgba(239, 71, 111, 0.15);
}

.validating {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 12px 0;
}

/* ─── Notifications ─── */
.notifications {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notification {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 13px;
  backdrop-filter: blur(12px);
  transform: translateX(120%);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.notification.show {
  transform: translateX(0);
  opacity: 1;
}

.notification.success { border-color: rgba(6, 214, 160, 0.3); }
.notification.error { border-color: rgba(239, 71, 111, 0.3); }
.notification.warning { border-color: rgba(255, 209, 102, 0.3); }

/* ─── Spinner ─── */
.spinner-small {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .right-panel {
    width: 260px;
  }
  .stats-row {
    display: none;
  }
}

@media (max-width: 700px) {
  .right-panel {
    display: none;
  }
}
