:root {
    --bg: #faf9f7;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #e5e3df;
    --border-hover: #d4d1cb;
    --fg: #1a1817;
    --muted: #6b6560;
    --accent: #6366f1;
    --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: rgba(129, 140, 248, 0.15);
    --accent-glow: rgba(129, 140, 248, 0.2);
    --secondary: #2dd4bf;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --input-bg: #0f0f14;
    --pattern-opacity: 0.05;
}

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

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 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;
    line-height: 1.5;
}

.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); } }

.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 { 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 { 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 { 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; flex-wrap: wrap; gap: 0.5rem; }
.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; }

.calc-section { background: var(--bg); border-radius: 12px; padding: 1rem; }
.calc-title { font-size: 0.9rem; font-weight: 600; color: var(--fg); margin-bottom: 0.75rem; }
.calc-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.9rem; }
.calc-row span { color: var(--muted); }

.input-small { 
    width: 80px; 
    padding: 10px 12px; 
    background: var(--input-bg); 
    border: 2px solid var(--border); 
    border-radius: 8px; 
    font-size: 14px; 
    color: var(--fg); 
    font-family: 'JetBrains Mono', monospace;
    transition: all 0.2s; 
}
.input-small:focus { outline: none; border-color: var(--accent); }

.btn-calc {
    width: 40px;
    height: 40px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-calc:hover { transform: scale(1.05); filter: brightness(1.1); }

.result-badge {
    padding: 8px 16px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 8px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    min-width: 80px;
    text-align: center;
}

.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-group label { font-size: 0.9rem; font-weight: 600; color: var(--fg); }
.input-field { 
    width: 100%; 
    background: var(--input-bg); 
    border: 2px solid var(--border); 
    border-radius: 10px; 
    padding: 12px 14px; 
    font-size: 14px; 
    color: var(--fg); 
    font-family: inherit; 
    transition: all 0.2s; 
}
.input-field:focus { outline: none; border-color: var(--accent); }

.results-header { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-top: 0.5rem; margin-bottom: 0.5rem; }

.quick-table { background: var(--bg); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.table-container { max-height: 200px; overflow-y: auto; }
.table-row { display: flex; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.table-row:last-child { border-bottom: none; }
.table-row:hover { background: var(--accent-light); border-radius: 6px; }
.table-percent { font-weight: 600; color: var(--accent); }
.table-value { font-family: 'JetBrains Mono', monospace; }

.history-list { max-height: 200px; overflow-y: auto; }
.history-item { 
    background: var(--bg); 
    border-radius: 10px; 
    padding: 10px 12px; 
    margin-bottom: 8px; 
    border-left: 3px solid var(--accent);
    font-size: 0.85rem;
}
.history-item:hover { background: var(--accent-light); }

.empty-state { text-align: center; padding: 1.5rem; color: var(--muted); opacity: 0.7; }
.empty-state svg { width: 40px; height: 40px; stroke: currentColor; fill: none; stroke-width: 1.5; margin-bottom: 0.5rem; }

.actions-row { display: flex; gap: 1rem; margin-top: 1.5rem; flex-wrap: wrap; }

.btn-action { 
    flex: 1; 
    min-width: 200px; 
    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; 
    font-family: inherit;
}
.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); }

.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.15); transform: translateY(100px); opacity: 0; transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); z-index: 1001; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast svg { width: 20px; height: 20px; stroke: var(--accent); fill: none; flex-shrink: 0; }

.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) {
    h1 { font-size: 2rem; }
    .calc-row { font-size: 0.8rem; }
    .input-small { width: 60px; padding: 8px 10px; }
    .actions-row { flex-direction: column; }
    .btn-action { width: 100%; min-width: auto; }
}
