/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #253349;
    --accent: #60a5fa;
    --accent-bold: #3b82f6;
    --accent-purple: #7c3aed;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(96, 165, 250, 0.4);
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    --gradient-header: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* ===== TOP BAR ===== */
.top-bar {
    background: var(--gradient-header);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.top-bar h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.precision-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.precision-control label {
    font-size: 0.82rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.75);
}

.precision-control select {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.precision-control select:focus {
    border-color: rgba(255, 255, 255, 0.4);
}

.precision-control select option {
    background: var(--surface);
    color: var(--text-primary);
}

/* ===== CATEGORY TABS ===== */
.category-tabs {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 65px;
    z-index: 99;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.category-tabs-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    gap: 4px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 12px 16px;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    position: relative;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-btn .tab-icon {
    display: inline-block;
    margin-right: 6px;
    font-size: 0.95rem;
    vertical-align: -1px;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== INPUT PANEL ===== */
.input-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.input-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-group {
    flex: 1;
    min-width: 0;
}

.input-group input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input::placeholder {
    color: var(--text-dim);
    font-weight: 400;
}

.input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

/* Remove number input spinners */
.input-group input[type="number"]::-webkit-inner-spin-button,
.input-group input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.input-group input[type="number"] {
    -moz-appearance: textfield;
}

.unit-select-group {
    flex-shrink: 0;
}

.unit-select-group select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 14px 38px 14px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    transition: border-color 0.2s;
    min-width: 180px;
}

.unit-select-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.unit-select-group select option {
    background: var(--surface);
    color: var(--text-primary);
}

.swap-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--accent-bold);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.swap-btn svg {
    width: 20px;
    height: 20px;
}

.swap-btn:hover {
    background: var(--accent);
    transform: scale(1.05);
}

.swap-btn:active {
    transform: scale(0.96);
}

/* ===== RESULTS GRID ===== */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s;
    position: relative;
    overflow: hidden;
}

.result-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--accent-bold);
    opacity: 0;
    transition: opacity 0.2s;
}

.result-card:hover {
    border-color: var(--border-focus);
    background: var(--surface-hover);
    transform: translateY(-1px);
}

.result-card:hover::before {
    opacity: 1;
}

.result-card.is-source {
    border-color: var(--accent-bold);
    background: rgba(59, 130, 246, 0.08);
}

.result-card.is-source::before {
    opacity: 1;
    background: var(--accent);
}

.result-unit {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.result-unit .copy-hint {
    font-size: 0.7rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity 0.2s;
}

.result-card:hover .copy-hint {
    opacity: 1;
}

.result-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
    font-variant-numeric: tabular-nums;
}

.result-value.empty {
    color: var(--text-dim);
    font-weight: 400;
    font-size: 1rem;
}

.result-full-name {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* ===== FAVORITES SECTION ===== */
.favorites-section {
    border-top: 1px solid var(--border);
    padding-top: 24px;
}

.favorites-section.hidden {
    display: none;
}

.favorites-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.favorites-header h3 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.clear-favorites-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.clear-favorites-btn:hover {
    color: var(--text-secondary);
    border-color: var(--text-dim);
}

.favorites-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.fav-chip {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    white-space: nowrap;
}

.fav-chip:hover {
    background: var(--surface-hover);
    border-color: var(--border-focus);
    color: var(--accent);
}

.fav-chip .fav-value {
    color: var(--text-primary);
    font-weight: 600;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--accent-bold);
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 10px 24px;
    border-radius: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(37, 99, 235, 0.35);
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .top-bar-inner {
        padding: 12px 16px;
    }

    .top-bar h1 {
        font-size: 1.1rem;
    }

    .main-content {
        padding: 16px;
    }

    .input-panel {
        padding: 16px;
    }

    .input-row {
        flex-wrap: wrap;
    }

    .input-group {
        width: 100%;
        flex: unset;
    }

    .input-group input {
        font-size: 1.25rem;
        padding: 12px 14px;
    }

    .unit-select-group {
        flex: 1;
        min-width: 0;
    }

    .unit-select-group select {
        width: 100%;
        min-width: unset;
        padding: 12px 38px 12px 14px;
    }

    .swap-btn {
        width: 44px;
        height: 44px;
    }

    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
    }

    .result-card {
        padding: 12px 14px;
    }

    .result-value {
        font-size: 1.05rem;
    }

    .tab-btn {
        padding: 10px 12px;
        font-size: 0.78rem;
    }
}

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

    .precision-control label {
        display: none;
    }
}

/* ===== SCROLLBAR STYLING ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== ANIMATIONS ===== */
@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-card {
    animation: cardAppear 0.25s ease-out both;
}

.result-card:nth-child(1) { animation-delay: 0.02s; }
.result-card:nth-child(2) { animation-delay: 0.04s; }
.result-card:nth-child(3) { animation-delay: 0.06s; }
.result-card:nth-child(4) { animation-delay: 0.08s; }
.result-card:nth-child(5) { animation-delay: 0.10s; }
.result-card:nth-child(6) { animation-delay: 0.12s; }
.result-card:nth-child(7) { animation-delay: 0.14s; }
.result-card:nth-child(8) { animation-delay: 0.16s; }
.result-card:nth-child(9) { animation-delay: 0.18s; }
.result-card:nth-child(10) { animation-delay: 0.20s; }
.result-card:nth-child(11) { animation-delay: 0.22s; }
.result-card:nth-child(12) { animation-delay: 0.24s; }
.result-card:nth-child(13) { animation-delay: 0.26s; }
.result-card:nth-child(14) { animation-delay: 0.28s; }
.result-card:nth-child(15) { animation-delay: 0.30s; }
