/* ============================================================================
   „Codul meu" — stratul personal de adnotări pe articole (marker, pix, bold,
   notițe). Touch-first: bara de unelte jos + preview live la drag.
   ============================================================================ */

:root {
    /* Marker (fundal pastel) */
    --an-hl-galben: #fde68a;
    --an-hl-verde: #bbf7d0;
    --an-hl-roz: #fbcfe8;
    --an-hl-albastru: #bfdbfe;
    /* Pix (linii saturate) */
    --an-pen-galben: #d97706;
    --an-pen-verde: #15803d;
    --an-pen-roz: #be185d;
    --an-pen-albastru: #1d4ed8;
}

/* ---- Textul articolului ---------------------------------------------------- */

.an-container { position: relative; }

.an-textbody {
    white-space: pre-wrap;
    font-size: 1rem;
    line-height: 1.8;
    color: var(--pg-ink, #1f2430);
    word-break: break-word;
}

/* Explicații salvate: Markdown formatat (titluri/liste), deci flux normal, nu pre-wrap. */
.an-textbody.an-md {
    white-space: normal;
    line-height: 1.7;
}
.an-textbody.an-md h3, .an-textbody.an-md h4 { line-height: 1.35; }

/* Marker: colțuri moi + continuitate la capetele de linie, ca un marker real. */
.an-hl-galben, .an-hl-verde, .an-hl-roz, .an-hl-albastru {
    border-radius: 3px;
    padding: 0.08em 0;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.an-hl-galben { background: var(--an-hl-galben); }
.an-hl-verde { background: var(--an-hl-verde); }
.an-hl-roz { background: var(--an-hl-roz); }
.an-hl-albastru { background: var(--an-hl-albastru); }

/* Pix: subliniere colorată. */
.an-ul-galben, .an-ul-verde, .an-ul-roz, .an-ul-albastru {
    text-decoration-line: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}
.an-ul-galben { text-decoration-color: var(--an-pen-galben); }
.an-ul-verde { text-decoration-color: var(--an-pen-verde); }
.an-ul-roz { text-decoration-color: var(--an-pen-roz); }
.an-ul-albastru { text-decoration-color: var(--an-pen-albastru); }

.an-b { font-weight: 700; }

/* Zona ancorată a unei notițe: punctat discret, colorat ca post-it-ul. */
.an-note { border-bottom: 2px dotted; cursor: pointer; }
.an-note-galben { border-bottom-color: var(--an-pen-galben); }
.an-note-verde { border-bottom-color: var(--an-pen-verde); }
.an-note-roz { border-bottom-color: var(--an-pen-roz); }
.an-note-albastru { border-bottom-color: var(--an-pen-albastru); }

/* Chip-ul 📌 de la capătul notiței. */
.an-chip {
    border: none;
    border-radius: 8px;
    padding: 0 5px;
    margin: 0 3px;
    font-size: 0.85em;
    line-height: 1.5;
    cursor: pointer;
    vertical-align: baseline;
}
.an-chip-galben { background: var(--an-hl-galben); }
.an-chip-verde { background: var(--an-hl-verde); }
.an-chip-roz { background: var(--an-hl-roz); }
.an-chip-albastru { background: var(--an-hl-albastru); }

/* ---- Modul adnotare (unealtă activă) --------------------------------------- */

/* Degetul „scrie" pe text: fără scroll din text, fără selecție nativă/callout iOS. */
.an-container.an-active .an-textbody {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    cursor: crosshair;
}

/* Preview live (pur client-side, până la commit). */
.an-color-galben { --an-prev-bg: var(--an-hl-galben); --an-prev-pen: var(--an-pen-galben); }
.an-color-verde { --an-prev-bg: var(--an-hl-verde); --an-prev-pen: var(--an-pen-verde); }
.an-color-roz { --an-prev-bg: var(--an-hl-roz); --an-prev-pen: var(--an-pen-roz); }
.an-color-albastru { --an-prev-bg: var(--an-hl-albastru); --an-prev-pen: var(--an-pen-albastru); }

.an-mode-marker .an-prev { background: var(--an-prev-bg, #fde68a); border-radius: 3px; }
.an-mode-pen .an-prev {
    text-decoration-line: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    text-decoration-color: var(--an-prev-pen, #d97706);
}
.an-mode-bold .an-prev { font-weight: 700; }
.an-mode-note .an-prev { background: var(--an-prev-bg, #fde68a); border-radius: 3px; opacity: 0.8; }
.an-mode-erase .an-prev { opacity: 0.35; text-decoration: line-through; }

/* Flash la deep-link din „Codul meu". */
@keyframes an-flash-kf {
    0% { outline: 3px solid rgba(63, 81, 224, 0.9); outline-offset: 2px; }
    100% { outline: 3px solid rgba(63, 81, 224, 0); outline-offset: 2px; }
}
.an-flash { animation: an-flash-kf 2s ease-out; }

/* ---- FAB + bara de unelte --------------------------------------------------- */

.an-fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--pg-nav-h, 56px) + env(safe-area-inset-bottom) + 16px);
    z-index: 60;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #3f51e0, #7048e8);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 22px rgba(63, 81, 224, 0.4);
    cursor: pointer;
    transition: transform 0.15s;
}
.an-fab:active { transform: scale(0.94); }
.an-fab .mud-icon-root { font-size: 26px; width: 26px; height: 26px; }

.an-toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--pg-nav-h, 56px) + env(safe-area-inset-bottom));
    z-index: 55;
    background: var(--pg-surface, #fff);
    border-top: 1px solid var(--pg-line, #e5e7eb);
    box-shadow: 0 -8px 28px rgba(20, 24, 40, 0.1);
    padding: 8px 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.an-tools {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
}
.an-tools::-webkit-scrollbar { display: none; }

.an-tool {
    flex: 1;
    min-width: 54px;
    height: 52px;
    border-radius: 12px;
    border: 1px solid var(--pg-line, #e5e7eb);
    background: var(--pg-surface, #fff);
    color: var(--pg-ink-2, #5a6072);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    font-size: 10.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.an-tool .mud-icon-root { font-size: 20px; width: 20px; height: 20px; }
.an-tool .an-tool-emoji { font-size: 18px; line-height: 20px; }
.an-tool.active {
    background: #eef0fd;
    border-color: var(--pg-primary, #3f51e0);
    color: var(--pg-primary, #3f51e0);
}

.an-colors {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
}
.an-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.08);
    cursor: pointer;
    padding: 0;
}
.an-swatch.sel { border: 3px solid var(--pg-ink, #1f2430); }
.an-swatch-galben { background: var(--an-hl-galben); }
.an-swatch-verde { background: var(--an-hl-verde); }
.an-swatch-roz { background: var(--an-hl-roz); }
.an-swatch-albastru { background: var(--an-hl-albastru); }

.an-toolbar-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--pg-ink-2, #5a6072);
}

/* ---- Mini-meniul la selecția cu mouse-ul (desktop) ---------------------------- */

.an-selmenu {
    position: fixed;
    z-index: 65;
    transform: translate(-50%, -115%);
    background: var(--pg-surface, #fff);
    border: 1px solid var(--pg-line, #e5e7eb);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(20, 24, 40, 0.18);
    padding: 8px 10px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.an-selmenu .an-swatch { width: 24px; height: 24px; }
.an-selbtn {
    border: none;
    background: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pg-ink-2, #5a6072);
}
.an-selbtn:hover { background: #f0f1fa; color: var(--pg-primary, #3f51e0); }

/* ---- Bottom sheet pentru notițe --------------------------------------------- */

.an-sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(15, 18, 30, 0.35);
}
.an-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 71;
    background: var(--pg-surface, #fff);
    border-radius: 18px 18px 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    max-height: 75dvh;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 -12px 40px rgba(20, 24, 40, 0.25);
}
.an-sheet-quote {
    font-size: 0.82rem;
    color: var(--pg-ink-2, #5a6072);
    border-left: 3px solid var(--pg-line, #e5e7eb);
    padding-left: 10px;
    max-height: 72px;
    overflow: hidden;
    font-style: italic;
}
.an-sheet textarea {
    min-height: 120px;
    border: 1px solid var(--pg-line, #e5e7eb);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    resize: vertical;
    outline-color: var(--pg-primary, #3f51e0);
}
.an-sheet-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}
.an-sheet-actions .an-delete { margin-right: auto; }

/* ---- CTA pentru anonimi ------------------------------------------------------ */

.an-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 999px;
    background: #eef0fd;
    color: var(--pg-primary, #3f51e0);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

/* ---- „Codul meu" (vederea de ansamblu) ---------------------------------------- */

.an-myitem {
    display: block;
    padding: 6px 8px;
    margin: 2px -8px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--pg-ink, #1f2430);
    font-size: 0.9rem;
    line-height: 1.6;
}
.an-myitem:hover { background: #f4f5fb; }
.an-myquote { border-radius: 3px; padding: 0.06em 2px; }
.an-mynote {
    display: block;
    margin-top: 4px;
    font-size: 0.84rem;
    color: var(--pg-ink-2, #5a6072);
    white-space: pre-wrap;
}

/* ---- Print („Codul meu" ca listă de revizuit) ---------------------------------- */

@media print {
    .pg-topbar, .pg-nav, .an-fab, .an-toolbar, .cm-no-print { display: none !important; }
    .pg-main { max-width: 100% !important; padding: 0 !important; }
    .pg-shell { background: #fff !important; }
    .an-myitem { break-inside: avoid; }
    .mud-paper { box-shadow: none !important; border: 1px solid #ddd; }
}

/* ---- Desktop ------------------------------------------------------------------ */

@media (min-width: 768px) {
    .an-fab { bottom: 24px; }
    .an-toolbar {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        bottom: 20px;
        width: min(560px, calc(100vw - 32px));
        border: 1px solid var(--pg-line, #e5e7eb);
        border-radius: 18px;
    }
    .an-sheet {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        bottom: 24px;
        width: min(560px, calc(100vw - 32px));
        border-radius: 18px;
    }
}
