/**
 * Navix - IC UI Design System
 * Case Western Reserve University Brand Guidelines
 *
 * Color Palette:
 * - CWRU Blue (Primary): #003071 - Dominant (45%+)
 * - CWRU True Blue: #007AB8 - Interactive elements
 * - CWRU Dark Blue: #09143A - Deep accents
 * - CWRU Light Blue: #A6D2E6 - Subtle backgrounds
 * - Success Green: #61A530
 * - Warning Yellow: #FF9239
 * - Error Orange: #D63D1F
 */

/* CSS Custom Properties - CWRU Brand Colors */
:root {
    /* Primary Palette */
    --cwru-blue: #003071;
    --cwru-true-blue: #007AB8;
    --cwru-dark-blue: #09143A;
    --cwru-light-blue: #A6D2E6;

    /* Neutrals */
    --black: #000000;
    --dark-gray: #999999;
    --light-gray: #D3D3D3;
    --white: #FFFFFF;

    /* Tertiary/Status Colors */
    --success-green: #61A530;
    --warning-yellow: #FF9239;
    --error-orange: #D63D1F;

    /* Spacing (8pt grid) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-body: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 20px;
    --font-size-2xl: 24px;
    --font-size-3xl: 28px;
    --font-size-4xl: 34px;

    /* Component Sizing (IC UI minimums) */
    --button-height: 48px;
    --input-height: 48px;
    --nav-height: 64px;
    --touch-target: 48px;
    --card-radius: 16px;
    --button-radius: 12px;
    --input-radius: 10px;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 48, 113, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 48, 113, 0.15);
    --shadow-lg: 0 8px 16px rgba(0, 48, 113, 0.2);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    line-height: 1.5;
    color: var(--black);
    background: linear-gradient(180deg, var(--cwru-blue) 0%, var(--cwru-dark-blue) 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Main Container */
.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    max-width: 480px;
    margin: 0 auto;
    padding: var(--space-md);
    padding-top: env(safe-area-inset-top, var(--space-md));
    padding-bottom: env(safe-area-inset-bottom, var(--space-md));
}

/* Header - App Bar Style */
header {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    margin-bottom: var(--space-lg);
}

header h1 {
    font-size: var(--font-size-4xl);
    font-weight: 700;
    color: var(--white);
    letter-spacing: -0.5px;
    margin-bottom: var(--space-sm);
}

header .subtitle {
    font-size: var(--font-size-lg);
    color: var(--cwru-light-blue);
    font-weight: 400;
}

/* Main Content Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Input Group - Card Style */
.input-group {
    background: var(--white);
    border-radius: var(--card-radius);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
}

.input-group label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--cwru-blue);
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input {
    width: 100%;
    height: var(--input-height);
    padding: 0 var(--space-md);
    font-size: var(--font-size-2xl);
    font-weight: 600;
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    text-align: center;
    letter-spacing: 8px;
    border: 2px solid var(--light-gray);
    border-radius: var(--input-radius);
    background: var(--white);
    color: var(--cwru-dark-blue);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--cwru-true-blue);
    box-shadow: 0 0 0 4px rgba(0, 122, 184, 0.15);
}

.input-group input::placeholder {
    color: var(--light-gray);
    letter-spacing: 8px;
}

/* Status Indicator - Card Style */
.status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--white);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-sm);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.status-dot.disconnected {
    background-color: var(--dark-gray);
}

.status-dot.connecting {
    background-color: var(--warning-yellow);
    animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.connected {
    background-color: var(--success-green);
}

.status-dot.error {
    background-color: var(--error-orange);
}

.status-text {
    font-size: var(--font-size-body);
    font-weight: 500;
    color: var(--cwru-dark-blue);
}

/* Primary Button - CWRU Blue */
.btn-connect {
    width: 100%;
    height: var(--button-height);
    padding: 0 var(--space-lg);
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--white);
    background: var(--cwru-blue);
    border: none;
    border-radius: var(--button-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-md);
}

.btn-connect:hover:not(:disabled) {
    background: var(--cwru-dark-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-connect:active:not(:disabled) {
    transform: translateY(0);
    opacity: 0.95;
}

.btn-connect:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Secondary Button Style when connected - high visibility */
.btn-connect.connected {
    background: var(--white);
    color: var(--cwru-blue);
    border: 2px solid var(--cwru-blue);
    box-shadow: var(--shadow-lg);
}

.btn-connect.connected:hover:not(:disabled) {
    background: var(--cwru-light-blue);
    color: var(--cwru-dark-blue);
    border-color: var(--cwru-dark-blue);
}

/* Mute Button Container - Card Style */
.mute-container {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-xl);
    background: var(--white);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-md);
}

.mute-container.visible {
    display: flex;
}

/* Large Circular Mute Button - 96px for large touch target */
.btn-mute {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--cwru-true-blue);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-lg);
}

.btn-mute:hover {
    transform: scale(1.05);
}

.btn-mute:active {
    transform: scale(0.98);
}

.btn-mute .mic-icon,
.btn-mute .muted-icon {
    width: 40px;
    height: 40px;
    color: var(--white);
}

.btn-mute .muted-icon {
    display: none;
}

.btn-mute.muted {
    background: var(--error-orange);
}

.btn-mute.muted .mic-icon {
    display: none;
}

.btn-mute.muted .muted-icon {
    display: block;
}

.mute-label {
    font-size: var(--font-size-body);
    font-weight: 500;
    color: var(--cwru-dark-blue);
}

/* Audio Level Indicator */
.audio-level {
    display: none;
    width: 100%;
    height: 8px;
    background: var(--light-gray);
    border-radius: 4px;
    overflow: hidden;
    margin-top: var(--space-sm);
}

.audio-level.visible {
    display: block;
}

.level-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--cwru-true-blue), var(--success-green));
    border-radius: 4px;
    transition: width 0.05s ease-out;
}

/* Footer */
footer {
    text-align: center;
    padding: var(--space-lg) var(--space-md);
    margin-top: auto;
}

footer p {
    font-size: var(--font-size-sm);
    color: var(--cwru-light-blue);
}

/* Error Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(9, 20, 58, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    z-index: 1000;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: var(--card-radius);
    padding: var(--space-xl);
    max-width: 320px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--error-orange);
    margin-bottom: var(--space-md);
}

.modal-content p {
    font-size: var(--font-size-body);
    color: var(--cwru-dark-blue);
    margin-bottom: var(--space-lg);
    line-height: 1.6;
}

.btn-close {
    width: 100%;
    height: var(--button-height);
    font-size: var(--font-size-body);
    font-weight: 600;
    color: var(--white);
    background: var(--cwru-blue);
    border: none;
    border-radius: var(--button-radius);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-close:hover {
    background: var(--cwru-dark-blue);
}

/* Hidden utility class */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* Speaking Animation for Mute Button */
.btn-mute.speaking {
    animation: speaking-pulse 1s ease-in-out infinite;
}

@keyframes speaking-pulse {
    0%, 100% {
        box-shadow: var(--shadow-lg);
    }
    50% {
        box-shadow: 0 0 0 12px rgba(0, 122, 184, 0.2), var(--shadow-lg);
    }
}

/* Responsive Adjustments for smaller screens */
@media (max-width: 360px) {
    :root {
        --font-size-4xl: 28px;
        --font-size-3xl: 24px;
    }

    .input-group input {
        font-size: var(--font-size-xl);
        letter-spacing: 6px;
    }

    .btn-mute {
        width: 80px;
        height: 80px;
    }

    .btn-mute .mic-icon,
    .btn-mute .muted-icon {
        width: 32px;
        height: 32px;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) {
    header {
        padding: var(--space-md);
        margin-bottom: var(--space-md);
    }

    header h1 {
        font-size: var(--font-size-2xl);
    }

    main {
        gap: var(--space-md);
    }

    .mute-container {
        padding: var(--space-md);
    }

    .btn-mute {
        width: 64px;
        height: 64px;
    }

    .btn-mute .mic-icon,
    .btn-mute .muted-icon {
        width: 28px;
        height: 28px;
    }

    footer {
        padding: var(--space-md);
    }
}

/* Desktop/Tablet Enhancements */
@media (min-width: 768px) {
    .container {
        padding: var(--space-xl);
        justify-content: center;
    }

    header {
        padding: var(--space-xxl) var(--space-lg);
    }

    .input-group,
    .status,
    .mute-container {
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
    }

    .btn-connect {
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
        display: block;
    }
}

/* Accessibility - Focus States */
.btn-connect:focus-visible,
.btn-mute:focus-visible,
.btn-close:focus-visible,
input:focus-visible {
    outline: 3px solid var(--cwru-true-blue);
    outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Safe area insets for notched phones */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
