:root {
    --color-primary: #e73c3e;
    --color-primary-dark: #cc2a2d;
    --color-secondary: #2c3e50;

    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-hover: #f1f5f9;
    --color-text-main: #1a1c1e;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-border-hover: #cbd5e1;
    --color-shadow: rgba(0, 0, 0, 0.05);

    --font-main: 'Inter', -apple-system, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-xl: 12px;
    --radius-lg: 8px;
    --radius-md: 6px;

    --header-height: 72px;
    --max-width: 1200px;
}

[data-theme='dark'] {
    --color-bg: #0f1115;
    --color-surface: #1a1d23;
    --color-surface-hover: #22262e;
    --color-text-main: #f3f4f6;
    --color-text-muted: #9ca3af;
    --color-border: #2d323b;
    --color-border-hover: #4b5563;
    --color-shadow: rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

/* --- Improved Navigation --- */
.navbar {
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-container {
    max-width: var(--max-width);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-text-main);
    text-decoration: none;
    letter-spacing: -0.04em;
    display: flex;
    align-items: center;
}

.nav-brand span {
    color: var(--color-primary);
}

.brand-logo {
    height: 43px;
    width: auto;
    object-fit: contain;
}

.brand-logo-dark {
    display: none;
}

[data-theme='dark'] .brand-logo-light {
    display: none;
}

[data-theme='dark'] .brand-logo-dark {
    display: block;
}

.footer-logo-wrap {
    margin-bottom: 12px;
}

.footer-logo-wrap .brand-logo {
    height: 50px;
}

.nav-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-link {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-text-main);
    background: var(--color-surface-hover);
}

.nav-link.active {
    color: var(--color-primary);
}

.nav-auth {
    display: flex;
    gap: 8px;
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid var(--color-border);
}

.btn-auth-outline {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-main);
    text-decoration: none;
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.btn-auth-outline:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
}

.btn-auth-primary {
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    background: var(--color-primary);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.btn-auth-primary:hover {
    background: var(--color-primary-dark);
}

/* --- Hero Section --- */
.converter-hero {
    padding: 40px 20px 30px;
    text-align: center;
}

.accent-title {
    font-size: 2.25rem;
    font-weight: 800;
    margin: 0 0 8px;
    color: var(--color-primary);
    letter-spacing: -0.02em;
}

.accent-title span {
    color: var(--color-text-main);
}

.converter-hero p {
    font-size: 1rem;
    color: var(--color-text-muted);
}

/* --- Logic Container --- */
.container-narrow {
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    padding: 0 20px;
}

.converter-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 20px var(--color-shadow);
    overflow: hidden;
    margin-bottom: 40px;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.stats-bar {
    display: flex;
    gap: 20px;
}

.stat {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat span {
    color: var(--color-text-main);
    font-variant-numeric: tabular-nums;
}

textarea,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"] {
    width: 100%;
    background: var(--color-surface);
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
    font-family: inherit;
    transition: all 0.2s;
    outline: none;
}

textarea {
    border: none;
    padding: 24px;
    font-family: var(--font-mono);
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 380px;
}

.editor-textarea {
    width: 100%;
    padding: 24px;
    border: none;
    background: var(--color-surface);
    color: var(--color-text-main);
    font-family: var(--font-mono);
    font-size: 1rem;
    resize: vertical;
}

textarea:focus {
    background: var(--color-surface-hover);
}

/* --- Dashboard Grids --- */
.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    padding: 24px;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
}

.control-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.control-card h3 {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    margin: 0 0 16px;
}

.btn-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

/* --- Reusable Buttons --- */
.btn {
    font-family: inherit;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 800;
}

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

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

.btn-outline {
    color: var(--color-text-muted);
}

.btn-outline:hover {
    color: var(--color-text-main);
}

.btn-large {
    padding: 14px 28px;
    font-size: 0.95rem;
}

.converter-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
}

/* --- Specialized Components --- */
.upload-prompt {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-xl);
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin: 24px;
}

.upload-prompt:hover {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
}

.upload-prompt .icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    display: block;
}

/* Financial Component Styles */
.input-group-pro {
    margin-bottom: 24px;
}

.input-group-pro label {
    display: block;
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--color-text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pro-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.pro-input-wrapper input {
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    font-size: 1.1rem;
    font-weight: 700;
}

.pro-input-wrapper .pre,
.pro-input-wrapper .suf {
    position: absolute;
    color: var(--color-text-muted);
    font-weight: 700;
    pointer-events: none;
}

.pro-input-wrapper .pre {
    left: 16px;
}

.pro-input-wrapper .suf {
    right: 16px;
}

.pro-input-wrapper:has(.pre) input {
    padding-left: 36px;
}

.pro-input-wrapper:has(.suf) input {
    padding-right: 36px;
}

/* --- Popover System (Strict Grid Layout) --- */
.format-popover {
    position: absolute;
    width: 500px;
    height: 480px;
    /* Fixed total height */
    background: #18181b;
    border: 1px solid #3f3f46;
    border-radius: 8px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: none;
    /* Toggled by JS */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #e4e4e7;

    /* Strict 2-Row Layout */
    display: none;
    /* Overridden to grid when active */
    grid-template-rows: auto 1fr;
}

.format-popover.active {
    display: grid;
}

/* Row 1: Header/Search */
.popover-header {
    padding: 16px 20px;
    border-bottom: 1px solid #27272a;
    background: #18181b;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-icon {
    font-size: 1rem;
    color: #a1a1aa;
}

.search-box input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: #e4e4e7;
    padding: 0;
}

.search-box input::placeholder {
    color: #52525b;
}

.search-box input:focus {
    outline: none;
}

/* Row 2: Body (Split Columns) */
.popover-body {
    display: grid;
    grid-template-columns: 140px 1fr;
    /* Exact Strict Columns */
    overflow: hidden;
    /* Contain scroll */
}

/* Col 1: Tabs */
.popover-sidebar {
    padding: 12px 0;
    border-right: 1px solid #27272a;
    background: #18181b;
    display: flex;
    flex-direction: column;
}

.category-item {
    padding: 12px 20px;
    font-size: 0.9rem;
    color: #a1a1aa;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: none;
    transition: color 0.1s;
}

.category-item:hover {
    color: #e4e4e7;
}

.category-item.active {
    color: #fff;
    font-weight: 500;
}

.category-item.active::after {
    content: "›";
    font-size: 1.2rem;
    line-height: 1;
    color: #fff;
}

/* Col 2: Grid */
.popover-main {
    padding: 24px;
    background: #18181b;
    overflow-y: auto;
}

.format-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.format-btn {
    background: #27272a;
    border: none;
    color: #e4e4e7;
    padding: 14px 0;
    text-align: center;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.format-btn:hover {
    background: #3f3f46;
    color: #fff;
}

/* --- Site Footer --- */
.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 60px 0 30px;
    margin-top: 60px;
}

.footer-columns {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    gap: 40px;
}

.footer-brand h2 {
    font-weight: 800;
    letter-spacing: -0.04em;
    margin-bottom: 12px;
}

.footer-brand p {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    line-height: 1.6;
}

.footer-col h4 {
    margin: 0 0 20px;
    font-weight: 800;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
}

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

.footer-links li {
    margin-bottom: 10px;
}

.footer-links a {
    color: var(--color-text-main);
    opacity: 0.7;
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.footer-links a:hover {
    opacity: 1;
    color: var(--color-primary);
    padding-left: 4px;
}

.footer-bottom {
    margin-top: 40px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Auth Pages */
.auth-box {
    max-width: 400px;
    margin: 80px auto;
    background: var(--color-surface);
    padding: 40px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    box-shadow: 0 10px 40px var(--color-shadow);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header h2 {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

/* UI Helpers */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-secondary);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2100;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--color-surface);
    color: var(--color-text-main);
    transition: all 0.2s;
    margin-left: 8px;
}

/* File List Items */
.converter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    /* Prevents flex overflow */
}

.file-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.file-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 24px;
}

.to-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 600;
}

.format-select-trigger {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.file-meta {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-badge {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid transparent;
    text-transform: uppercase;
}

.file-size {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.remove-file {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
}

.remove-file:hover {
    color: var(--color-primary);
}

.theme-toggle:hover {
    border-color: var(--color-primary);
    background: var(--color-bg);
}

.conversion-summary {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 600;
}

.status-badge.done {
    color: #2fb344;
    background: rgba(47, 179, 68, 0.1);
    border-color: #2fb344;
}

.status-badge.error {
    color: #d63939;
    background: rgba(214, 57, 57, 0.1);
    border-color: #d63939;
}

.status-badge.converting {
    color: #f76707;
    background: rgba(247, 103, 7, 0.1);
    border-color: #f76707;
}

/* Features Grid Pro */
.features-grid-pro {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 32px;
    margin-top: 60px;
    margin-bottom: 80px;
}

.feature-item-pro {
    text-align: left;
    padding: 32px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    transition: transform 0.2s;
}

.feature-item-pro:hover {
    transform: translateY(-4px);
    border-color: var(--color-primary);
}

.feature-item-pro .feature-icon {
    font-size: 2rem;
    margin-bottom: 20px;
}

.feature-item-pro h3 {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 12px;
}

.feature-item-pro p {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.6;
}

/* --- Margin Calculator --- */
.margin-calc-grid {
    padding: 40px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
}

.margin-inputs {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.btn-lock {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-lock:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-surface-hover);
}

.btn-lock .lock-icon {
    width: 16px;
    height: 16px;
}

.btn-lock .lock-closed {
    display: none;
}

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

.btn-lock.locked .lock-open {
    display: none;
}

.btn-lock.locked .lock-closed {
    display: block;
}

.lock-suf {
    right: 48px !important;
}

.pro-input-wrapper:has(.btn-lock) input {
    padding-right: 52px;
}

.pro-input-wrapper:has(.lock-suf) input {
    padding-right: 72px;
}

.results-card {
    background: var(--color-bg);
    padding: 28px;
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.results-card + .results-card {
    margin-top: 16px;
}

.results-heading {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--color-text-muted);
    letter-spacing: 0.1em;
    margin: 0;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.result-label {
    color: var(--color-text-muted);
}

.result-value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    transition: color 0.2s;
}

.result-value:hover {
    color: var(--color-primary);
}

.result-value.negative {
    color: #d63939;
}

.result-divider {
    border-top: 1px solid var(--color-border);
    margin: 4px 0;
}

.result-total {
    font-size: 1.4rem;
}

.result-total .result-label {
    font-weight: 800;
    color: var(--color-text-main);
}

.result-total .result-value {
    font-weight: 800;
}

.margin-quick-ref {
    margin-top: 32px;
    margin-bottom: 40px;
    text-align: center;
}

.quick-ref-title {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.quick-ref-chips {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.chip {
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 8px 18px;
    border: 1px solid var(--color-border);
    border-radius: 50px;
    background: var(--color-surface);
    color: var(--color-text-main);
    cursor: pointer;
    transition: all 0.2s;
}

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

.chip.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

/* Responsive Adjustments */
@media (max-width: 900px) {
    .footer-columns {
        grid-template-columns: 1fr 1fr;
    }

    .nav-links .nav-link {
        display: none;
    }

    .nav-links .nav-link.active {
        display: block;
    }

    .margin-calc-grid {
        grid-template-columns: 1fr;
        padding: 24px;
        gap: 24px;
    }
}

@media (max-width: 600px) {
    .footer-columns {
        grid-template-columns: 1fr;
    }

    .stats-bar {
        gap: 10px;
        flex-wrap: wrap;
    }

    .btn-large {
        width: 100%;
    }
}