:root {
  --bg: #0b1020;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0ea5e9;
  --primary-2: #6366f1;
  --primary-fg: #ffffff;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #050817;
    --surface: #0f172a;
    --surface-2: #111c33;
    --surface-3: #1e293b;
    --border: #1f2937;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.6em; letter-spacing: -0.015em; }
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
small, .muted { color: var(--text-muted); }

.splash {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; gap: 1rem; color: #94a3b8;
}
.splash img { filter: drop-shadow(0 8px 24px rgba(14,165,233,0.3)); animation: pulse 2.5s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); opacity: 0.85; } }

.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1rem; border-radius: var(--radius);
  border: 1px solid transparent; font: inherit; font-weight: 500;
  cursor: pointer; transition: all 120ms ease;
  background: var(--surface-3); color: var(--text);
}
.btn:hover { background: var(--surface-2); border-color: var(--border); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--primary-fg); border: none; box-shadow: var(--shadow);
}
.btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  font: inherit; transition: border-color 120ms, box-shadow 120ms;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.18);
}
label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.35rem; color: var(--text-muted); }
.field { margin-bottom: 1rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.app-shell { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; background: var(--surface-2); color: var(--text); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.topbar .brand { display: flex; align-items: center; gap: 0.65rem; font-weight: 700; }
.topbar .brand img { width: 32px; height: 32px; }
.topbar nav { display: flex; gap: 0.25rem; }
.topbar nav a {
  padding: 0.4rem 0.9rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 500; font-size: 0.95rem;
}
.topbar nav a:hover { background: var(--surface-3); }
.topbar nav a.active { background: var(--surface-3); color: var(--primary); }
.topbar .right { display: flex; align-items: center; gap: 0.75rem; }

.page { padding: 1.5rem; max-width: 1280px; margin: 0 auto; width: 100%; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }

.auth-shell {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(ellipse at top, rgba(14,165,233,0.18), transparent 60%),
              radial-gradient(ellipse at bottom right, rgba(99,102,241,0.18), transparent 60%),
              var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; padding: 2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.auth-card .brand-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem; }
.auth-card .brand-row img { width: 40px; height: 40px; }
.auth-card .brand-row strong { font-size: 1.15rem; }

.landing {
  min-height: 100vh; color: white;
  background: radial-gradient(ellipse at top left, rgba(14,165,233,0.32), transparent 55%),
              radial-gradient(ellipse at bottom right, rgba(99,102,241,0.32), transparent 55%),
              #050817;
}
.landing .hero {
  max-width: 1100px; margin: 0 auto; padding: 6rem 1.5rem 4rem;
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 3rem; align-items: center;
}
.landing h1 { font-size: 3rem; font-weight: 800; line-height: 1.05; }
.landing h1 .grad {
  background: linear-gradient(135deg, #38bdf8, #818cf8); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.landing p.lead { color: #cbd5e1; font-size: 1.1rem; line-height: 1.55; }
.landing .hero-art { display: grid; place-items: center; }
.landing .hero-art img { width: 280px; max-width: 100%; filter: drop-shadow(0 20px 60px rgba(99,102,241,0.4)); }
.landing .features {
  max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem 6rem;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem;
}
.landing .feature {
  background: rgba(15,23,42,0.6); backdrop-filter: blur(8px);
  border: 1px solid rgba(148,163,184,0.18); border-radius: var(--radius-lg); padding: 1.5rem; color: #e2e8f0;
}
.landing .feature h3 { color: #f1f5f9; }
@media (max-width: 800px) { .landing .hero, .landing .features { grid-template-columns: 1fr; } .landing .hero { padding-top: 3rem; } }

.designer { display: grid; grid-template-columns: 260px minmax(0, 1fr) 320px; gap: 0; height: calc(100vh - 56px); background: var(--surface-2); }
.designer .rail { background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; padding: 1rem; }
.designer .rail.right { border-right: none; border-left: 1px solid var(--border); }
.designer .stage { display: flex; flex-direction: column; min-width: 0; }
.designer .toolbar {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.designer .canvas-wrap {
  flex: 1; overflow: auto; padding: 2rem; display: grid; place-items: center;
  background-image:
    linear-gradient(to right, rgba(148,163,184,0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148,163,184,0.12) 1px, transparent 1px);
  background-size: 10px 10px;
}
.designer svg.card-canvas {
  background: white; box-shadow: var(--shadow-lg); border-radius: 4px; user-select: none;
}
.designer .field-rect {
  fill: rgba(14,165,233,0.06); stroke: rgba(14,165,233,0.4); stroke-width: 0.1;
  stroke-dasharray: 0.6 0.4; cursor: move;
}
.designer .field-rect.selected { fill: rgba(14,165,233,0.14); stroke: var(--primary); stroke-dasharray: none; stroke-width: 0.2; }
.designer .field-handle { fill: white; stroke: var(--primary); stroke-width: 0.15; cursor: nwse-resize; }

.field-list { list-style: none; padding: 0; margin: 0; }
.field-list li {
  padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem;
  border: 1px solid transparent;
}
.field-list li:hover { background: var(--surface-3); }
.field-list li.active { background: rgba(14,165,233,0.12); border-color: rgba(14,165,233,0.3); color: var(--primary); }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.palette button {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.5rem; cursor: pointer; font-size: 0.85rem; color: var(--text); transition: all 120ms;
}
.palette button:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }

.section-title {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin: 1.25rem 0 0.5rem;
}
.section-title:first-child { margin-top: 0; }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 1.5rem; text-align: center; cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: rgba(14,165,233,0.05); }
.dropzone input[type=file] { display: none; }

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 1000;
  background: var(--surface); border: 1px solid var(--border); padding: 0.75rem 1rem;
  border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: 380px;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

.tbl { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tbl th, .tbl td { padding: 0.55rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.tbl th { font-weight: 600; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.tbl tr:hover td { background: var(--surface-3); }

.badge {
  display: inline-flex; align-items: center; padding: 0.15rem 0.55rem;
  border-radius: 999px; font-size: 0.75rem; font-weight: 500;
  background: var(--surface-3); color: var(--text-muted);
}
.badge.primary { background: rgba(14,165,233,0.15); color: var(--primary); }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.template-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.25rem; cursor: pointer; transition: transform 120ms, box-shadow 120ms;
}
.template-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

#blazor-error-ui {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  padding: 0.8rem 1rem; background: #fee2e2; color: #991b1b;
  border-top: 1px solid #fca5a5; z-index: 1100;
}
#blazor-error-ui .reload, #blazor-error-ui .dismiss { margin-left: 1rem; cursor: pointer; }

@media print {
  body { background: white !important; }
  .no-print, .topbar, .designer .rail, .designer .toolbar { display: none !important; }
}
