/* ============================================
   DigMaker - Modern UI Design System
   Based on Web Design Guidelines v1.0
   ============================================ */

/* CSS Custom Properties - Design Tokens */
:root {
  color-scheme: light;
  /* Primary Color Scale - Teal */
  --primary-50: #ecfdfa;
  --primary-100: #d5f5ee;
  --primary-200: #a7ebe0;
  --primary-300: #6fdccf;
  --primary-400: #2cc7b7;
  --primary-500: #0f766e;
  --primary-600: #0b5d57;
  --primary-700: #0a4a45;
  --primary-800: #083b37;
  --primary-900: #062d2a;

  /* Secondary Color Scale - Amber */
  --secondary-50: #fffbeb;
  --secondary-100: #fef3c7;
  --secondary-500: #f59e0b;
  --secondary-600: #d97706;

  /* Accent Colors */
  --accent-sky: #38bdf8;
  --accent-mint: #34d399;
  --accent-coral: #f97316;

  /* Semantic Colors */
  --success-50: #f0fdf4;
  --success-100: #dcfce7;
  --success-500: #22c55e;
  --success-600: #16a34a;

  --warning-50: #fffbeb;
  --warning-100: #fef3c7;
  --warning-500: #f59e0b;
  --warning-600: #d97706;

  --error-50: #fef2f2;
  --error-100: #fee2e2;
  --error-500: #ef4444;
  --error-600: #dc2626;

  /* Neutral Gray Scale */
  --gray-0: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --gray-950: #020617;

  /* Background Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-overlay: rgba(15, 23, 42, 0.8);

  /* Text Colors */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Border Colors */
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  --border-focus: #0f766e;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #0f766e 0%, #2cc7b7 100%);
  --gradient-secondary: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
  --gradient-accent: linear-gradient(135deg, #38bdf8 0%, #14b8a6 100%);
  --gradient-mesh: linear-gradient(135deg, #fff4d6 0%, #e9fbf6 45%, #dff3ff 100%);
  --gradient-dark: linear-gradient(135deg, #0b1220 0%, #111827 100%);

  /* Typography */
  --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;

  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Line Heights */
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.4);
  --shadow-glow-lg: 0 0 40px rgba(99, 102, 241, 0.3);

  /* Transitions */
  --duration-150: 150ms;
  --duration-200: 200ms;
  --duration-300: 300ms;
  --duration-500: 500ms;
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);

  /* Z-Index Scale */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal: 500;
  --z-toast: 800;
  --z-loading: 900;
}

/* ============================================
   Dark Theme Tokens
   ============================================ */

html[data-theme="dark"] {
  color-scheme: dark;

  /* Neutral Gray Scale (dark context) */
  --gray-0: #0b1220;
  --gray-50: #0f172a;
  --gray-100: #111827;
  --gray-200: #1f2937;
  --gray-300: #334155;
  --gray-400: #475569;
  --gray-500: #64748b;
  --gray-600: #94a3b8;
  --gray-700: #cbd5e1;
  --gray-800: #e2e8f0;
  --gray-900: #f8fafc;
  --gray-950: #ffffff;

  /* Background Colors */
  --bg-primary: #0b1220;
  --bg-secondary: #0f172a;
  --bg-tertiary: #111827;
  --bg-elevated: #111827;
  --bg-overlay: rgba(2, 6, 23, 0.85);

  /* Text Colors */
  --text-primary: #e2e8f0;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-light: #64748b;

  /* Border Colors */
  --border-color: #1f2937;
  --border-hover: #334155;
  --border-focus: #2cc7b7;

  /* Secondary/Status Tints */
  --secondary-50: #1f1a0b;
  --secondary-100: #2b210c;
  --success-50: #0c1f14;
  --success-100: #0f2a1a;
  --warning-50: #241a07;
  --warning-100: #2d2109;
  --error-50: #2a0f10;
  --error-100: #321112;

  /* Gradients */
  --gradient-mesh: linear-gradient(135deg, #0b1220 0%, #0f1f1c 45%, #111827 100%);
}

/* ============================================
   Reset & Base Styles
   ============================================ */

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--gradient-mesh);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Selection Styles */
::selection {
  background: var(--primary-200);
  color: var(--primary-900);
}

/* Scrollbar Styles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: var(--radius-full);
  transition: background var(--duration-200) var(--ease-out);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* ============================================
   Layout - Main Container
   ============================================ */

.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1800px;
  margin: var(--space-4) auto;
  padding: 0 var(--space-4);
  gap: var(--space-4);
}

/* Glassmorphism App Container */
.app-wrapper {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl), 0 0 0 1px rgba(255, 255, 255, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

html[data-theme="dark"] .app-wrapper {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: var(--shadow-2xl), 0 0 0 1px rgba(148, 163, 184, 0.08);
}

/* ============================================
   Header
   ============================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  background: linear-gradient(to right, var(--gray-50), var(--bg-primary));
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

html[data-theme="dark"] .header {
  background: linear-gradient(to right, #0b1220, #111827);
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary-200), transparent);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--gradient-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
  animation: float 3s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}

.logo-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 50%);
}

.logo-icon svg {
  width: 1.5rem;
  height: 1.5rem;
  color: white;
  position: relative;
  z-index: 1;
}

.logo h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--gray-900) 0%, var(--primary-600) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

html[data-theme="dark"] .logo h1 {
  background: none;
  color: #e2e8f0;
  -webkit-text-fill-color: #e2e8f0;
}

.tagline {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-4);
  background: var(--secondary-50);
  border-radius: var(--radius-full);
  border: 1px solid var(--secondary-100);
}

html[data-theme="dark"] .tagline {
  border-color: rgba(245, 158, 11, 0.2);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* ============================================
   Main Content Layout
   ============================================ */

.main-content {
  display: grid;
  grid-template-columns: 340px 1fr 1fr;
  gap: var(--space-5);
  padding: var(--space-6);
  flex: 1;
  min-height: 0;
  background: var(--bg-secondary);
}

/* ============================================
   Panels
   ============================================ */

.panel {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all var(--duration-300) var(--ease-out);
}

.panel:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(to right, var(--gray-50), var(--bg-primary));
  border-bottom: 1px solid var(--border-color);
}

html[data-theme="dark"] .panel-header {
  background: linear-gradient(to right, #0f172a, #111827);
}

.panel-header-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.panel-header h2 {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-header h2::before {
  content: '';
  width: 4px;
  height: 20px;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
}

.panel-header p {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-body {
  flex: 1;
  padding: var(--space-5);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* ============================================
   Input Panel Specific
   ============================================ */

.input-panel .panel-body {
  padding: var(--space-5);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-group label {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-group label .label-icon {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
  box-shadow: 0 0 0 2px var(--primary-100);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.form-group select,
.form-group textarea {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  transition: all var(--duration-200) var(--ease-out);
  box-shadow: var(--shadow-xs);
}

.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-100), var(--shadow-sm);
  background: var(--bg-primary);
}

.form-group select:hover,
.form-group textarea:hover {
  border-color: var(--border-hover);
}

.form-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

.form-group textarea {
  resize: vertical;
  min-height: 140px;
  line-height: var(--leading-relaxed);
}

.form-group textarea::placeholder {
  color: var(--text-light);
}

/* ============================================
   Buttons
   ============================================ */

.button-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  cursor: pointer;
  transition: all var(--duration-200) var(--ease-out);
  border: none;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.6s ease;
}

.btn:hover::before {
  left: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--gray-100);
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

html[data-theme="dark"] .btn-secondary:hover {
  background: #111827;
}

.btn-success {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: white;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.4);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(15, 118, 110, 0.5);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
}

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

/* Icon Buttons */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-200) var(--ease-out);
  box-shadow: var(--shadow-xs);
}

html[data-theme="dark"] .icon-btn {
  background: #0f172a;
  border-color: #1f2937;
}

html[data-theme="dark"] .icon-btn:hover {
  background: #111827;
  border-color: #2cc7b7;
  color: #5eead4;
}

.icon-btn:hover {
  background: var(--gray-100);
  border-color: var(--primary-300);
  color: var(--primary-600);
  transform: translateY(-1px) scale(1.05);
  box-shadow: var(--shadow-sm);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn svg {
  width: 1rem;
  height: 1rem;
}

/* ============================================
   Quick Actions / Templates
   ============================================ */

.quick-actions {
  margin-top: auto;
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-color);
}

.quick-actions-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.quick-actions-header h3 {
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.template-badge {
  font-size: var(--text-xs);
  padding: 2px 8px;
  background: var(--secondary-100);
  color: var(--secondary-600);
  border-radius: var(--radius-full);
  font-weight: var(--font-semibold);
}

.template-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.template-btn {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--gray-50) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-200) var(--ease-out);
  text-align: center;
}

html[data-theme="dark"] .template-btn {
  background: linear-gradient(135deg, #0f172a 0%, #111827 100%);
}

.template-btn:hover {
  background: linear-gradient(135deg, var(--secondary-50) 0%, var(--secondary-100) 100%);
  border-color: var(--secondary-500);
  color: var(--secondary-600);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.template-btn:active {
  transform: translateY(0);
}

/* ============================================
   Code Panel
   ============================================ */

.code-panel {
  display: flex;
  flex-direction: column;
}

.code-panel .panel-body {
  padding: 0;
  position: relative;
}

#codeEditor {
  flex: 1;
  width: 100%;
  min-height: 300px;
  background: #0b1220;
  border: none;
  padding: var(--space-5);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  resize: none;
  tab-size: 2;
}

#codeEditor:focus {
  outline: none;
}

#codeEditor::placeholder {
  color: var(--gray-500);
}

.code-panel-footer {
  padding: var(--space-3) var(--space-5);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

html[data-theme="dark"] .code-panel-footer {
  background: #0f172a;
}

/* ============================================
   Preview Panel
   ============================================ */

.preview-panel {
  display: flex;
  flex-direction: column;
}

.preview-container {
  flex: 1;
  background: linear-gradient(135deg, #fef9f1 0%, #eefbf7 100%);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  position: relative;
  overflow: auto;
  padding: var(--space-6);
  min-height: 400px;
}

html[data-theme="dark"] .preview-container {
  background: linear-gradient(135deg, #0b1220 0%, #0f172a 100%);
}

.preview-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    radial-gradient(circle at 20% 50%, rgba(15, 118, 110, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(245, 158, 11, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

html[data-theme="dark"] .preview-container::before {
  background-image: 
    radial-gradient(circle at 20% 50%, rgba(94, 234, 212, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(251, 191, 36, 0.08) 0%, transparent 50%);
}

.mermaid-output {
  width: 100%;
  min-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--duration-300) var(--ease-out);
  cursor: grab;
  position: relative;
  z-index: 1;
}

.mermaid-output:active {
  cursor: grabbing;
}

.mermaid-output svg {
  max-width: none;
  width: 100%;
  height: auto;
  min-width: 100%;
  filter: drop-shadow(var(--shadow-md));
  border-radius: var(--radius-lg);
  overflow: visible !important;
}

.placeholder-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-8);
}

.placeholder-state .placeholder-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--secondary-100) 0%, var(--secondary-50) 100%);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--secondary-600);
  opacity: 0.85;
}

.placeholder-state p {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
}

.placeholder-state .placeholder-hint {
  font-size: var(--text-sm);
  color: var(--text-light);
}

/* ============================================
   Status Bar
   ============================================ */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  background: linear-gradient(to right, var(--gray-50), var(--bg-primary));
  border-top: 1px solid var(--border-color);
  font-size: var(--text-sm);
}

html[data-theme="dark"] .status-bar {
  background: linear-gradient(to right, #0b1220, #111827);
}

.status-message {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-weight: var(--font-medium);
}

.status-message::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--gray-400);
  border-radius: var(--radius-full);
}

.status-message.success {
  color: var(--success-600);
}

.status-message.success::before {
  background: var(--success-500);
  box-shadow: 0 0 8px var(--success-500);
}

.status-message.error {
  color: var(--error-600);
}

.status-message.error::before {
  background: var(--error-500);
  box-shadow: 0 0 8px var(--error-500);
}

.status-message.loading::before {
  background: var(--primary-500);
  animation: pulse 1.5s ease-in-out infinite;
}

/* Rate Limit Indicator */
.rate-limit-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  border: 1px solid var(--primary-400);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: white;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.3);
}

.rate-limit-used {
  color: white;
  font-weight: var(--font-bold);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.rate-limit-limit {
  color: rgba(255, 255, 255, 0.8);
  font-weight: var(--font-semibold);
}

.rate-limit-separator {
  color: rgba(255, 255, 255, 0.6);
}

/* Warning state */
.rate-limit-warning {
  background: linear-gradient(135deg, var(--warning-500), var(--warning-600));
  border-color: var(--warning-400);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.rate-limit-warning .rate-limit-used {
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Exceeded state */
.rate-limit-exceeded {
  background: linear-gradient(135deg, var(--error-500), var(--error-600));
  border-color: var(--error-400);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.rate-limit-exceeded .rate-limit-used {
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Dark theme */
html[data-theme="dark"] .rate-limit-indicator {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
  border-color: var(--primary-500);
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.4);
}

html[data-theme="dark"] .rate-limit-limit {
  color: rgba(255, 255, 255, 0.7);
}

html[data-theme="dark"] .rate-limit-separator {
  color: rgba(255, 255, 255, 0.5);
}

html[data-theme="dark"] .rate-limit-warning {
  background: linear-gradient(135deg, var(--warning-600), var(--warning-700));
  border-color: var(--warning-500);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

html[data-theme="dark"] .rate-limit-warning .rate-limit-used {
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

html[data-theme="dark"] .rate-limit-exceeded {
  background: linear-gradient(135deg, var(--error-600), var(--error-700));
  border-color: var(--error-500);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

html[data-theme="dark"] .rate-limit-exceeded .rate-limit-used {
  color: var(--error-500);
}

.status-info {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.status-badge {
  padding: var(--space-1) var(--space-3);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

/* ============================================
   Loading Overlay
   ============================================ */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  opacity: 1;
  visibility: visible;
  transition: all var(--duration-300) var(--ease-out);
}

html[data-theme="dark"] .loading-overlay {
  background: rgba(2, 6, 23, 0.88);
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader {
  text-align: center;
  background: var(--bg-primary);
  padding: var(--space-8);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  border: 1px solid var(--border-color);
  max-width: 320px;
}

.spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--primary-100);
  border-top-color: var(--primary-500);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
  margin: 0 auto var(--space-5);
}

.loader-text {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.loader-subtext {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-xl);
  color: white;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  animation: slideInRight 0.4s var(--ease-spring);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  max-width: 400px;
}

.toast.success {
  background: linear-gradient(135deg, var(--success-500) 0%, var(--success-600) 100%);
}

.toast.error {
  background: linear-gradient(135deg, var(--error-500) 0%, var(--error-600) 100%);
}

.toast.warning {
  background: linear-gradient(135deg, var(--warning-500) 0%, var(--warning-600) 100%);
}

.toast.info {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ============================================
   Fullscreen Mode
   ============================================ */

.fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-300) var(--ease-out);
}

.fullscreen-overlay.active {
  opacity: 1;
  visibility: visible;
}

.fullscreen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

html[data-theme="dark"] .fullscreen-header {
  background: #0f172a;
}

.fullscreen-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  overflow: auto;
}

.fullscreen-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--duration-200) var(--ease-out);
}

.fullscreen-close-btn:hover {
  background: var(--error-50);
  border-color: var(--error-200);
  color: var(--error-600);
  transform: rotate(90deg);
}

/* ============================================
   Animations
   ============================================ */

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ============================================
   Focus Styles (Accessibility)
   ============================================ */

.btn:focus-visible,
.icon-btn:focus-visible,
.template-btn:focus-visible,
.form-group select:focus-visible,
.form-group textarea:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1400px) {
  .main-content {
    grid-template-columns: 300px 1fr 1fr;
    gap: var(--space-4);
    padding: var(--space-5);
  }
}

@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 280px 1fr;
    grid-template-rows: 1fr 1fr;
    gap: var(--space-4);
  }

  .input-panel {
    grid-row: span 2;
  }

  .code-panel {
    grid-column: 2;
    grid-row: 1;
  }

  .preview-panel {
    grid-column: 2;
    grid-row: 2;
  }
}

@media (max-width: 900px) {
  .container {
    margin: var(--space-2);
    padding: 0 var(--space-2);
  }

  .app-wrapper {
    border-radius: var(--radius-xl);
  }

  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: var(--space-4);
    padding: var(--space-4);
  }

  .input-panel,
  .code-panel,
  .preview-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .input-panel {
    order: 1;
  }

  .code-panel {
    order: 2;
  }

  .preview-panel {
    order: 3;
    min-height: 400px;
  }

  .header {
    flex-direction: column;
    gap: var(--space-3);
    text-align: center;
    padding: var(--space-4);
  }

  .logo h1 {
    font-size: var(--text-xl);
  }

  .tagline {
    font-size: var(--text-xs);
  }

  .template-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .button-group {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .status-bar {
    flex-direction: column;
    gap: var(--space-2);
    text-align: center;
  }

  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: var(--space-4);
  }

  .toast {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .panel-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .template-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .logo-icon {
    animation: none;
  }
}

/* ============================================
   Inline Editor Styles
   ============================================ */

.inline-editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-200) var(--ease-out);
}

.inline-editor-overlay.active {
  opacity: 1;
  visibility: visible;
}

.inline-editor {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-2xl);
  padding: var(--space-6);
  min-width: 320px;
  max-width: 480px;
  width: 90%;
  animation: slideUp 0.3s var(--ease-spring);
}

.inline-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.inline-editor-header h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.inline-editor-header h3::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--primary-500);
  display: inline-block;
}

.inline-editor-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-200) var(--ease-out);
}

.inline-editor-close:hover {
  background: var(--error-50);
  border-color: var(--error-200);
  color: var(--error-600);
}

.inline-editor-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: all var(--duration-200) var(--ease-out);
  margin-bottom: var(--space-4);
}

.inline-editor-input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px var(--primary-100);
  background: var(--bg-primary);
}

.inline-editor-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

.inline-editor-actions .btn {
  min-width: 100px;
}

/* Editable node indicator */
.mermaid-output svg .node {
  cursor: pointer;
  transition: filter var(--duration-200) var(--ease-out);
}

.mermaid-output svg .node:hover {
  filter: brightness(1.1) drop-shadow(0 0 8px rgba(99, 102, 241, 0.4));
}

.mermaid-output svg .node:hover rect,
.mermaid-output svg .node:hover circle,
.mermaid-output svg .node:hover polygon,
.mermaid-output svg .node:hover ellipse {
  stroke: var(--primary-500);
  stroke-width: 3px;
}

/* Edit hint tooltip */
.edit-hint {
  position: absolute;
  background: #0b1220;
  color: white;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--duration-200) var(--ease-out);
  z-index: 100;
  white-space: nowrap;
}

.edit-hint.visible {
  opacity: 1;
  transform: translateY(0);
}

.edit-hint::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: #0b1220 transparent transparent;
}

/* Theme Toggle Icon Visibility */
.theme-icon {
  width: 1rem;
  height: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-icon svg {
  width: 100%;
  height: 100%;
}

.theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-icon-sun {
  display: inline-flex;
}

html[data-theme="dark"] .theme-icon-moon {
  display: none;
}

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

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .header,
  .status-bar,
  .loading-overlay,
  .toast-container,
  .panel-actions,
  .inline-editor-overlay {
    display: none !important;
  }

  .container {
    background: white;
  }

  .app-wrapper {
    box-shadow: none;
    border: none;
  }

  .main-content {
    display: block;
  }

  .panel {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
    margin-bottom: 1rem;
  }
}
