/*
 * Documents library (services/documents/front/documents.php).
 * Builds on teleconsultation/front/assets/css/articles-list.css
 * (hero, search, tabs, chips, states, buttons, CTA band, footer).
 */

:root {
    --c-pdf: #dc2626;
    --c-pdf-bg: #fef2f2;
    --c-word: #2563eb;
    --c-word-bg: #eff6ff;
    --c-new: #059669;
}

/* tabs are buttons here, not links */
button.tab {
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 0.93rem;
    font-weight: 600;
    cursor: pointer;
}

button.chip,
button.reset {
    font: inherit;
    cursor: pointer;
}

button.chip {
    font-size: 0.87rem;
    font-weight: 500;
}

button.reset {
    border: 0;
    background: none;
    font-size: 0.92rem;
    font-weight: 600;
}

/* guests: search is visible but asleep */
.is-guest .search {
    opacity: 0.85;
}

/* ------------------------------------------------------- Toolbar */
.doc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    flex-wrap: wrap;
}

.doc-toolbar .tabs {
    margin-inline: 0;
}

.account {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 5px;
    padding-inline-start: 5px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    max-width: 100%;
    min-width: 0;
}

.account-avatar {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--grad-blue);
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.account-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.account-label {
    color: var(--muted);
    font-size: 0.72rem;
}

.account-name {
    color: var(--ink);
    font-weight: 700;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-out {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: #f1f5f9;
    color: #475569;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.account-out:hover {
    background: #fee2e2;
    color: var(--c-pdf);
}

[dir="rtl"] .account-out i {
    transform: scaleX(-1);
}

/* --------------------------------------------------------- Grid */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(1rem, 2.4vw, 1.5rem);
}

.doc-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    border-radius: var(--radius-md);
    background: #ffffff;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), border-color 0.25s ease;
    min-width: 0;
}

.doc-card:not(.is-ghost):hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--line-blue);
}

.js .doc-card.is-in {
    animation: card-in 0.55s var(--ease) backwards;
    animation-delay: calc(var(--i, 0) * 40ms);
}

.doc-head {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.doc-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 1.35rem;
    background: #f1f5f9;
    color: var(--muted);
}

.doc-icon.is-pdf {
    background: var(--c-pdf-bg);
    color: var(--c-pdf);
    box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.14);
}

.doc-icon.is-word {
    background: var(--c-word-bg);
    color: var(--c-word);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}

.doc-kind {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.doc-ext {
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.doc-size {
    color: var(--muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.doc-new {
    margin-inline-start: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #ecfdf5;
    color: var(--c-new);
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
}

.doc-new::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.18);
}

.doc-title {
    color: var(--ink);
    font-size: 1.08rem;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

[lang="ar"] .doc-title {
    letter-spacing: 0;
}

.doc-desc {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.doc-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.doc-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 4px 10px;
    border-radius: 8px;
    background: #f1f5f9;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-tag.is-cat {
    background: #eef2ff;
    color: var(--blue-dark);
}

.doc-foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 8px;
}

.doc-date {
    color: var(--muted);
    font-size: 0.8rem;
    margin-inline-end: auto;
    white-space: nowrap;
}

.doc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid transparent;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s var(--ease);
}

.doc-btn.is-read {
    background: var(--grad-blue);
    color: #ffffff;
    box-shadow: 0 10px 22px -14px rgba(37, 99, 235, 0.95);
}

.doc-btn.is-read:hover {
    transform: translateY(-1px);
}

.doc-btn.is-dl {
    width: 40px;
    padding: 0;
    background: #ffffff;
    color: #475569;
    border-color: rgba(15, 23, 42, 0.14);
}

.doc-btn.is-dl:hover {
    border-color: rgba(37, 99, 235, 0.45);
    color: var(--blue);
}

/* ------------------------------------------------- Skeletons */
.ghost-line {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: #e2e8f0;
}

.ghost-line.w90 { width: 90%; height: 16px; }
.ghost-line.w70 { width: 70%; }
.ghost-line.w50 { width: 50%; }
.ghost-line.w40 { width: 40%; }

.doc-card.is-loading .ghost-line,
.doc-card.is-loading .doc-icon {
    background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
}

@keyframes shimmer {
    from { background-position: 100% 50%; }
    to   { background-position: 0 50%; }
}

/* ---------------------------------------------------- Locked */
.gate {
    position: relative;
    min-height: 440px;
}

.gate-preview {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
    filter: blur(3px);
    opacity: 0.7;
    pointer-events: none;
    user-select: none;
    -webkit-mask-image: linear-gradient(180deg, #000 30%, transparent 100%);
    mask-image: linear-gradient(180deg, #000 30%, transparent 100%);
}

.gate-preview .doc-card {
    min-height: 190px;
}

.gate-card {
    position: absolute;
    inset-inline: 0;
    top: 50%;
    transform: translateY(-50%);
    width: min(460px, 100%);
    margin-inline: auto;
    padding: clamp(1.75rem, 4vw, 2.5rem);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid var(--line-blue);
    box-shadow: 0 30px 60px -30px rgba(37, 99, 235, 0.45), var(--shadow-sm);
    text-align: center;
}

.gate-lock {
    width: 68px;
    height: 68px;
    margin: 0 auto 1.1rem;
    border-radius: 22px;
    display: grid;
    place-items: center;
    background: var(--grad);
    color: #ffffff;
    font-size: 1.5rem;
    box-shadow: 0 16px 30px -16px rgba(118, 75, 162, 0.9);
}

.gate-card h3 {
    color: var(--ink);
    font-size: 1.35rem;
    line-height: 1.3;
}

.gate-card > p {
    margin-top: 0.6rem;
    color: var(--muted);
}

.gate-card .btn {
    margin-top: 1.4rem;
    width: 100%;
}

.gate-foot {
    margin-top: 1rem !important;
    font-size: 0.9rem;
}

.gate-foot a {
    color: var(--blue);
    font-weight: 600;
    text-decoration: none;
}

.gate-foot a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ---------------------------------------------------- Dialogs */
.modal {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    max-width: none;
    max-height: none;
    overflow: visible;
}

.modal::backdrop {
    background: rgba(15, 23, 42, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.modal[open] {
    animation: modal-in 0.35s var(--ease);
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

body.modal-open {
    overflow: hidden;
}

/* Login */
.login-modal {
    width: min(440px, calc(100vw - 32px));
}

.login-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: clamp(1.5rem, 5vw, 2.25rem);
    border-radius: var(--radius-lg);
    background: #ffffff;
    box-shadow: 0 40px 80px -30px rgba(15, 23, 42, 0.6);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
}

.modal-x {
    position: absolute;
    top: 14px;
    inset-inline-end: 14px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: #f1f5f9;
    color: #475569;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.modal-x:hover {
    background: #e2e8f0;
}

.login-badge {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: var(--grad);
    color: #ffffff;
    font-size: 1.45rem;
    box-shadow: 0 14px 28px -14px rgba(118, 75, 162, 0.9);
}

.login-card h2 {
    color: var(--ink);
    font-size: 1.45rem;
    letter-spacing: -0.02em;
}

.login-sub {
    margin-top: -6px !important;
    color: var(--muted);
    font-size: 0.93rem;
}

.login-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.login-alert i {
    margin-top: 3px;
}

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

.field-label {
    color: var(--ink);
    font-size: 0.88rem;
    font-weight: 600;
}

.field-box {
    position: relative;
    display: flex;
    align-items: center;
    border-radius: 14px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.field-box:focus-within {
    border-color: var(--blue);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.field-box.is-invalid {
    border-color: #ef4444;
}

.field-box > i {
    position: absolute;
    inset-inline-start: 15px;
    color: #94a3b8;
    font-size: 0.95rem;
    pointer-events: none;
}

.field-box input {
    flex: 1;
    min-width: 0;
    height: 50px;
    padding-inline: 44px 14px;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 16px; /* no iOS zoom */
    color: var(--ink);
}

.field-box input:focus,
.field-box input:focus-visible {
    outline: none;
}

.field-eye {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    margin-inline-end: 3px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
}

.field-eye:hover {
    color: var(--blue);
}

.login-submit {
    margin-top: 4px;
    width: 100%;
}

.login-submit .spinner {
    display: none;
}

.login-submit.is-busy .spinner {
    display: inline-block;
}

.login-submit:disabled {
    cursor: progress;
    opacity: 0.85;
    transform: none;
}

.login-note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.login-note i {
    margin-top: 3px;
    color: var(--c-new);
}

.spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
}

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

/* Reader */
.viewer-modal {
    width: min(1100px, calc(100vw - 32px));
    height: calc(100dvh - 32px);
}

.viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 20px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 40px 80px -30px rgba(15, 23, 42, 0.6);
}

.viewer-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    padding-inline-start: 14px;
    border-bottom: 1px solid var(--line);
}

.viewer-bar .doc-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 1.05rem;
}

.viewer-bar h2 {
    flex: 1;
    min-width: 0;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    border: 0;
    background: #f1f5f9;
    color: #475569;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.viewer-btn:hover {
    background: #e0e7ff;
    color: var(--blue-dark);
}

.viewer-body {
    position: relative;
    flex: 1;
    background: #e2e8f0;
}

.viewer-body iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.viewer-loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}

.viewer-loading .spinner {
    width: 34px;
    height: 34px;
    border-color: rgba(37, 99, 235, 0.2);
    border-top-color: var(--blue);
}

/* ------------------------------------------------------ Toast */
.toast {
    position: fixed;
    z-index: 3000;
    inset-inline: 16px;
    bottom: max(20px, env(safe-area-inset-bottom));
    width: max-content;
    max-width: calc(100vw - 32px);
    margin-inline: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 14px;
    background: var(--ink);
    color: #ffffff;
    font-size: 0.92rem;
    font-weight: 500;
    box-shadow: 0 20px 40px -20px rgba(15, 23, 42, 0.8);
    animation: toast-in 0.35s var(--ease);
}

.toast i {
    color: #34d399;
}

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

/* ------------------------------------------------- Responsive */
@media (max-width: 1023px) {
    .doc-grid,
    .gate-preview {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .doc-toolbar {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .doc-toolbar .tabs {
        margin-inline: auto;
    }

    .account {
        align-self: stretch;
    }

    .account-text {
        flex: 1;
    }
}

@media (max-width: 640px) {
    .doc-grid,
    .gate-preview {
        grid-template-columns: 1fr;
    }

    .gate {
        min-height: 480px;
    }

    .viewer-modal {
        width: 100vw;
        height: 100dvh;
    }

    .viewer {
        border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .js .doc-card.is-in,
    .modal[open],
    .toast,
    .doc-card.is-loading .ghost-line,
    .doc-card.is-loading .doc-icon {
        animation: none !important;
    }

    .doc-card:hover,
    .doc-btn:hover {
        transform: none !important;
    }
}
