/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1a3a5c;
  --primary-light: #2d5a8e;
  --primary-dark: #0f2440;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f8f9fa;
  --text: #1a1a2e;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-focus: var(--primary);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-focus: 0 0 0 3px rgba(26,58,92,0.15);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 420px;
}

[data-theme=dark]{
  --bg:#0f172a;--surface:#1e293b;--surface-hover:#0f172a;
  --text:#f1f5f9;--text-secondary:#94a3b8;--text-muted:#64748b;
  --border:#334155;
  --shadow:0 1px 3px rgba(0,0,0,.3),0 1px 2px rgba(0,0,0,.2);
  --shadow-lg:0 10px 40px rgba(0,0,0,.4),0 2px 8px rgba(0,0,0,.2);
  --shadow-focus:0 0 0 3px rgba(45,90,142,.4)
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === SKIP LINK === */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 var(--radius-xs) var(--radius-xs);
  font-weight: 600;
  font-size: 0.85rem;
  z-index: 1000;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* === HEADER === */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 2rem 2rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,0.15);
}

.app-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  position: relative;
}

.app-logo img {
  height: 40px;
  width: auto;
  display: block;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-subtitle {
  font-size: 0.85rem;
  opacity: 0.75;
  width: 100%;
  margin-top: -0.5rem;
}

/* === NAV TOOLS === */
.nav-tools {
  position: absolute;
  right: 0;
  top: 0;
}

.nav-tools-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font);
  line-height: 1.1;
  border: 1.5px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-xs);
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.nav-tools-btn:hover {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.4);
}

.nav-tools-btn svg { flex-shrink: 0; }

.nav-tools-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: all 0.2s ease;
  z-index: 200;
}

.nav-tools-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-tools-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  border-radius: var(--radius-xs);
  text-decoration: none;
  transition: var(--transition);
}

.nav-tools-link:hover {
  background: var(--surface-hover);
  text-decoration: none;
  color: var(--primary);
}

.nav-tools-link.active {
  background: rgba(26,58,92,0.06);
  color: var(--primary);
  font-weight: 600;
}

.nav-tools-icon { font-size: 1rem; line-height: 1; }

/* === HEADER ACTIONS === */
.header-actions{display:flex;gap:.5rem;align-items:center;position:absolute;right:0;top:0}
.header-actions + .nav-tools{right:44px}
.header-btn{
  display:inline-flex;align-items:center;gap:.35rem;
  padding:.35rem .65rem;font-size:.75rem;font-weight:600;font-family:var(--font);
  border:1.5px solid rgba(255,255,255,.25);border-radius:var(--radius-xs);
  background:rgba(255,255,255,.1);color:#fff;cursor:pointer;
  white-space:nowrap;transition:var(--transition);text-decoration:none
}
.header-btn:hover{background:rgba(255,255,255,.18);border-color:rgba(255,255,255,.4);text-decoration:none}

/* === LAYOUT === */
.app-container {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  gap: 1.5rem;
  min-height: calc(100vh - 120px);
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 100px;
  align-self: flex-start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-inner {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* === FORM SECTIONS === */
.form-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.form-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 0.875rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.required { color: #dc2626; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  transition: var(--transition);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.field-invalid {
  border-color: #dc2626 !important;
  background: rgba(220,38,38,0.04);
}

.field-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220,38,38,0.15) !important;
}

textarea { resize: vertical; min-height: 48px; }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-light);
  box-shadow: var(--shadow);
}

.btn-outline {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--surface-hover);
}

.btn-sm {
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
}

.btn-success {
  background: #059669;
  color: #fff;
}

.btn-success:hover {
  background: #047857;
  box-shadow: var(--shadow);
}

/* === PREVIEW === */
.preview-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.preview-header .section-title {
  margin-bottom: 0;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
}

#previewFrame {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

[data-theme=dark] #previewFrame {
  background: #0f172a;
}

.footer-preview {
  padding: 1.5rem;
  min-height: 160px;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem 2rem;
  color: var(--text-muted);
  text-align: center;
}

.preview-placeholder p {
  font-size: 0.9rem;
  max-width: 250px;
}

/* === CODE OUTPUT === */
.code-section {
  background: #1e1e2e;
  border-radius: var(--radius-sm);
  position: relative;
}

.code-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.code-section-header span {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.code-copy-btn {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  border: 1.5px solid rgba(255,255,255,0.2);
}

.code-copy-btn:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.35);
  color: #fff;
}

.html-code {
  display: block;
  padding: 1rem;
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  color: #cdd6f4;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--primary-dark);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 999;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === FOOTER === */
.app-footer {
  max-width: 1400px;
  margin: 1.5rem auto 0;
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.app-footer nav {
  display: flex;
  gap: 1.25rem;
}

.app-footer a {
  color: var(--text-secondary);
}

.app-footer a:hover {
  color: var(--text);
}

/* === RESPONSIVE === */
@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 1.25rem 1rem;
  }

  .app-header h1 {
    font-size: 1.05rem;
  }

  .app-container {
    padding: 1rem;
    gap: 1rem;
  }

  .preview-container {
    padding: 0.75rem;
  }

  .app-footer {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
  }
}
