/* --- Design System & CSS Variables --- */
:root {
  --font-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-serif: 'Lora', Georgia, serif;
  --font-mono: 'Fira Code', monospace;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 35px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
}

/* --- Dark Theme Variables --- */
body.dark-theme {
  --bg-app: #08090d;
  --bg-panel: #0e1017;
  --bg-card: rgba(22, 24, 34, 0.6);
  --bg-card-hover: rgba(29, 32, 46, 0.85);
  --bg-input: #151722;
  --border-color: rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.15);
  
  --text-primary: #eff1f5;
  --text-secondary: #9aa0b2;
  --text-muted: #5e6375;
  
  --accent-color: #3b82f6;
  --accent-color-hover: #2563eb;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  --accent-glow: rgba(59, 130, 246, 0.2);
  
  --toast-bg: rgba(14, 16, 23, 0.95);
  --toast-border: rgba(59, 130, 246, 0.3);
  --color-success: #10b981;
}

/* --- Light Theme Variables --- */
body.light-theme {
  --bg-app: #f1f3f7;
  --bg-panel: #ffffff;
  --bg-card: rgba(240, 242, 245, 0.8);
  --bg-card-hover: rgba(240, 242, 245, 1);
  --bg-input: #ffffff;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  
  --accent-color: #2563eb;
  --accent-color-hover: #1d4ed8;
  --accent-gradient: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  --accent-glow: rgba(37, 99, 235, 0.15);
  
  --toast-bg: rgba(255, 255, 255, 0.95);
  --toast-border: rgba(37, 99, 235, 0.2);
  --color-success: #059669;
}

/* --- Reset & Base Styles --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
}

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

::-webkit-scrollbar-track {
  background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* --- Layout Container --- */
.app-container {
  width: 100%;
  max-width: 1540px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex-grow: 1;
}

/* --- Header --- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon-wrapper {
  background: var(--accent-gradient);
  color: white;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.logo-icon {
  width: 20px;
  height: 20px;
}

.header-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.header-actions {
  display: flex;
  align-items: center;
}

/* --- Theme Toggle Button --- */
.theme-toggle-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

body.dark-theme .sun-icon,
body.light-theme .moon-icon {
  display: block;
}

body.dark-theme .moon-icon,
body.light-theme .sun-icon {
  display: none;
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* --- Main Workspace Layout --- */
.app-main {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 1.5rem;
  flex-grow: 1;
  height: calc(100vh - 120px);
  min-height: 0;
}

@media (max-width: 1024px) {
  .app-main {
    grid-template-columns: 1fr;
    height: auto;
  }
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  height: 100%;
  min-height: 0;
}

/* --- Left Column: Controls & Exporter --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.card-header svg {
  color: var(--accent-color);
  width: 20px;
  height: 20px;
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-group input {
  font-family: var(--font-sans);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  outline: none;
  transition: all var(--transition-fast);
}

.input-group input:focus {
  border-color: var(--accent-color);
}

/* --- Exporter Styles --- */
.export-card {
  flex-grow: 1;
  min-height: 280px;
}

.export-tabs-header {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  gap: 1.25rem;
}

.export-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  padding-bottom: 0.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.export-tab-btn:hover {
  color: var(--text-primary);
}

.export-tab-btn.active {
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.export-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-grow: 1;
  min-height: 0;
}

.code-block-wrapper {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  flex-grow: 1;
  overflow-y: auto;
  min-height: 120px;
}

.code-block-wrapper pre {
  margin: 0;
}

.code-block-wrapper code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.btn-copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-copy-code:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.btn-copy-code svg {
  width: 14px;
  height: 14px;
}

.download-action-wrapper {
  display: flex;
  justify-content: flex-end;
}

/* Button styles */
.btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
  width: 100%;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--accent-glow);
  filter: brightness(1.05);
}

/* --- Right Column: Preview Panel --- */
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.preview-badge {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
}

.preview-viewport {
  flex-grow: 1;
  background: #141722;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: start;
}

/* --- Document Sheet Styling --- */
.preview-sheet {
  background-color: #ffffff;
  color: #1f2937;
  padding: 2.5rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 760px;
  border-radius: 4px;
  box-sizing: border-box;
  font-family: var(--font-serif);
  line-height: 1.6;
}

.policy-header {
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
}

.policy-header h1 {
  font-family: var(--font-sans);
  font-size: 1.75rem;
  font-weight: 700;
  color: #111827;
  line-height: 1.25;
  margin-bottom: 0.75rem;
}

.policy-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: #4b5563;
  font-family: var(--font-sans);
}

.policy-meta span {
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: #f3f4f6;
  padding: 1px 4px;
  border-radius: 3px;
  color: #111827;
}

.policy-content h2 {
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 600;
  color: #111827;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  border-top: 1px solid #f3f4f6;
  padding-top: 1rem;
}

.policy-content h2:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0.5rem;
}

.policy-content p {
  margin-bottom: 1rem;
  font-size: 0.95rem;
  text-align: justify;
}

.policy-content ul {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
  font-size: 0.95rem;
}

.policy-content li {
  margin-bottom: 0.5rem;
  text-align: justify;
}

.policy-content li strong {
  color: #111827;
}

.policy-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: #f3f4f6;
  padding: 1px 4px;
  border-radius: 3px;
  color: #c7254e;
}

/* Bindings highlighter */
.bind-tool-name, .bind-dev-name {
  font-weight: bold;
}

/* --- Toast Alerts --- */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 9999;
}

.toast {
  background: var(--toast-bg);
  border: 1px solid var(--toast-border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transform: translateY(20px);
  opacity: 0;
  animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  backdrop-filter: blur(10px);
}

.toast svg {
  color: var(--color-success);
  width: 16px;
  height: 16px;
}

.toast-message {
  font-size: 0.85rem;
  font-weight: 500;
}

@keyframes toast-in {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast.fade-out {
  animation: toast-out 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toast-out {
  to {
    transform: translateY(10px);
    opacity: 0;
  }
}
