/* ============================================
   PROCESSMED MOBILE - Mobile-First Styles
   ============================================ */

:root {
    --navy: #1a3668;
    --navy-dark: #0f2347;
    --navy-light: #2a4a7f;
    --red: #e4202c;
    --red-dark: #c41820;
    --bg: #f0f4fa;
    --bg-card: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #5a6178;
    --text-muted: #8e95a9;
    --border: #e2e8f0;
    --success: #10b981;
    --success-bg: #ecfdf5;
    --error: #ef4444;
    --error-bg: #fef2f2;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   SCREEN MANAGEMENT
   ============================================ */

.screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    visibility: hidden;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

.screen.active {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

.screen.slide-out-left {
    transform: translateX(-30%);
    opacity: 0;
}

.screen-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--navy);
    color: white;
    min-height: 56px;
    gap: 12px;
    flex-shrink: 0;
}

.screen-title {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.screen-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    min-height: 48px;
    touch-action: manipulation;
}

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

.btn-primary:active {
    background: var(--navy-dark);
    transform: scale(0.98);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 50%;
    color: white;
    flex-shrink: 0;
}

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

.btn-icon:active {
    background: rgba(255,255,255,0.15);
}

.btn-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   LOGIN SCREEN
   ============================================ */

.login-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 32px 24px;
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
}

#screen-login {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
}

.login-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
}

.login-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 16px;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    color: white;
    margin-bottom: 4px;
}

.login-subtitle {
    color: rgba(255,255,255,0.7);
    font-size: 15px;
    margin-bottom: 32px;
}

#screen-login .mobile-form {
    width: 100%;
    max-width: 360px;
}

#screen-login .form-field label {
    color: rgba(255,255,255,0.9);
}

#screen-login .form-field input {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.2);
    color: white;
}

#screen-login .form-field input::placeholder {
    color: rgba(255,255,255,0.4);
}

#screen-login .form-field input:focus {
    border-color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.18);
}

#screen-login .btn-primary {
    background: var(--red);
    margin-top: 8px;
}

#screen-login .btn-primary:active {
    background: var(--red-dark);
}

.view-switch-link-mobile {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1.5px solid rgba(255,255,255,0.2);
    transition: all 0.2s;
    margin-top: 24px;
}

.view-switch-link-mobile:active {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.4);
}

.view-switch-link-mobile svg {
    flex-shrink: 0;
    color: rgba(255,255,255,0.8);
}

.login-footer-text {
    margin-top: 20px;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
}

.text-navy { color: rgba(255,255,255,0.9); }
.text-red { color: var(--red); }

/* ============================================
   FORMS
   ============================================ */

.mobile-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-field input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: white;
    color: var(--text);
    transition: border-color 0.2s;
    outline: none;
    min-height: 48px;
}

.form-field input:focus {
    border-color: var(--navy);
}

.form-field input::placeholder {
    color: var(--text-muted);
}

.required {
    color: var(--red);
}

.error-banner {
    background: var(--error-bg);
    color: var(--error);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    width: 100%;
}

/* ============================================
   USER BADGE
   ============================================ */

.user-badge {
    font-size: 12px;
    background: rgba(255,255,255,0.15);
    padding: 4px 10px;
    border-radius: 20px;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

/* ============================================
   SEARCH BAR
   ============================================ */

.search-bar {
    position: relative;
    padding: 8px 16px 8px;
    background: var(--navy);
    flex-shrink: 0;
    padding-bottom: 12px;
}

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-bar input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    background: white;
    color: var(--text);
    outline: none;
    min-height: 44px;
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

/* ============================================
   COMPANY GRID
   ============================================ */

#company-grid-container {
    padding-top: 8px;
}

.company-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.company-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
    border: 1.5px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 100px;
    justify-content: center;
    text-align: center;
}

.company-card:active {
    transform: scale(0.97);
    border-color: var(--navy);
    box-shadow: var(--shadow);
}

.company-card.no-credentials {
    opacity: 0.45;
    pointer-events: none;
}

.company-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--navy);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.company-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.company-card-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.status-ready {
    background: var(--success-bg);
    color: var(--success);
}

.status-no-creds {
    background: #f1f5f9;
    color: var(--text-muted);
}

/* ============================================
   COMPANY BADGE (Input Screen)
   ============================================ */

.company-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

/* ============================================
   PROCESSING SCREEN
   ============================================ */

.processing-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    gap: 28px;
    padding: 32px 24px;
}

.processing-company {
    font-size: 20px;
    font-weight: 700;
    color: var(--navy);
    animation: fadeSlideDown 0.5s ease both;
}

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

/* --- Dual-ring animated spinner with center icon --- */

.spinner-container {
    width: 88px;
    height: 88px;
    position: relative;
    animation: fadeScaleIn 0.4s ease both 0.1s;
}

@keyframes fadeScaleIn {
    from { opacity: 0; transform: scale(0.7); }
    to { opacity: 1; transform: scale(1); }
}

.spinner-ring {
    position: absolute;
    border-radius: 50%;
    border-style: solid;
}

.spinner-ring-outer {
    width: 88px;
    height: 88px;
    top: 0; left: 0;
    border-width: 4px;
    border-color: var(--border);
    border-top-color: var(--navy);
    border-right-color: var(--navy-light);
    animation: spin 1s linear infinite;
}

.spinner-ring-inner {
    width: 64px;
    height: 64px;
    top: 12px; left: 12px;
    border-width: 3px;
    border-color: transparent;
    border-bottom-color: var(--red);
    border-left-color: rgba(228,32,44,0.4);
    animation: spin-reverse 1.4s linear infinite;
}

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

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

.spinner-icon {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    color: var(--navy);
    animation: pulse-icon 2s ease-in-out infinite;
}

.spinner-icon svg {
    width: 100%;
    height: 100%;
}

@keyframes pulse-icon {
    0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

/* --- Step list --- */

.step-list {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: fadeSlideUp 0.4s ease both 0.2s;
}

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

.step-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-muted);
    opacity: 0.45;
    transform: translateX(-6px);
    transition: color 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
}

.step-indicator {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s ease;
    position: relative;
}

/* Active step */
.step-item.active {
    color: var(--navy);
    font-weight: 600;
    opacity: 1;
    transform: translateX(0);
}

.step-item.active .step-indicator {
    border-color: var(--navy);
    background: var(--navy);
    box-shadow: 0 0 0 5px rgba(26,54,104,0.12);
    animation: pulse-ring 1.8s ease infinite;
}

@keyframes pulse-ring {
    0%, 100% { box-shadow: 0 0 0 4px rgba(26,54,104,0.12); }
    50% { box-shadow: 0 0 0 8px rgba(26,54,104,0.06); }
}

.step-item.active .step-indicator::after {
    content: '';
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    animation: pulse-dot 1s ease infinite;
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.6); opacity: 0.7; }
}

.step-item.active .step-label {
    animation: shimmer-text 2s ease infinite;
}

@keyframes shimmer-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Done step */
.step-item.done {
    color: var(--success);
    opacity: 1;
    transform: translateX(0);
}

.step-item.done .step-indicator {
    border-color: var(--success);
    background: var(--success);
    box-shadow: none;
    animation: pop-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes pop-in {
    0% { transform: scale(0.6); }
    70% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.step-item.done .step-indicator::after {
    content: '';
    width: 12px;
    height: 12px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    animation: check-draw 0.3s ease both;
}

@keyframes check-draw {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

/* Processing status text */
.processing-status {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    min-height: 24px;
    animation: fadeSlideUp 0.4s ease both 0.3s;
    transition: opacity 0.3s ease;
}

/* ============================================
   RESULTS SCREEN
   ============================================ */

.result-status-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px;
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    text-align: center;
}

.result-status-badge.eligible {
    background: var(--success-bg);
}

.result-status-badge.not-eligible {
    background: var(--error-bg);
}

.result-status-badge.unknown {
    background: var(--warning-bg);
}

.badge-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.eligible .badge-icon {
    background: var(--success);
}

.not-eligible .badge-icon {
    background: var(--error);
}

.unknown .badge-icon {
    background: var(--warning);
}

.badge-icon svg {
    width: 28px;
    height: 28px;
    stroke: white;
    stroke-width: 2.5;
    fill: none;
}

.badge-text {
    font-size: 20px;
    font-weight: 700;
}

.eligible .badge-text { color: var(--success); }
.not-eligible .badge-text { color: var(--error); }
.unknown .badge-text { color: var(--warning); }

.result-company {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 4px;
}

.result-patient {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.result-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.result-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    border: 1px solid var(--border);
}

.result-card-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.result-card-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    word-break: break-word;
}

.result-actions {
    padding-bottom: 24px;
}

.result-actions .btn-primary {
    background: var(--navy);
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

.company-card {
    animation: fadeIn 0.3s ease both;
}

.company-card:nth-child(1) { animation-delay: 0.02s; }
.company-card:nth-child(2) { animation-delay: 0.04s; }
.company-card:nth-child(3) { animation-delay: 0.06s; }
.company-card:nth-child(4) { animation-delay: 0.08s; }
.company-card:nth-child(5) { animation-delay: 0.10s; }
.company-card:nth-child(6) { animation-delay: 0.12s; }
.company-card:nth-child(7) { animation-delay: 0.14s; }
.company-card:nth-child(8) { animation-delay: 0.16s; }
.company-card:nth-child(9) { animation-delay: 0.18s; }
.company-card:nth-child(10) { animation-delay: 0.20s; }

.result-card {
    animation: fadeIn 0.3s ease both;
}

.result-card:nth-child(1) { animation-delay: 0.05s; }
.result-card:nth-child(2) { animation-delay: 0.10s; }
.result-card:nth-child(3) { animation-delay: 0.15s; }
.result-card:nth-child(4) { animation-delay: 0.20s; }
.result-card:nth-child(5) { animation-delay: 0.25s; }
.result-card:nth-child(6) { animation-delay: 0.30s; }

/* ============================================
   EMPTY & ERROR STATES
   ============================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 14px;
}

/* ============================================
   SCROLLBAR
   ============================================ */

.screen-content::-webkit-scrollbar {
    width: 0;
}

/* ============================================
   LANDSCAPE HANDLING
   ============================================ */

@media (orientation: landscape) and (max-height: 500px) {
    .login-logo { width: 48px; height: 48px; }
    .login-title { font-size: 22px; }
    .login-subtitle { margin-bottom: 16px; }
    .processing-content { gap: 12px; padding: 16px; }
    .spinner-container { width: 40px; height: 40px; }
    .spinner { width: 40px; height: 40px; }
}

/* ============================================
   NOTCH / ISLAND HANDLING
   ============================================ */

@supports (padding: env(safe-area-inset-top)) {
    .screen-header {
        padding-top: calc(12px + var(--safe-top));
    }
    #screen-login .screen-content {
        padding-top: var(--safe-top);
    }
}

/* ============================================
   USER INFO BAR
   ============================================ */

.user-info-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: var(--navy-dark);
    color: rgba(255,255,255,0.75);
    font-size: 12px;
    flex-shrink: 0;
}

.user-info-bar svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.user-info-bar .info-sep {
    margin: 0 4px;
    opacity: 0.5;
}

/* ============================================
   SOURCE BADGE (Results Screen)
   ============================================ */

.result-source-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin: 0 auto 12px;
    width: fit-content;
}

.source-from-records {
    background: #eff6ff;
    color: #3b82f6;
}

.source-live-check {
    background: var(--success-bg);
    color: var(--success);
}

.source-from-records svg,
.source-live-check svg {
    flex-shrink: 0;
}

/* ============================================
   RESULT INFO FOOTER
   ============================================ */

.result-info-footer {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 16px;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.result-info-footer .info-item {
    display: block;
}

.result-info-footer .info-item strong {
    color: var(--text);
    font-weight: 600;
    margin-right: 4px;
}

/* ============================================
   POWERED BY FOOTER
   ============================================ */

.powered-footer {
    text-align: center;
    padding: 12px 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.text-navy-dark { color: var(--navy); }
.text-red-dark { color: var(--red); }

