/* CSS Variables for theming */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --secondary-color: #6366f1;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-focus: #4f46e5;
    --success: #10b981;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

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

/* Container */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 32px;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.025em;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* Main content */
main {
    flex: 1;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

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

.tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex: 1;
    min-width: 70px;
    font-size: 0.875rem;
    font-weight: 500;
}

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

.tab-btn.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.tab-icon {
    font-size: 1.25rem;
}

.tab-text {
    white-space: nowrap;
}

/* Converter Panel */
.converter-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

/* Presets Section */
.presets-section {
    margin-bottom: 24px;
}

.presets-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.presets-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.preset-btn {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.813rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

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

.preset-btn.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Conversion Area */
.conversion-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.unit-section {
    width: 100%;
}

.unit-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-group {
    display: flex;
    gap: 12px;
}

.unit-input {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--surface);
    transition: var(--transition);
    min-width: 0;
}

.unit-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.unit-input::placeholder {
    color: var(--text-muted);
}

.unit-input[readonly] {
    background: var(--surface-hover);
    cursor: default;
}

.unit-select {
    width: 140px;
    padding: 14px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.938rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.unit-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Swap Button */
.swap-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.swap-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: rotate(180deg);
}

.swap-btn:active {
    transform: rotate(180deg) scale(0.95);
}

/* Formula Display */
.formula-display {
    margin-top: 24px;
    padding: 16px;
    background: var(--surface-hover);
    border-radius: var(--radius-md);
    text-align: center;
}

#formula-text {
    font-size: 0.938rem;
    color: var(--text-secondary);
    word-break: break-word;
}

#formula-text strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Copy Button */
.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 24px;
    margin-top: 16px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary-color);
    color: white;
    font-size: 0.938rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.copy-btn:hover {
    background: var(--primary-hover);
}

.copy-btn:active {
    transform: scale(0.98);
}

.copy-btn.copied {
    background: var(--success);
}

/* Reference Section */
.reference-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

.reference-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.reference-table-container {
    overflow-x: auto;
}

.reference-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.reference-table th,
.reference-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.reference-table th {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.reference-table td {
    color: var(--text-primary);
}

.reference-table tbody tr:hover {
    background: var(--surface-hover);
}

.reference-table tbody tr:last-child td {
    border-bottom: none;
}

/* Footer */
footer {
    text-align: center;
    padding: 24px 0;
    margin-top: auto;
}

footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 16px 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.875rem;
    }

    .tab-btn {
        padding: 10px 12px;
        min-width: 60px;
    }

    .tab-icon {
        font-size: 1.125rem;
    }

    .tab-text {
        font-size: 0.75rem;
    }

    .converter-panel {
        padding: 16px;
    }

    .input-group {
        flex-direction: column;
        gap: 8px;
    }

    .unit-input {
        font-size: 1.125rem;
        padding: 12px 14px;
    }

    .unit-select {
        width: 100%;
    }

    .swap-btn {
        transform: rotate(90deg);
    }

    .swap-btn:hover {
        transform: rotate(270deg);
    }

    .preset-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .reference-section {
        padding: 16px;
    }

    .reference-table th,
    .reference-table td {
        padding: 8px;
    }
}

/* Animation for result update */
@keyframes highlight {
    0% {
        background-color: var(--primary-light);
    }
    100% {
        background-color: var(--surface-hover);
    }
}

.unit-input.highlight {
    animation: highlight 0.5s ease;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--text-primary);
    color: white;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    visibility: visible;
}

/* Dark mode support (follows system preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #818cf8;
        --primary-hover: #a5b4fc;
        --primary-light: rgba(129, 140, 248, 0.15);
        --background: #0f172a;
        --surface: #1e293b;
        --surface-hover: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: #334155;
        --border-focus: #818cf8;
    }

    .unit-select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    }
}
