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

:root {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-elevated: #1a1a26;
  --text: #e0e0e8;
  --text-muted: #8888a0;
  --accent: #00c8ff;
  --accent-glow: rgba(0, 200, 255, 0.15);
  --accent-glow-strong: rgba(0, 200, 255, 0.25);
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(0, 200, 255, 0.2);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-width: 280px;
  --header-height: 60px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle background texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(0, 200, 255, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 200, 255, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============ Sidebar ============ */
.sidebar {
  position: fixed;
  top: 0;
  left: calc(-1 * var(--sidebar-width));
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: left var(--transition);
}

.sidebar.open {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-wordmark {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sidebar-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-menu {
  list-style: none;
  padding: 0.75rem 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  margin: 2px 0;
}

.sidebar-menu li a svg {
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.sidebar-menu li a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.sidebar-menu li a:hover svg {
  opacity: 0.9;
}

.sidebar-menu li a.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.sidebar-menu li a.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer p {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ============ Overlay ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============ App Layout ============ */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ============ App Header ============ */
.app-header {
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  height: var(--header-height);
  position: relative;
  flex-shrink: 0;
  background: linear-gradient(to bottom, rgba(18, 18, 26, 0.8), transparent);
  border-bottom: 1px solid var(--border);
}

/* Subtle glow line under header */
.app-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--border-accent) 30%,
    var(--border-accent) 70%,
    transparent 100%
  );
}

.hamburger {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0.6rem;
  border-radius: 8px;
  z-index: 1;
  transition: all 0.2s;
}

.hamburger:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
}

.hamburger:active {
  background: rgba(255, 255, 255, 0.1);
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: all 0.2s;
}

.hamburger:hover span {
  background: var(--accent);
}

.app-header .wordmark {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.accent {
  color: var(--accent);
}

/* ============ Page Content ============ */
.page-content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Fade-in animation */
.page-content.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

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

/* ============ Cards ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.glow-card {
  animation: fadeIn 0.4s ease backwards;
}

.card:hover {
  border-color: var(--border-accent);
  box-shadow: 0 0 20px rgba(0, 200, 255, 0.04), 0 4px 16px rgba(0, 0, 0, 0.3);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.card-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card-text {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.7;
}

.card-text.muted {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
  margin-top: 1rem;
}

/* ============ Instructions List ============ */
.instructions {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin-bottom: 0.5rem;
}

.instructions li {
  counter-increment: step;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0;
  color: var(--text);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
  transition: color 0.2s;
}

.instructions li:last-child {
  border-bottom: none;
}

.instructions li:hover {
  color: #fff;
}

.instructions li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  border: 1px solid var(--border-accent);
}

/* ============ Dashboard Grid ============ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  min-height: calc(100vh - var(--header-height) - 8rem);
}

.dashboard-left {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* AI Guidance */
.ai-guidance {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 1.5rem;
  flex: 1;
  min-height: 120px;
}

.ai-guidance-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.ai-guidance-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ai-guidance-text {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.7;
}

.ai-guidance-text.updated {
  animation: guidancePulse 0.4s ease;
}

@keyframes guidancePulse {
  0% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* AI Loading */
.ai-loading {
  margin-top: 0.5rem;
}

.loading-dots {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
}

.loading-dots span {
  animation: dotBlink 1.4s infinite;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotBlink {
  0%, 20% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

/* Diagram Selector */
.diagram-selector {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.diagram-selector-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.diagram-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.diagram-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s;
  font-family: var(--font);
}

.diagram-card:hover {
  border-color: var(--border-accent);
  background: rgba(0, 200, 255, 0.04);
}

.diagram-card.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 12px rgba(0, 200, 255, 0.1);
}

.diagram-card.suggested {
  border-color: rgba(0, 200, 255, 0.4);
  box-shadow: 0 0 8px rgba(0, 200, 255, 0.08);
}

.diagram-card.suggested::after {
  content: 'suggested';
  position: absolute;
  top: -8px;
  right: -4px;
  font-size: 0.6rem;
  color: var(--accent);
  background: var(--bg-card);
  padding: 0 4px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.diagram-card {
  position: relative;
}

.diagram-card-abbr {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}

.diagram-card-name {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.3;
}

.diagram-card.selected .diagram-card-name {
  color: var(--text);
}

/* Generate Button */
.generate-btn {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #0a0a0f;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.generate-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.generate-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.generate-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.generate-btn.loading {
  opacity: 0.6;
  cursor: wait;
}

/* Diagram Output */
.diagram-output {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.diagram-output-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.diagram-svg-container {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
}

.diagram-svg-container svg {
  width: 100%;
  height: auto;
  display: block;
}

.diagram-error {
  color: #ff6b6b;
  font-size: 0.85rem;
  padding: 0.75rem;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: 8px;
  margin-top: 0.5rem;
}

/* User Input */
.user-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.user-input-form {
  display: flex;
  gap: 0.75rem;
}

.user-input-field {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.user-input-field::placeholder {
  color: var(--text-muted);
}

.user-input-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.user-input-submit {
  background: var(--accent);
  color: #0a0a0f;
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.5rem;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}

.user-input-submit:hover {
  opacity: 0.9;
}

.user-input-submit:active {
  transform: scale(0.97);
}

/* Input List */
.input-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--header-height) - 8rem);
}

.input-list-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.input-list-header h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.input-list-items {
  flex: 1;
  overflow-y: auto;
}

.input-list-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
  text-align: center;
  padding: 2rem 0.5rem;
}

.input-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
  animation: itemFadeIn 0.3s ease forwards;
}

.input-item:last-child {
  border-bottom: none;
}

.input-item-text {
  flex: 1;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
  min-width: 0;
  word-break: break-word;
}

.input-item-edit {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  min-width: 0;
}

.input-item-edit:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-item-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.input-item-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.input-item-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.input-item-btn.delete:hover {
  color: #ff6b6b;
}

.input-item.fade-out {
  animation: itemFadeOut 0.25s ease forwards;
}

@keyframes itemFadeIn {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

/* ============ Examples Page ============ */
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.35rem;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.examples-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.example-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.example-card:hover {
  border-color: var(--border-accent);
  box-shadow: 0 0 20px rgba(0, 200, 255, 0.04), 0 4px 16px rgba(0, 0, 0, 0.3);
}

.example-image {
  width: 100%;
  height: 120px;
  background: var(--bg-elevated);
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

.example-title {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.3rem;
}

.example-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ============ Footer ============ */
footer {
  padding: 2rem 1.5rem;
  text-align: center;
}

footer p {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ============ Focus ============ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .input-list {
    max-height: none;
  }

  .examples-grid {
    grid-template-columns: 1fr;
  }

  .diagram-cards {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 100%;
    left: -100%;
  }

  .app-header .wordmark {
    font-size: 1.15rem;
  }

  .page-content {
    padding: 1.5rem 1rem;
  }

  .user-input-form {
    flex-direction: column;
  }

  .diagram-cards {
    grid-template-columns: 1fr 1fr;
  }
}
