/* ==========================================================================
   Reusable file picker (ImageUploadPicker / DocumentUploadPicker)
   Every class starts with "fp-". Uses the --of-* colours when present.
   ========================================================================== */

.fp-field, .fp-panel, .fp-panel * { box-sizing: border-box; }

.fp-field {
    --fp-brand: var(--of-brand, #168276);
    --fp-brand-soft: var(--of-brand-soft, #e8f5f3);
    --fp-ink: var(--of-ink, #1a2e35);
    --fp-muted: var(--of-muted, #64748b);
    --fp-line: var(--of-line, #e2e8f0);
    --fp-surface: var(--of-surface, #ffffff);
    --fp-panel: var(--of-panel, #f8fafb);
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.fp-field--doc { display: flex; align-items: stretch; width: 100%; }

/* ── Trigger (image) ── */
.fp-trigger {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 80px;
    height: 80px;
    flex: none;
    padding: 0;
    overflow: hidden;
    border: 1.5px dashed var(--fp-line);
    border-radius: 12px;
    background: var(--fp-panel);
    color: var(--fp-muted);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.fp-trigger:hover,
.fp-trigger:focus-visible {
    border-color: var(--fp-brand);
    box-shadow: 0 0 0 3px var(--fp-brand-soft);
    outline: none;
}

.fp-trigger img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.fp-trigger__icon { font-size: 22px; color: var(--fp-brand); }
.fp-trigger small { font-size: 10px; line-height: 1.1; font-weight: 600; }

.fp-trigger__hover {
    position: absolute;
    inset: auto 0 0 0;
    padding: 4px;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.7), rgba(15, 23, 42, 0));
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    opacity: 0;
    transition: opacity 0.15s;
}

.fp-trigger:hover .fp-trigger__hover,
.fp-trigger:focus-visible .fp-trigger__hover { opacity: 1; }

.fp-remove {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    border: none;
    background: transparent;
    color: #b42318;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.fp-remove:hover { text-decoration: underline; }

/* ── Trigger (document) ── */
.fp-docchip {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--fp-line);
    border-radius: 12px;
    background: var(--fp-surface);
}

.fp-docchip--empty { border-style: dashed; background: var(--fp-panel); }

.fp-docchip__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--fp-brand-soft);
    color: var(--fp-brand);
    font-size: 20px;
}

.fp-docchip__text { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.fp-docchip__text a, .fp-docchip__text strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 700;
    color: var(--fp-ink);
    text-decoration: none;
}
.fp-docchip__text a:hover { text-decoration: underline; }
.fp-docchip__text small { font-size: 11px; color: var(--fp-muted); }

/* ── Buttons ── */
.fp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--fp-line);
    border-radius: 10px;
    background: var(--fp-surface);
    color: var(--fp-ink);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.fp-btn:hover:not(:disabled) { background: var(--fp-panel); border-color: var(--fp-brand); }
.fp-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.fp-btn--sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.fp-btn--primary { background: var(--fp-brand); border-color: var(--fp-brand); color: #fff; }
.fp-btn--primary:hover:not(:disabled) { background: var(--of-brand-dark, #0f6258); border-color: var(--of-brand-dark, #0f6258); }
.fp-btn--danger { color: #b42318; }
.fp-btn--danger:hover:not(:disabled) { background: #fde4e1; border-color: #f1a8a0; }
.fp-btn--danger-solid { background: #c0392b; border-color: #c0392b; color: #fff; }
.fp-btn--danger-solid:hover:not(:disabled) { background: #a8281c; border-color: #a8281c; }

/* ── Panel ── */
.fp-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1055;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(3px);
    animation: fp-fade 0.2s ease-out;
}

.fp-panel {
    --fp-brand: var(--of-brand, #168276);
    --fp-brand-soft: var(--of-brand-soft, #e8f5f3);
    --fp-ink: var(--of-ink, #1a2e35);
    --fp-muted: var(--of-muted, #64748b);
    --fp-line: var(--of-line, #e2e8f0);
    --fp-surface: var(--of-surface, #ffffff);
    --fp-panel: var(--of-panel, #f8fafb);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1056;
    display: flex;
    flex-direction: column;
    width: min(960px, 100vw);
    background: var(--fp-panel);
    color: var(--fp-ink);
    font-size: 13px;
    box-shadow: -14px 0 44px rgba(15, 23, 42, 0.25);
    animation: fp-slide 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes fp-slide { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fp-fade { from { opacity: 0; } to { opacity: 1; } }

.fp-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--fp-line);
    background: var(--fp-surface);
}

.fp-eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; color: var(--fp-brand); }
.fp-title { margin: 2px 0 0; font-size: 20px; font-weight: 800; color: var(--fp-ink); }

.fp-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--fp-line);
    border-radius: 10px;
    background: var(--fp-surface);
    color: var(--fp-ink);
    cursor: pointer;
}
.fp-close:hover { border-color: var(--fp-brand); }

.fp-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px 22px 22px;
    overflow-y: auto;
}

.fp-tabs { display: flex; flex-wrap: wrap; gap: 8px; }

.fp-tab {
    padding: 7px 16px;
    border: 1px solid var(--fp-line);
    border-radius: 999px;
    background: var(--fp-surface);
    color: var(--fp-ink);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.fp-tab:hover:not(:disabled) { border-color: var(--fp-brand); }
.fp-tab.is-active { background: var(--fp-brand); border-color: var(--fp-brand); color: #fff; }
.fp-tab:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Alerts ── */
.fp-alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
}
.fp-alert--error { background: #fde4e1; color: #a8281c; }
.fp-alert--ok { background: #dff5e7; color: #17713c; }

/* ── Drop zone ── */
.fp-drop {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 26px 16px;
    border: 2px dashed var(--fp-brand);
    border-radius: 16px;
    background: var(--fp-brand-soft);
    color: var(--fp-ink);
    text-align: center;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
}

.fp-drop:hover, .fp-drop:focus-within { box-shadow: 0 0 0 4px var(--fp-brand-soft); background: var(--fp-surface); }
.fp-drop input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.fp-drop__icon { font-size: 34px; color: var(--fp-brand); line-height: 1; }
.fp-drop__title { font-size: 14px; }
.fp-drop__title strong { color: var(--fp-brand); }
.fp-drop__rules { font-size: 12px; color: var(--fp-muted); }

/* ── Staged file (preview before upload) ── */
.fp-stage {
    display: flex;
    gap: 18px;
    padding: 16px;
    border: 1px solid var(--fp-brand);
    border-radius: 16px;
    background: var(--fp-surface);
    box-shadow: 0 0 0 4px var(--fp-brand-soft);
}

.fp-stage__preview {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 190px;
    height: 190px;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid var(--fp-line);
    background-color: #fff;
    background-image: linear-gradient(45deg, #eef2f6 25%, transparent 25%), linear-gradient(-45deg, #eef2f6 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #eef2f6 75%), linear-gradient(-45deg, transparent 75%, #eef2f6 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    color: var(--fp-brand);
    font-size: 64px;
}

.fp-stage__preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

.fp-stage__info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.fp-stage__label { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fp-brand); }
.fp-stage__name { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 800; }
.fp-stage__meta { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; color: var(--fp-muted); }
.fp-stage__hint { margin: 10px 0 0; color: var(--fp-muted); }
.fp-stage__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: auto; padding-top: 14px; }

/* ── Library ── */
.fp-library-head { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.fp-library-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.fp-library-head span { margin-right: auto; color: var(--fp-muted); }

.fp-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 36px 16px;
    border: 1px dashed var(--fp-line);
    border-radius: 14px;
    background: var(--fp-surface);
    color: var(--fp-muted);
    text-align: center;
}
.fp-empty i { font-size: 30px; }

.fp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.fp-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 2px solid var(--fp-line);
    border-radius: 14px;
    background: #fff;
    transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.fp-tile:hover { border-color: var(--fp-brand); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12); transform: translateY(-1px); }
.fp-tile.is-selected { border-color: var(--fp-brand); box-shadow: 0 0 0 3px var(--fp-brand-soft); }
.fp-tile.is-new { border-color: #d08a0b; }

.fp-tile__pick { display: block; width: 100%; height: 100%; padding: 0; border: none; background: transparent; cursor: pointer; }
.fp-tile__pick img { display: block; width: 100%; height: 100%; object-fit: contain; }

.fp-tile__caption {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.68);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    pointer-events: none;
}

.fp-tile__check {
    position: absolute;
    top: 6px;
    left: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--fp-brand);
    color: #fff;
    font-size: 13px;
    pointer-events: none;
}

.fp-tile__new { position: absolute; right: 6px; bottom: 6px; }

.fp-tile__delete {
    position: absolute;
    top: 6px;
    right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    color: #b42318;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s;
}

.fp-tile:hover .fp-tile__delete, .fp-tile__delete:focus-visible { opacity: 1; }
.fp-tile__delete:hover { background: #fde4e1; }

@media (hover: none) { .fp-tile__delete { opacity: 1; } }

.fp-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #fff4d6;
    color: #92590a;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.fp-badge--ok { background: #dff5e7; color: #17713c; }

/* ── Document rows ── */
.fp-rows { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }

.fp-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--fp-line);
    border-radius: 12px;
    background: var(--fp-surface);
}
.fp-row.is-selected { border-color: var(--fp-brand); box-shadow: 0 0 0 3px var(--fp-brand-soft); }
.fp-row.is-new { border-color: #d08a0b; }
.fp-row__icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--fp-brand-soft); color: var(--fp-brand); font-size: 19px; }
.fp-row__main { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; margin-right: auto; padding: 0; border: none; background: transparent; text-align: left; cursor: pointer; }
.fp-row__name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; color: var(--fp-ink); }
.fp-row__meta { font-size: 11px; color: var(--fp-muted); }
.fp-row__main:hover .fp-row__name { text-decoration: underline; }

/* ── Footer ── */
.fp-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 22px;
    border-top: 1px solid var(--fp-line);
    background: var(--fp-surface);
}
.fp-foot__note { color: var(--fp-muted); }

/* ── Delete confirmation ── */
.fp-confirm {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.55);
}

.fp-confirm__card {
    width: min(420px, 100%);
    padding: 20px;
    border-radius: 16px;
    background: var(--fp-surface);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
}

.fp-confirm__card h3 { margin: 0 0 10px; font-size: 17px; font-weight: 800; }
.fp-confirm__card p { margin: 0; color: var(--fp-muted); line-height: 1.5; word-break: break-word; }
.fp-confirm__preview { display: block; max-width: 100%; max-height: 150px; margin: 0 auto 12px; object-fit: contain; border-radius: 10px; border: 1px solid var(--fp-line); }
.fp-confirm__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.fp-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: fp-spin 0.7s linear infinite;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }

[data-theme-mode="dark"] .fp-alert--error { background: rgba(230, 80, 70, 0.2); color: #f39a92; }
[data-theme-mode="dark"] .fp-alert--ok { background: rgba(50, 180, 100, 0.2); color: #7fd9a2; }
[data-theme-mode="dark"] .fp-tile, [data-theme-mode="dark"] .fp-stage__preview { background-color: #fff; }

@media (max-width: 640px) {
    .fp-stage { flex-direction: column; }
    .fp-stage__preview { width: 100%; height: 180px; }
    .fp-head, .fp-body, .fp-foot { padding-left: 14px; padding-right: 14px; }
}
