/**
 * Unit Converter App Styles
 *
 * A production-ready unit converter with accessible, responsive design
 */

/* ========================================
   App Page Layout
   ======================================== */

.app-page {
    padding: var(--space-4);
    padding-top: calc(var(--header-height) + var(--space-4));
    min-height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.app-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.uc-container {
    max-width: 600px;
}

.app-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.app-header h1 {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--space-2);
}

.app-description {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    margin-bottom: 0;
}

/* ========================================
   Unit Converter
   ======================================== */

.unit-converter {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

/* ========================================
   Category Section
   ======================================== */

.uc-category-section {
    padding: var(--space-4) var(--space-6);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
}

.uc-category-section label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.uc-category-select {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--font-size-base);
    font-weight: 500;
}

/* ========================================
   Conversion Section
   ======================================== */

.uc-conversion-section {
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    align-items: center;
}

.uc-unit-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.uc-unit-group label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-muted);
}

.uc-select {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--font-size-sm);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    cursor: pointer;
}

.uc-select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.uc-input,
.uc-result {
    width: 100%;
    padding: var(--space-4);
    font-size: var(--font-size-xl);
    font-family: var(--font-mono);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-align: right;
    background: var(--color-bg-card);
    color: var(--color-text);
}

.uc-input {
    background: var(--color-bg-alt);
}

.uc-input:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.uc-result {
    background: var(--color-bg-alt);
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    word-break: break-all;
}

/* Remove spinner from number input */
.uc-input::-webkit-outer-spin-button,
.uc-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.uc-input[type='number'] {
    -moz-appearance: textfield;
}

/* ========================================
   Swap Button
   ======================================== */

.uc-swap-btn {
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast), transform 0.1s ease;
    flex-shrink: 0;
    transform: rotate(90deg);
}

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

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

.uc-swap-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

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

/* ========================================
   Action Buttons
   ======================================== */

.uc-actions {
    padding: var(--space-4) var(--space-6);
    background: var(--color-bg-card);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.uc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), transform 0.1s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    border: none;
}

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

.uc-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.uc-btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.uc-btn-icon:hover {
    background: var(--color-border);
    color: var(--color-text);
}

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

.uc-btn-icon.is-active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.uc-btn-icon.is-active svg {
    fill: currentColor;
}

.uc-btn-secondary {
    background: var(--color-bg-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    margin-left: auto;
}

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

.uc-btn-text {
    background: transparent;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    padding: var(--space-2);
}

.uc-btn-text:hover {
    color: var(--color-text);
    background: var(--color-bg-alt);
}

.uc-btn-success {
    background: #22c55e !important;
    color: white !important;
    border-color: #22c55e !important;
}

/* ========================================
   Favorites Section
   ======================================== */

.uc-favorites {
    padding: var(--space-4) var(--space-6);
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-border);
}

.uc-favorites[hidden] {
    display: none;
}

.uc-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
}

.uc-section-header h2 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin: 0;
    color: var(--color-text);
}

.uc-favorites-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.uc-favorite-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.uc-favorite-item:hover {
    background: var(--color-border);
    border-color: var(--color-primary-light);
}

.uc-favorite-item:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.uc-favorite-text {
    color: var(--color-text);
}

.uc-favorite-remove {
    width: 16px;
    height: 16px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
}

.uc-favorite-remove:hover {
    color: var(--color-error);
    background: rgba(239, 68, 68, 0.1);
}

.uc-empty-message {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-style: italic;
    margin: 0;
    padding: var(--space-2) 0;
}

.uc-empty-message[hidden] {
    display: none;
}

/* ========================================
   History Section
   ======================================== */

.uc-history {
    border-top: 1px solid var(--color-border);
}

.uc-history-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    background: var(--color-bg-card);
    border: none;
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    text-align: left;
}

.uc-history-toggle:hover {
    background: var(--color-bg-alt);
}

.uc-history-toggle:focus-visible {
    outline: none;
    box-shadow: inset var(--focus-ring);
}

.uc-chevron {
    width: 20px;
    height: 20px;
    color: var(--color-text-muted);
    transition: transform var(--transition-fast);
}

.uc-history-toggle[aria-expanded="true"] .uc-chevron {
    transform: rotate(180deg);
}

.uc-history-content {
    padding: 0 var(--space-6) var(--space-4);
    background: var(--color-bg-alt);
}

.uc-history-content[hidden] {
    display: none;
}

.uc-history-list {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-3) 0;
    max-height: 200px;
    overflow-y: auto;
}

.uc-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-2);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.uc-history-item:last-child {
    margin-bottom: 0;
}

.uc-history-item:hover {
    background: var(--color-border);
}

.uc-history-item:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.uc-history-conversion {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.uc-history-category {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    background: var(--color-bg-alt);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

/* ========================================
   Accessibility Announcements
   ======================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (min-width: 600px) {
    .uc-conversion-section {
        flex-direction: row;
        align-items: flex-end;
        gap: var(--space-4);
    }

    .uc-unit-group {
        flex: 1;
    }

    .uc-swap-btn {
        transform: rotate(0);
        margin-bottom: var(--space-2);
    }

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

@media (max-width: 600px) {
    .app-page {
        padding: var(--space-2);
        padding-top: calc(var(--header-height) + var(--space-2));
    }

    .app-header {
        margin-bottom: var(--space-4);
    }

    .uc-category-section,
    .uc-conversion-section,
    .uc-actions,
    .uc-favorites,
    .uc-history-toggle,
    .uc-history-content {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    .uc-input,
    .uc-result {
        font-size: var(--font-size-lg);
        padding: var(--space-3);
    }

    .uc-result {
        min-height: 48px;
    }
}

/* ========================================
   RTL Support
   ======================================== */

[dir="rtl"] .uc-input,
[dir="rtl"] .uc-result {
    text-align: left;
}

[dir="rtl"] .uc-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] .uc-btn-secondary {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .uc-history-toggle {
    text-align: right;
}

/* ========================================
   Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .uc-btn,
    .uc-swap-btn,
    .uc-select,
    .uc-input,
    .uc-chevron,
    .uc-favorite-item,
    .uc-history-item {
        transition: none;
    }

    .uc-btn:active,
    .uc-swap-btn:active {
        transform: none;
    }
}

/* ========================================
   Help Panel (Modal)
   ======================================== */

.help-panel {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.help-panel[hidden] {
    display: none;
}

.help-content {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    background: var(--color-bg-card);
}

.help-header h2 {
    font-size: var(--font-size-lg);
    margin: 0;
}

.help-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
}

.help-close:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.help-close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.help-body {
    padding: var(--space-6);
}

.help-section {
    margin-bottom: var(--space-6);
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-size: var(--font-size-base);
    margin-bottom: var(--space-4);
    color: var(--color-text);
}

.help-steps {
    margin: 0;
    padding-left: var(--space-5);
}

.help-steps li {
    margin-bottom: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.help-features {
    margin: 0;
    padding-left: var(--space-5);
}

.help-features li {
    margin-bottom: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* ========================================
   Header Actions
   ======================================== */

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    cursor: pointer;
}

.btn-icon:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.btn-icon:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .uc-actions,
    .uc-favorites,
    .uc-history,
    .help-panel,
    .nav-actions {
        display: none;
    }

    .unit-converter {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .uc-category-section,
    .uc-conversion-section {
        background: white;
    }
}
