/* ============================================================
   MAIN.CSS — CSS Custom Properties, Reset, Base Typography
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,400&family=Merriweather:ital,wght@0,300;0,400;0,700;1,400&family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;1,400&family=Lato:ital,wght@0,300;0,400;0,700;1,400&family=Roboto:ital,wght@0,300;0,400;0,500;0,700;1,400&family=Raleway:ital,wght@0,300;0,400;0,600;0,700;1,400&family=Montserrat:ital,wght@0,300;0,400;0,600;0,700;1,400&family=Nunito:ital,wght@0,300;0,400;0,600;0,700;1,400&family=PT+Serif:ital,wght@0,400;0,700;1,400&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap');

/* ── Root Variables ─────────────────────────────────────── */
:root {
  /* Brand Colors */
  --primary: #1B2DE7;
  --primary-dark: #1424C0;
  --primary-light: #4558FF;
  --primary-xlight: rgba(27, 45, 231, 0.08);

  /* UI Colors */
  --bg: #F4F6FD;
  --bg-panel: #FFFFFF;
  --bg-sidebar: #EFF2FA;
  --border: #DDE2F0;
  --border-light: #E8ECF8;

  /* Text */
  --text-primary: #1D2532;
  --text-secondary: #838CA3;
  --text-muted: #A0A8BC;
  --text-placeholder: #C0C6D8;

  /* Interactive */
  --accent: #1B2DE7;
  --accent-hover: #1424C0;
  --link: #1B2DE7;
  --focus-ring: 0 0 0 3px rgba(27, 45, 231, 0.18);

  /* Status */
  --success: #16A34A;
  --warning: #D97706;
  --error: #DC2626;
  --info: #0EA5E9;

  /* Shadows — blue-tinted */
  --shadow-xs: 0 1px 2px rgba(27, 45, 231, 0.05);
  --shadow-sm: 0 2px 6px rgba(27, 45, 231, 0.07);
  --shadow-md: 0 4px 14px rgba(27, 45, 231, 0.09);
  --shadow-lg: 0 8px 28px rgba(27, 45, 231, 0.11);
  --shadow-xl: 0 20px 48px rgba(27, 45, 231, 0.13);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 999px;

  /* Typography */
  --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 120ms var(--ease-out);
  --transition-base: 200ms var(--ease-out);
  --transition-slow: 350ms var(--ease-out);

  /* Z-index */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;
  --z-toast: 400;
  --z-tooltip: 500;

  /* Sidebar width */
  --sidebar-width: 220px;

  /* Preview dimensions */
  --page-a4-width: 210mm;
  --page-a4-height: 297mm;
  --page-letter-width: 8.5in;
  --page-letter-height: 11in;
}

/* Dark Mode */
[data-theme="dark"] {
  --bg: #0F1117;
  --bg-panel: #181C27;
  --bg-sidebar: #1E2233;
  --border: #2A3045;
  --border-light: #242840;
  --text-primary: #E8EAF2;
  --text-secondary: #8892AA;
  --text-muted: #596480;
  --text-placeholder: #3A4460;
  --primary-xlight: rgba(27, 45, 231, 0.15);
  --shadow-sm: 0 2px 6px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.35);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.4);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  overflow: hidden;
  height: 100vh;
}

/* ── Base Typography ────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

p { color: var(--text-secondary); }

a {
  color: var(--link);
  text-decoration: none;
  transition: opacity var(--transition-fast);
}
a:hover { opacity: 0.8; }

img { max-width: 100%; display: block; }

button {
  font-family: var(--font-ui);
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
}

input, textarea, select {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  outline: none;
}

ul, ol { list-style: none; }

/* ── Scrollbars — hidden but functional ─────────────────── */
::-webkit-scrollbar { width: 0; height: 0; background: transparent; }
* { scrollbar-width: none; }

/* ── Selection ──────────────────────────────────────────── */
::selection {
  background: rgba(27,45,231,0.12);
  color: var(--text-primary);
}

/* ── Utility Classes ────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-primary-color { color: var(--primary); }

/* ── Button Variants ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-base);
  white-space: nowrap;
  line-height: 1.4;
  border: 1.5px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(27,45,231,0.35);
  transform: translateY(-1px);
}

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

.btn-secondary {
  background: white;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
}
.btn-ghost:hover {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: transparent;
}
.btn-danger:hover {
  background: rgba(231,76,60,0.08);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1rem;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.btn-icon:hover {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

.reset-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 500;
}
.reset-btn:hover {
  background: rgba(220, 38, 38, 0.07);
  color: var(--error);
  border-color: rgba(220, 38, 38, 0.35);
}

/* ── Badge ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-primary {
  background: var(--primary);
  color: white;
}

.badge-success {
  background: rgba(39,174,96,0.12);
  color: var(--success);
}

.badge-warning {
  background: rgba(243,156,18,0.12);
  color: var(--warning);
}

/* ── Tag / Chip ─────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--primary-xlight);
  color: var(--primary);
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.tag button {
  display: flex;
  align-items: center;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
  padding: 0;
  line-height: 1;
}
.tag button:hover { opacity: 1; }

/* ── Tooltip ────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: white;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: var(--z-tooltip);
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── Divider ────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Toast ──────────────────────────────────────────────── */

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 150ms ease forwards;
  transition: opacity 150ms ease;
}

.modal-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.modal {
  display: block;
  position: relative;
  top: auto;
  left: auto;
  height: auto;
  outline: none;
  background: var(--bg-panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 200ms var(--ease-out) forwards;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.modal-body { padding: 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

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

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

/* ── Dropdown ───────────────────────────────────────────── */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  z-index: var(--z-dropdown);
  overflow: hidden;
  animation: slideDown 150ms var(--ease-out);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: background var(--transition-fast);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

.dropdown-item.danger { color: var(--error); }
.dropdown-item.danger:hover { background: rgba(231,76,60,0.06); }

@keyframes slideDown {
  from { transform: translateY(-6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Loading Spinner ────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

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

/* ── Focus Styles ───────────────────────────────────────── */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── Animations ─────────────────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.animate-pulse { animation: pulse 2s ease infinite; }
