/* --- CSS Variables --- */
:root {
    --bg: #faf9f7;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #e5e3df;
    --border-hover: #d4d1cb;
    --fg: #1a1817;
    --muted: #6b6560;
    --accent: #6366f1; /* Indigo */
    --accent-light: #e0e7ff;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --secondary: #14b8a6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --input-bg: #ffffff;
    --pattern-opacity: 0.3;
}

[data-theme="dark"] {
    --bg: #0a0a0f;
    --bg-elevated: #12121a;
    --card: #16161f;
    --border: #2a2a3a;
    --border-hover: #3a3a4a;
    --fg: #e8e8ed;
    --muted: #6b6b7a;
    --accent: #818cf8;
    --accent-light: #818cf820;
    --accent-glow: rgba(129, 140, 248, 0.2);
    --secondary: #2dd4bf;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --input-bg: #0f0f14;
    --pattern-opacity: 0.05;
}

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

body {
    font-family: 'Space Grotesk', sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* --- Background --- */
.bg-decoration { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-pattern { position: absolute; inset: 0; background-image: radial-gradient(circle, var(--muted) 1px, transparent 1px); background-size: 24px 24px; opacity: var(--pattern-opacity); }
.gradient-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.4; animation: float 20s ease-in-out infinite; }
.orb-1 { width: 500px; height: 500px; background: linear-gradient(135deg, #a5b4fc, #818cf8); top: -150px; right: -100px; }
.orb-2 { width: 400px; height: 400px; background: linear-gradient(135deg, #5eead4, #2dd4bf); bottom: -100px; left: -100px; animation-delay: -5s; }
[data-theme="dark"] .orb-1 { background: var(--accent); opacity: 0.15; }
[data-theme="dark"] .orb-2 { background: var(--secondary); opacity: 0.15; }
@keyframes float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(30px, 20px) scale(1.05); } }

/* --- Layout --- */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1rem; }
.main-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 900px) { .main-grid { grid-template-columns: 1fr 1fr; } }

/* --- Header --- */
header { text-align: center; margin-bottom: 2rem; }
.header-top { display: flex; justify-content: center; margin-bottom: 1rem; }
.status-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 50px; border: 1px solid var(--border); background: var(--card); font-size: 14px; color: var(--muted); }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
h1 { font-size: 2.5rem; font-weight: 700; letter-spacing: -1px; margin-bottom: 0.5rem; }
h1 span { color: var(--accent); }
.subtitle { color: var(--muted); font-size: 1.1rem; }

/* --- Theme Toggle --- */
.theme-toggle { position: fixed; top: 1.5rem; right: 1.5rem; z-index: 100; width: 48px; height: 48px; border-radius: 50%; background: var(--card); border: 2px solid var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.theme-toggle:hover { transform: rotate(15deg) scale(1.1); border-color: var(--accent); background: var(--accent-light); }
.theme-toggle svg { width: 24px; height: 24px; stroke: var(--fg); fill: none; stroke-width: 2; }

/* --- Panel --- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 1.5rem; box-shadow: 0 4px 24px rgba(0,0,0,0.03); display: flex; flex-direction: column; gap: 1rem; }
.panel-header { display: flex; justify-content: space-between; align-items: center; }
.label { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.label svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* --- Tab Switcher --- */
.tab-switcher { display: flex; background: var(--bg); padding: 4px; border-radius: 10px; }
.switch-btn { flex: 1; padding: 8px; border: none; background: transparent; border-radius: 8px; font-weight: 600; font-size: 0.9rem; color: var(--muted); cursor: pointer; transition: all 0.2s; }
.switch-btn.active { background: var(--card); color: var(--accent); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

/* --- Inputs --- */
.input-field { width: 100%; background: var(--input-bg); border: 2px solid var(--border); border-radius: 12px; padding: 12px 16px; font-size: 14px; color: var(--fg); font-family: inherit; transition: all 0.2s; }
.input-field:focus { outline: none; border-color: var(--accent); }

.url-input-group { display: flex; gap: 0.5rem; }
.btn-fetch { background: var(--accent); color: white; border: none; border-radius: 12px; padding: 0 20px; cursor: pointer; display: flex; align-items: center; gap: 5px; transition: all 0.2s; }
.btn-fetch svg { width: 18px; height: 18px; stroke: currentColor; fill: none; }
.btn-fetch:hover { filter: brightness(1.1); }
.btn-fetch:disabled { opacity: 0.7; cursor: not-allowed; }

.fetch-status { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--accent-light); border-radius: 8px; color: var(--accent); font-size: 0.9rem; margin-top: 0.5rem; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.code-area { width: 100%; flex: 1; min-height: 200px; background: var(--input-bg); border: 2px solid var(--border); border-radius: 12px; padding: 1rem; font-size: 14px; line-height: 1.6; color: var(--fg); resize: vertical; }
.code-area:focus { outline: none; border-color: var(--accent); }

.keywords-group label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; }
.keywords-group small { color: var(--muted); font-weight: 400; }
.keyword-area { width: 100%; height: 80px; background: var(--input-bg); border: 2px solid var(--border); border-radius: 12px; padding: 12px; font-size: 14px; resize: none; }
.keyword-area:focus { outline: none; border-color: var(--accent); }

/* --- Stats --- */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box { background: var(--bg); border-radius: 12px; padding: 12px; text-align: center; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; margin-top: 4px; }
.stat-value.accent { color: var(--accent); }
.stat-value.secondary { color: var(--secondary); }

/* --- Results List --- */
.results-header { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-top: 0.5rem; }
.results-list { flex: 1; overflow-y: auto; max-height: 250px; margin-bottom: 1rem; }
.empty-state { text-align: center; padding: 2rem; color: var(--muted); opacity: 0.6; }
.empty-state svg { width: 40px; height: 40px; stroke: currentColor; fill: none; margin-bottom: 0.5rem; }

.result-item { display: flex; align-items: center; justify-content: space-between; padding: 12px; background: var(--bg); border-radius: 10px; margin-bottom: 8px; transition: all 0.2s; }
.result-item:hover { background: var(--accent-light); }
.result-info h4 { font-size: 1rem; margin-bottom: 2px; }
.result-info p { font-size: 0.8rem; color: var(--muted); }
.result-meta { text-align: right; }
.result-count { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.result-density { font-size: 0.8rem; color: var(--muted); }

.density-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 20px; margin-left: 8px; font-weight: 600; }
.badge-low { background: #dbeafe; color: #1d4ed8; }
.badge-ideal { background: #d1fae5; color: #059669; }
.badge-high { background: #fee2e2; color: #dc2626; }

/* --- Highlight Box --- */
.highlight-header { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 0.5rem; }
.highlight-box { background: var(--input-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; min-height: 120px; max-height: 200px; overflow-y: auto; font-size: 14px; line-height: 1.6; }
.placeholder-text { color: var(--muted); opacity: 0.5; text-align: center; margin-top: 2rem; }

mark { background: var(--accent-light); color: var(--accent); padding: 0.1rem 0.2rem; border-radius: 3px; font-weight: 600; }

/* --- Buttons --- */
.actions-row { display: flex; gap: 1rem; margin-top: 1.5rem; }
.btn-action { flex: 1; padding: 14px; background: var(--accent); color: white; border: none; border-radius: 12px; font-weight: 600; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all 0.2s; }
.btn-action svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-action:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--accent-glow); filter: brightness(1.05); }
.btn-secondary { flex: 1; padding: 14px; background: var(--bg); color: var(--fg); border: 2px solid var(--border); border-radius: 12px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all 0.2s; }
.btn-secondary svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* --- Toast --- */
.toast { position: fixed; bottom: 2rem; right: 2rem; background: var(--card); border: 1px solid var(--accent); padding: 1rem 1.5rem; border-radius: 12px; display: flex; align-items: center; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); transform: translateY(100px); opacity: 0; transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); z-index: 1000; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast svg { width: 20px; height: 20px; stroke: var(--accent); fill: none; stroke-width: 2.5; }

/* Utility */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.6s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 768px) {
    .stats-row { grid-template-columns: 1fr; }
    .actions-row { flex-direction: column; }
}