/* ═══════════════════════════════════════════════════════════════
   SunCoach — Light Orange Theme, Responsive, Mobile-First
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Reset & Variables ──────────────────────────────────── */
:root {
    --orange-50:  #FFF8F0;
    --orange-100: #FFEDD5;
    --orange-200: #FED7AA;
    --orange-300: #FDBA74;
    --orange-400: #FB923C;
    --orange-500: #FF8C00;
    --orange-600: #EA7200;
    --orange-700: #C2410C;
    --orange-800: #9A3412;
    --white:      #FFFFFF;
    --gray-50:    #F9FAFB;
    --gray-100:   #F3F4F6;
    --gray-200:   #E5E7EB;
    --gray-300:   #D1D5DB;
    --gray-400:   #9CA3AF;
    --gray-500:   #6B7280;
    --gray-600:   #4B5563;
    --gray-700:   #374151;
    --gray-800:   #1F2937;
    --gray-900:   #111827;
    --danger:     #EF4444;
    --success:    #22C55E;
    --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);
    --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
    --radius:     12px;
    --radius-sm:  8px;
    --transition: 0.2s ease;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: var(--orange-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: var(--orange-600); text-decoration: none; }
a:hover { color: var(--orange-700); }

/* ── Page Layout ────────────────────────────────────────────── */
.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--white);
    border-bottom: 1px solid var(--orange-100);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    height: 36px;
    width: auto;
    object-fit: contain;
}

.header-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--orange-700);
    margin-left: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-logout {
    background: none;
    border: 1px solid var(--orange-300);
    color: var(--orange-600);
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-logout:hover {
    background: var(--orange-100);
    border-color: var(--orange-400);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* ── Login Page ─────────────────────────────────────────────── */
.login-container {
    width: 100%;
    max-width: 420px;
    margin: auto;
    padding: 24px;
}

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xl);
    padding: 40px 32px;
    text-align: center;
}

.login-logo {
    height: 52px;
    margin-bottom: 8px;
}

.login-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--orange-700);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    color: var(--gray-800);
    background: var(--gray-50);
    transition: all var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--orange-400);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.15);
}

.form-input::placeholder {
    color: var(--gray-400);
}

.btn-primary {
    width: 100%;
    padding: 13px 24px;
    background: linear-gradient(135deg, var(--orange-500), var(--orange-600));
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.02em;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--orange-600), var(--orange-700));
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.login-error {
    background: #FEF2F2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    margin-bottom: 16px;
    display: none;
    border: 1px solid #FECACA;
}

.login-error.visible {
    display: block;
}

/* ── Coach Page ─────────────────────────────────────────────── */
.coach-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    min-height: calc(100vh - 69px);
}

.coach-welcome {
    text-align: center;
    margin-bottom: 40px;
}

.coach-welcome h2 {
    font-size: 1.5rem;
    color: var(--gray-800);
    font-weight: 600;
}

.coach-welcome p {
    font-size: 0.95rem;
    color: var(--gray-500);
    margin-top: 4px;
}

/* Blob container */
.blob-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 220px;
    height: 220px;
    margin: 0 auto 32px;
}

.voice-blob {
    width: 160px;
    height: 160px;
    background: radial-gradient(circle at 35% 35%, #FFB366, #FF8C00 40%, #E06C00 80%, #C25A00);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow:
        0 0 40px rgba(255, 140, 0, 0.35),
        0 0 80px rgba(255, 107, 0, 0.15),
        inset 0 -8px 20px rgba(0, 0, 0, 0.15),
        inset 0 8px 20px rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-blob::before {
    content: '';
    position: absolute;
    top: 12%;
    left: 20%;
    width: 35%;
    height: 25%;
    background: radial-gradient(ellipse, rgba(255, 255, 255, 0.5), transparent);
    border-radius: 50%;
    pointer-events: none;
}

.voice-blob .blob-icon {
    width: 48px;
    height: 48px;
    fill: var(--white);
    opacity: 0.9;
    transition: all 0.2s ease;
    pointer-events: none;
}

.voice-blob:hover {
    box-shadow:
        0 0 55px rgba(255, 140, 0, 0.45),
        0 0 100px rgba(255, 107, 0, 0.2),
        inset 0 -8px 20px rgba(0, 0, 0, 0.15),
        inset 0 8px 20px rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.voice-blob.speaking {
    animation: blobPulse 0.4s ease-in-out infinite alternate;
}

.voice-blob.listening {
    animation: blobBreath 1.5s ease-in-out infinite;
}

.voice-blob.idle {
    animation: none;
}

/* Blob ring */
.blob-ring {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 2px solid rgba(255, 140, 0, 0.2);
    animation: ringPulse 2.5s ease-in-out infinite;
}

@keyframes blobPulse {
    0% {
        transform: scale(1) rotate(0deg);
        border-radius: 50%;
        box-shadow: 0 0 40px rgba(255, 107, 0, 0.4);
    }
    25% {
        transform: scale(1.12) rotate(2deg);
        border-radius: 45% 55% 52% 48% / 48% 52% 55% 45%;
    }
    50% {
        transform: scale(1.08) rotate(-1deg);
        border-radius: 55% 45% 48% 52% / 52% 48% 45% 55%;
        box-shadow: 0 0 60px rgba(255, 107, 0, 0.6);
    }
    100% {
        transform: scale(1.15) rotate(1deg);
        border-radius: 48% 52% 55% 45% / 55% 45% 52% 48%;
    }
}

@keyframes blobBreath {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.04); opacity: 1; }
}

@keyframes ringPulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.1); opacity: 0.1; }
}

/* Status text */
.session-status {
    text-align: center;
    margin-bottom: 24px;
    min-height: 48px;
}

.status-text {
    font-size: 1.0625rem;
    color: var(--gray-600);
    font-weight: 500;
    transition: all 0.3s ease;
}

.status-text.active {
    color: var(--orange-600);
}

.status-hint {
    font-size: 0.8125rem;
    color: var(--gray-400);
    margin-top: 4px;
}

/* Session controls */
.session-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-session {
    padding: 12px 32px;
    border-radius: 50px;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.02em;
}

.btn-start {
    background: linear-gradient(135deg, var(--orange-500), var(--orange-600));
    color: var(--white);
    box-shadow: 0 4px 14px rgba(255, 140, 0, 0.3);
}

.btn-start:hover {
    background: linear-gradient(135deg, var(--orange-600), var(--orange-700));
    box-shadow: 0 6px 20px rgba(255, 140, 0, 0.4);
    transform: translateY(-2px);
}

.btn-start:active { transform: translateY(0); }

.btn-stop {
    background: var(--white);
    color: var(--orange-600);
    border: 2px solid var(--orange-500);
}

.btn-stop:hover {
    background: var(--orange-50);
}

.btn-session:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Connection indicator */
.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    background: var(--gray-300);
}

.connection-dot.connected { background: var(--success); }
.connection-dot.connecting { background: var(--orange-400); animation: dotBlink 1s infinite; }
.connection-dot.error { background: var(--danger); }

@keyframes dotBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ── Admin Page ─────────────────────────────────────────────── */
.admin-container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 24px;
}

.admin-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 24px;
}

.upload-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 28px;
    margin-bottom: 32px;
}

.upload-card h3 {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 16px;
}

.upload-zone {
    border: 2px dashed var(--orange-200);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    background: var(--orange-50);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--orange-400);
    background: var(--orange-100);
}

.upload-zone-icon {
    width: 48px;
    height: 48px;
    fill: var(--orange-400);
    margin-bottom: 12px;
}

.upload-zone-text {
    font-size: 0.9375rem;
    color: var(--gray-600);
}

.upload-zone-text strong {
    color: var(--orange-600);
}

.upload-zone-hint {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 6px;
}

.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-progress {
    margin-top: 16px;
    display: none;
}

.upload-progress.visible {
    display: block;
}

.progress-bar-track {
    width: 100%;
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--orange-400), var(--orange-600));
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-status {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: 8px;
}

/* Documents table */
.docs-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.docs-card h3 {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--gray-700);
    padding: 20px 24px 16px;
}

.docs-table {
    width: 100%;
    border-collapse: collapse;
}

.docs-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.docs-table td {
    padding: 12px 16px;
    font-size: 0.875rem;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-100);
}

.docs-table tr:last-child td {
    border-bottom: none;
}

.docs-table tr:hover td {
    background: var(--orange-50);
}

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-badge.ready {
    background: #DCFCE7;
    color: #166534;
}

.status-badge.processing {
    background: #FEF3C7;
    color: #92400E;
}

.status-badge.pending {
    background: var(--gray-100);
    color: var(--gray-600);
}

.status-badge.failed {
    background: #FEE2E2;
    color: #991B1B;
}

.docs-empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--gray-400);
    font-size: 0.875rem;
}

/* ── Toast Notification ─────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: 360px;
}

.toast.success {
    background: #DCFCE7;
    color: #166534;
    border: 1px solid #BBF7D0;
}

.toast.error {
    background: #FEE2E2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

.toast.info {
    background: var(--orange-100);
    color: var(--orange-800);
    border: 1px solid var(--orange-200);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Responsive: Tablet ─────────────────────────────────────── */
@media (max-width: 768px) {
    .header {
        padding: 12px 16px;
    }

    .header-logo {
        height: 30px;
    }

    .header-title {
        font-size: 1rem;
    }

    .login-card {
        padding: 32px 24px;
    }

    .login-brand {
        font-size: 1.25rem;
    }

    .blob-wrapper {
        width: 180px;
        height: 180px;
    }

    .voice-blob {
        width: 130px;
        height: 130px;
    }

    .voice-blob .blob-icon {
        width: 40px;
        height: 40px;
    }

    .blob-ring {
        width: 165px;
        height: 165px;
    }

    .coach-welcome h2 {
        font-size: 1.25rem;
    }

    .btn-session {
        padding: 10px 24px;
        font-size: 0.875rem;
    }

    .admin-container {
        padding: 16px;
    }

    .upload-card {
        padding: 20px;
    }

    /* Responsive table */
    .docs-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .docs-table {
        min-width: 540px;
    }
}

/* ── Responsive: Mobile ─────────────────────────────────────── */
@media (max-width: 480px) {
    html {
        font-size: 15px;
    }

    .header {
        padding: 10px 14px;
    }

    .header-logo {
        height: 26px;
    }

    .header-title {
        font-size: 0.875rem;
        display: none;
    }

    .login-container {
        padding: 16px;
    }

    .login-card {
        padding: 28px 20px;
        border-radius: var(--radius-sm);
    }

    .blob-wrapper {
        width: 160px;
        height: 160px;
        margin-bottom: 24px;
    }

    .voice-blob {
        width: 110px;
        height: 110px;
    }

    .voice-blob .blob-icon {
        width: 34px;
        height: 34px;
    }

    .blob-ring {
        width: 140px;
        height: 140px;
    }

    .coach-welcome {
        margin-bottom: 28px;
    }

    .coach-welcome h2 {
        font-size: 1.125rem;
    }

    .coach-welcome p {
        font-size: 0.8125rem;
    }

    .session-controls {
        flex-direction: column;
        width: 100%;
        padding: 0 16px;
    }

    .btn-session {
        width: 100%;
        justify-content: center;
    }

    .upload-zone {
        padding: 28px 16px;
    }

    .upload-zone-icon {
        width: 36px;
        height: 36px;
    }

    .toast-container {
        left: 16px;
        right: 16px;
        top: 70px;
    }

    .toast {
        max-width: 100%;
    }
}

/* ── Safe area for notched phones ───────────────────────────── */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .session-controls {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border-width: 0;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner.dark {
    border-color: rgba(0,0,0,0.1);
    border-top-color: var(--orange-500);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
