/* ========== Reset & Base ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #0d9488;
    --primary-light: #14b8a6;
    --primary-dark: #0f766e;
    --primary-gradient: linear-gradient(135deg, #0d9488, #0891b2);
    --danger: #ef4444;
    --danger-light: #fecaca;
    --success: #22c55e;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --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;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 40px -10px rgba(0,0,0,0.1);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ========== Screens ========== */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
}

.state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 24px;
    animation: fadeInUp 0.5s ease;
}

.state.active {
    display: flex;
}

/* ========== Animations ========== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.4;
    }
    50% {
        transform: scale(1.5);
        opacity: 0;
    }
}

@keyframes recPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

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

@keyframes checkDraw {
    to { stroke-dashoffset: 0; }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========== Auth Gate ========== */
#auth-gate {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0fdfa 0%, #ecfeff 50%, #f0f9ff 100%);
}

.auth-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    margin: 24px;
    animation: scaleIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.logo-container {
    text-align: center;
    margin-bottom: 36px;
}

.logo-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-gradient);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: white;
}

.logo-icon svg {
    width: 32px;
    height: 32px;
}

.logo-container h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--gray-500);
    font-size: 14px;
    margin-top: 6px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form label {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.auth-form input {
    padding: 14px 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: inherit;
    transition: var(--transition);
    outline: none;
}

.auth-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.1);
}

/* ========== Buttons ========== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    width: 18px;
    height: 18px;
}

.btn-ghost {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.btn-ghost:hover {
    color: var(--gray-600);
    background: var(--gray-100);
}

/* ========== App Header ========== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-100);
    background: white;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    width: 32px;
    height: 32px;
    background: var(--primary-gradient);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.header-logo svg {
    width: 18px;
    height: 18px;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-800);
}

/* ========== App Main ========== */
#app-screen {
    flex-direction: column;
}

.app-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* ========== Idle State ========== */
.instruction-text {
    text-align: center;
}

.instruction-text h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.instruction-text p {
    color: var(--gray-500);
    font-size: 15px;
    line-height: 1.5;
    max-width: 360px;
}

.mic-button {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: white;
    cursor: pointer;
    transition: var(--transition-bounce);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.mic-button svg {
    width: 48px;
    height: 48px;
    position: relative;
    z-index: 1;
}

.mic-button:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(13, 148, 136, 0.35);
}

.mic-button:active {
    transform: scale(0.97);
}

.mic-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.4;
    animation: pulse 2.5s ease-in-out infinite;
}

.mic-pulse.delay {
    animation-delay: 1.25s;
}

.hint-text {
    font-size: 13px;
    color: var(--gray-400);
}

/* ========== Recording State ========== */
.recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    color: var(--danger);
}

.rec-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--danger);
    animation: recPulse 1s ease-in-out infinite;
}

#waveform {
    width: 100%;
    max-width: 400px;
    height: 120px;
    border-radius: var(--radius);
    background: white;
    box-shadow: var(--shadow);
}

.timer {
    font-size: 32px;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: var(--gray-700);
}

.stop-button {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    color: white;
    cursor: pointer;
    transition: var(--transition-bounce);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stop-button svg {
    width: 32px;
    height: 32px;
}

.stop-button:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(239, 68, 68, 0.35);
}

/* ========== Processing State ========== */
#processing-state h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--gray-800);
}

.steps {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.step {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    opacity: 0.4;
    transition: var(--transition);
}

.step.active {
    opacity: 1;
    box-shadow: var(--shadow);
    animation: slideInRight 0.4s ease;
}

.step.done {
    opacity: 1;
}

.step-icon {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.step.active .step-icon {
    background: rgba(13, 148, 136, 0.1);
    color: var(--primary);
}

.step.done .step-icon {
    background: var(--success-light);
    color: var(--success);
}

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

.step-check {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.step.done .step-check {
    opacity: 1;
}

.step.done .step-icon > svg:first-child {
    opacity: 0;
}

.step-check svg {
    width: 22px;
    height: 22px;
    color: var(--success);
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    animation: checkDraw 0.4s ease forwards;
}

.step span {
    font-size: 15px;
    font-weight: 500;
    color: var(--gray-600);
}

.step.active span {
    color: var(--gray-800);
}

.step.active .step-icon::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 14px;
    border: 2px solid var(--primary);
    opacity: 0.3;
    animation: pulse 1.5s ease-in-out infinite;
}

/* ========== Results State ========== */
.results-card {
    width: 100%;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: slideUp 0.5s ease;
}

.result-section {
    padding: 24px;
    border-bottom: 1px solid var(--gray-100);
    animation: fadeInUp 0.5s ease;
}

.result-section:nth-child(1) { animation-delay: 0.1s; }
.result-section:nth-child(2) { animation-delay: 0.25s; }
.result-section:nth-child(3) { animation-delay: 0.4s; }

.result-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.result-icon {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.result-header h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
}

.result-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.result-field label {
    font-size: 12px;
    color: var(--gray-400);
    font-weight: 500;
}

.result-field span {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
}

.oib-display {
    display: flex;
    align-items: center;
    gap: 10px;
}

#result-oib {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.valid {
    background: var(--success-light);
    color: var(--success);
}

.status-badge.invalid {
    background: var(--danger-light);
    color: var(--danger);
}

/* ========== Medicine Cards ========== */
.medicines-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.medicine-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--gray-50);
    border-radius: var(--radius);
    border-left: 4px solid var(--gray-300);
    animation: slideInRight 0.4s ease;
    transition: var(--transition);
}

.medicine-card:hover {
    box-shadow: var(--shadow);
    transform: translateX(2px);
}

.medicine-card.high { border-left-color: var(--success); }
.medicine-card.medium { border-left-color: var(--warning); }
.medicine-card.low { border-left-color: var(--danger); }

.medicine-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.medicine-raw {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-800);
}

.medicine-match {
    font-size: 13px;
    color: var(--gray-500);
}

.medicine-confidence {
    font-size: 13px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
}

.medicine-confidence.high { background: var(--success-light); color: var(--success); }
.medicine-confidence.medium { background: var(--warning-light); color: var(--warning); }
.medicine-confidence.low { background: var(--danger-light); color: var(--danger); }

/* ========== Transcript ========== */
.transcript-section {
    border-bottom: none;
}

.transcript-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: inherit;
    padding: 0;
    color: inherit;
}

.chevron {
    width: 18px;
    height: 18px;
    color: var(--gray-400);
    margin-left: auto;
    transition: var(--transition);
}

.transcript-section.open .chevron {
    transform: rotate(180deg);
}

.transcript-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease;
    opacity: 0;
}

.transcript-section.open .transcript-content {
    max-height: 300px;
    opacity: 1;
    margin-top: 16px;
}

#result-transcript-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--gray-600);
    background: var(--gray-50);
    padding: 16px;
    border-radius: var(--radius);
    font-style: italic;
}

.result-meta {
    padding: 12px 24px;
    text-align: right;
    font-size: 12px;
    color: var(--gray-400);
}

/* ========== Error State ========== */
.error-card {
    text-align: center;
    background: white;
    border-radius: var(--radius-lg);
    padding: 48px 32px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    animation: scaleIn 0.4s ease;
}

.error-icon {
    width: 56px;
    height: 56px;
    color: var(--danger);
    margin-bottom: 16px;
}

.error-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.error-card p {
    color: var(--gray-500);
    margin-bottom: 24px;
}

/* ========== Patient Cards ========== */
.patient-card {
    padding: 24px;
    border-bottom: 1px solid var(--gray-100);
    animation: fadeInUp 0.5s ease backwards;
}

.patient-card:last-child {
    border-bottom: none;
}

.patient-header {
    margin-bottom: 16px;
}

.patient-number {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary);
    padding: 4px 12px;
    background: rgba(13, 148, 136, 0.08);
    border-radius: 20px;
    display: inline-block;
}

.patient-medicines {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-100);
}

.field-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
}

.oib-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

/* ========== Utilities ========== */
.hidden {
    display: none !important;
}

.error-text {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
    .auth-card {
        padding: 36px 24px;
        margin: 16px;
    }

    .mic-button {
        width: 100px;
        height: 100px;
    }

    .mic-button svg {
        width: 40px;
        height: 40px;
    }

    .result-field span, #result-oib {
        font-size: 16px;
    }
}

/* ========== Build Version ========== */
#build-version {
    position: fixed;
    bottom: 8px;
    right: 12px;
    font-size: 11px;
    color: var(--gray-300);
    font-family: 'Inter', monospace;
    pointer-events: none;
    z-index: 1;
}
