:root {
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --accent: #38bdf8;
    --bg: #0b0f1a;
    /* Deeper background */
    --card-bg: #131c2e;
    /* Solid, premium surface */
    --glass-border: rgba(148, 163, 184, 0.15);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --radius-lg: 1.5rem;
    --radius-md: 0.75rem;
    --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    background-image: radial-gradient(circle at top right, #1e293b 0%, #0b0f1a 50%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
}

.app-container {
    width: 100%;
    max-width: 480px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    padding: 2.5rem;
    min-height: 650px;
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        min-height: 100vh;
    }
}


/* Transitions */
.screen {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Auth Screen */
.auth-card {
    text-align: center;
    padding-top: 2rem;
}

.auth-card h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 2.5rem;
    letter-spacing: -1px;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, var(--primary-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.input-group {
    text-align: left;
    margin-bottom: 1.25rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.input-group input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: white;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: var(--primary);
}

.btn {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-light);
    transform: scale(1.02);
}

.error-text {
    color: var(--accent);
    font-size: 0.85rem;
    margin-top: 1rem;
}

/* Main Screen */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    font-weight: 700;
    letter-spacing: 1px;
    font-family: 'Outfit', sans-serif;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-icon:active {
    transform: scale(0.92);
}

.btn-icon.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.5);
    color: #ef4444;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
    justify-content: center;
}

.dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
}

@keyframes blink {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

.dot.recording {
    background: #ef4444; /* Brighter red for recording */
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
    animation: blink 1.2s infinite ease-in-out;
}

.recording-controls {
    text-align: center;
    margin-bottom: 3rem;
}

.btn-record {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1); /* light red */
    border: 2px solid rgba(239, 68, 68, 0.5); /* semi-transparent red */
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
}

.btn-record:hover {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
}

.btn-record.active {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.4);
    border-color: #ef4444;
}

.record-icon {
    width: 24px;
    height: 24px;
    background: #ef4444; /* red icon */
    border-radius: 50%;
    transition: 0.3s;
}

.btn-record.active .record-icon {
    border-radius: 4px;
}

#timer {
    margin-top: 1rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.history-list h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

#history-items {
    max-height: 350px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

#history-items::-webkit-scrollbar {
    width: 4px;
}

#history-items::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
}

#history-items::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 2px;
}

.history-item {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: 0.2s;
    gap: 1rem;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.item-date {
    font-size: 0.75rem;
    color: var(--primary-light);
}

.item-info {
    flex: 1;
    min-width: 0;
    /* Critical for flex truncation */
}

.item-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Result Screen */
.btn-back {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: 0.2s;
}

.btn-back:hover {
    color: var(--primary-light);
    transform: translateX(-2px);
}

.result-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    padding: 1.5rem;
}

.result-type {
    font-size: 0.8rem;
    color: var(--primary-light);
    margin-bottom: 1rem;
}

/* Modern Player */
.modern-player {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 2rem;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.player-btn {
    background: var(--primary);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    fill: white;
}

.player-progress-container {
    flex: 1;
}

.player-progress-container input {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
    position: relative;
    z-index: 5;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    appearance: none;
    outline: none;
    transition: opacity .2s;
}

.player-progress-container input::-webkit-slider-runnable-track {
    background: rgba(255, 255, 255, 0.1);
    height: 6px;
    border-radius: 3px;
}

.player-progress-container input::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -4px; /* Center thumb on track */
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
    border: 2px solid white;
}

.player-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-family: 'Outfit', monospace;
}



.summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.info-block {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    transition: 0.2s;
}

.info-block:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--primary-light);
}

.info-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
}

.info-value {
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.4;
    font-weight: 500;
}

/* Выделение тревожных симптомов */
.info-block.warning {
    border-color: rgba(244, 63, 94, 0.4);
    background: rgba(244, 63, 94, 0.08);
}

.info-block.warning .info-label {
    color: var(--accent);
}

.analysis-section {
    margin-bottom: 2rem;
}

.section-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.markdown-body {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
}



.secondary {
    opacity: 0.7;
    font-size: 0.9rem;
}

footer {
    margin-top: auto;
    padding-top: 2rem;
    text-align: center;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.2);
}

.hidden {
    display: none !important;
}

/* Physician Invite UI */
.invite-section {
    margin: 2rem 0;
    padding: 1.5rem;
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-md);
}

@media (max-width: 768px) {
    .invite-section {
        background: none !important;
        border: none !important;
        padding: 0 !important;
        border-bottom: 1px solid rgba(255,255,255,0.1) !important;
        border-radius: 0 !important;
    }
}


.invite-section h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--primary-light);
}

.invite-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.invite-form select,
.invite-form input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.6rem 0.8rem;
    border-radius: 0.5rem;
    color: white;
    outline: none;
}

.btn-secondary {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid var(--primary);
    color: var(--primary-light);
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
}

#generated-link-container {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    animation: fadeIn 0.3s ease;
}

#share-link {
    flex: 1;
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-color: var(--primary);
}

/* Patient View */
.patient-info {
    text-align: center;
    margin-bottom: 2rem;
}

.patient-info h2 {
    font-family: 'Outfit', sans-serif;
    margin-bottom: 0.5rem;
}

.patient-info p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.questions-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 2.5rem;
    border-left: 3px solid var(--primary);
}

.question-item {
    padding: 0.5rem 0;
    font-size: 0.95rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.question-item:last-child {
    border-bottom: none;
}

.doctor-title {
    font-size: 0.8rem;
    color: var(--primary-light);
    background: rgba(99, 102, 241, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
}

/* Select Fix & Improvements */
.modern-select {
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08) !important;
    color: white !important;
    border: 1px solid var(--primary) !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 1rem center !important;
    background-size: 1em !important;
}

.modern-select option {
    background-color: #18181b;
    color: white;
}

.field-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.link-display {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.4);
    padding: 0.35rem 0.35rem 0.35rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--primary);
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.link-display:hover {
    background: rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.link-display.copied {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
}

.link-display input {
    background: none !important;
    border: none !important;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--primary-light);
    flex: 1;
    width: 0; /* Force flex to control width */
    min-width: 0;
    cursor: pointer;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    outline: none;
}

.btn-icon.primary-action {
    background: var(--primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.4rem 0.5rem;
    font-weight: 600;
    font-size: 0.75rem;
    width: 130px;
    flex-shrink: 0; /* Prevent shrinking */
    border-radius: 0.35rem;
    transition: all 0.3s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon.primary-action i {
    width: 16px;
    height: 16px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.refresh-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.refresh-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-light);
    transform: rotate(180deg);
    border-color: var(--primary-light);
}

.refresh-btn i {
    width: 18px;
    height: 18px;
}

.item-tag {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary-light);
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    text-transform: uppercase;
}

.item-user {
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
    color: var(--text-primary);
}

.success-msg {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.success-banner {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    animation: slideDown 0.4s ease-out;
}

.success-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.success-text h4 {
    color: #22c55e;
    margin-bottom: 0.25rem;
}

.success-text p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* App Loading */
.app-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(59, 130, 246, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.item-arrow {
    color: var(--primary-light);
    opacity: 0.5;
    font-size: 1.1rem;
    transition: 0.2s;
}

.history-item:hover .item-arrow {
    opacity: 1;
    transform: translateX(4px);
}

.post-recording {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.preview-player {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.player-btn.small {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
}

.preview-progress-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.preview-progress-container input {
    flex: 1;
    accent-color: var(--primary);
    cursor: pointer;
    height: 4px;
}

.preview-player #p-preview-timer {
    font-family: 'Outfit', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: right;
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
}

.btn-record.disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* Mobile optimizations for the Clinic Admin / Doctor Dashboard */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .app-container {
        padding: 1.25rem;
        border: none;
        border-radius: 0;
        min-height: 100vh;
        max-width: 100%;
        background: var(--bg);
        box-shadow: none;
    }

    #history-items {
        max-height: none;
        overflow-y: visible;
        padding-right: 0;
    }

    /* Remove the 'box' look of internal sections on mobile as requested */
    .doctor-dashboard .invite-section,
    .questions-card,
    .result-card,
    .info-block {
        background: none !important;
        border: none !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-shadow: none !important;
    }

    .doctor-dashboard .invite-section {
        margin: 1rem 0 2rem 0;
        border-bottom: 1px solid rgba(255,255,255,0.1) !important;
        padding-bottom: 2rem !important;
    }

    .doctor-dashboard .invite-section h3 {
        margin-bottom: 1.5rem;
    }

    .history-item {
        padding: 1rem;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid rgba(255, 255, 255, 0.05);
        margin-bottom: 0.75rem;
    }
    
    .item-info {
        max-width: calc(100% - 30px);
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .success-banner {
        padding: 1rem;
        gap: 0.75rem;
        flex-direction: column;
        text-align: center;
    }

    /* Copy Link Mobile Fix */
    .btn-icon.primary-action {
        width: auto !important;
        min-width: 100px;
        padding: 0.4rem 0.6rem;
    }
    
    #copy-link-text {
        font-size: 0.7rem;
    }
}
