:root {
    /* Brand Colors */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --accent: #f59e0b;
    /* Amber for highlights */
    --danger: #ef4444;
    --success: #22c55e;

    /* Light Theme Base */
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --input-bg: #ffffff;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Spacing & Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --header-height: 70px;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-header: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

/* Typography */
h1,
h2,
h3,
h4 {
    margin-top: 0;
    line-height: 1.2;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: var(--spacing-sm);
}

h2 {
    font-size: 1.5rem;
    margin-bottom: var(--spacing-sm);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: 0.2s;
}

a:hover {
    color: var(--primary-hover);
}

/* Layout Grid */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-sm);
}

.main-grid {
    display: grid;
    gap: var(--spacing-lg);
    padding: var(--spacing-lg) 0;
}

@media (min-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
        /* Calculator Left, Results Right */
        align-items: start;
    }

    .main-grid.single-col {
        grid-template-columns: 1fr;
    }
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--spacing-md);
    border: 1px solid var(--border);
}

/* Forms & Inputs */
.form-group {
    margin-bottom: var(--spacing-sm);
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

input,
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: 0.2s;
    font-size: 1rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.btn-block {
    width: 100%;
}

/* Utilities */
.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: .5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-4 {
    margin-top: 2rem;
}

.hidden {
    display: none !important;
}

.error-msg {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
}

input:invalid+.error-msg {
    display: block;
}

.result-box {
    background: var(--bg-body);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    text-align: center;
    margin-top: var(--spacing-md);
}

.result-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    display: block;
    word-break: break-all;
}

/* Components: Chips */
.chips {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.chip {
    background: var(--bg-body);
    border: 1px solid var(--border);
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: 0.2s;
}

.chip:hover {
    background: var(--border);
}

/* Components: Copy Button */
.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.relative {
    position: relative;
}

/* Header & Nav */
.app-header {
    background: var(--bg-header);
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}

.logo {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-menu {
    display: none;
}

/* Mobile first hidden */
.nav-desktop {
    display: none;
}

@media (min-width: 768px) {
    .nav-burger {
        display: none;
    }

    .nav-desktop {
        display: flex;
        gap: var(--spacing-md);
        align-items: center;
    }

    .nav-item {
        position: relative;
        cursor: pointer;
        padding: 0.5rem;
        font-weight: 500;
    }

    .dropdown {
        position: absolute;
        top: 100%;
        left: -50px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-lg);
        min-width: 250px;
        padding: 1rem;
        display: none;
        z-index: 1000;
        /* Ensure it stays on top */
    }

    .nav-item:hover .dropdown {
        display: block;
    }
}

/* Accordion */
.accordion-item {
    border-bottom: 1px solid var(--border);
}

.accordion-btn {
    width: 100%;
    text-align: left;
    padding: 1rem 0;
    background: none;
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    color: var(--text-main);
}

.accordion-content {
    display: none;
    padding-bottom: 1rem;
    color: var(--text-muted);
}

.accordion-btn[aria-expanded="true"]+.accordion-content {
    display: block;
}

.accordion-btn::after {
    content: '+';
    font-size: 1.25rem;
}

.accordion-btn[aria-expanded="true"]::after {
    content: '-';
}

/* Footer */
.app-footer {
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    padding: var(--spacing-lg) 0;
    margin-top: auto;
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
}

.footer-links ul {
    list-style: none;
    padding: 0;
}

.footer-links li {
    margin-bottom: 0.5rem;
}

/* Mobile Menu Overlay */
.mobile-menu {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 100%;
    height: calc(100vh - var(--header-height));
    background: var(--bg-body);
    padding: 1rem;
    transform: translateX(100%);
    transition: transform 0.3s;
    overflow-y: auto;
}

.mobile-menu.open {
    transform: translateX(0);
}

/* Mobile Accordion Styles */
.mobile-group {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.mobile-group summary {
    padding: 1rem 0;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    list-style: none;
    /* Hide default triangle */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mobile-group summary::-webkit-details-marker {
    display: none;
}

.mobile-group summary::after {
    content: '+';
    font-size: 1.5rem;
    color: var(--primary);
}

.mobile-group[open] summary::after {
    content: '-';
}

/* Input Error State */
.input-error {
    border-color: var(--danger) !important;
}

.input-error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}