/* ============================================================
   Mis Notas · hoja de estilos
   ============================================================ */

:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --border: #e5e7ef;
    --text: #1b2033;
    --muted: #6b7280;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #dc2626;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--primary);
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: #f1f2f8;
    padding: 1px 6px;
    border-radius: 6px;
    font-size: .9em;
}

.container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px;
}

.main {
    flex: 1;
    padding-bottom: 60px;
}

/* ---------- Barra superior ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -.01em;
    color: var(--text);
    text-decoration: none;
}

.brand svg {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

/* ---------- Botones ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    font: inherit;
    font-size: .92rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
}

.btn--primary {
    background: var(--primary);
    color: #fff;
}

.btn--primary:hover {
    background: var(--primary-dark);
}

.btn--ghost {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn--ghost:hover {
    border-color: #c9cee0;
}

.btn--danger {
    background: var(--surface);
    border-color: #f3c9c9;
    color: var(--danger);
}

.btn--danger:hover {
    background: #fdf2f2;
}

.btn--sm {
    padding: 6px 12px;
    font-size: .84rem;
}

/* ---------- Avisos ---------- */
.alert {
    margin: 20px 0;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid;
    font-size: .93rem;
}

.alert--success {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}

.alert--error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.alert ul {
    margin: 0;
    padding-left: 20px;
}

/* ---------- Encabezado de página ---------- */
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin: 32px 0 24px;
}

.page-head h1 {
    margin: 0;
    font-size: 1.75rem;
    line-height: 1.25;
    letter-spacing: -.02em;
}

.page-head__sub {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: .9rem;
}

.page-head__actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.note-meta {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: .85rem;
}

.link-back {
    display: inline-block;
    margin-bottom: 6px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
}

.link-back:hover {
    color: var(--primary);
}

/* ---------- Buscador ---------- */
.search {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.search .input {
    min-width: 220px;
    flex: 1;
}

/* ---------- Formularios ---------- */
.input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .95rem;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.field {
    margin-bottom: 22px;
}

.field__label {
    display: block;
    margin-bottom: 8px;
    font-size: .85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}

.note-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
    margin-top: 8px;
}

.inline-form {
    display: inline;
    margin: 0;
}

/* ---------- Editor de texto ---------- */
.editor {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}

.editor:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.editor__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: #fafbff;
    border-bottom: 1px solid var(--border);
}

.tb {
    border: 1px solid transparent;
    background: transparent;
    color: #3d4358;
    border-radius: 8px;
    padding: 6px 10px;
    font: inherit;
    font-size: .84rem;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.2;
}

.tb:hover {
    background: #eef0fb;
}

.tb:active {
    background: #e2e5f7;
}

.tb-sep {
    width: 1px;
    align-self: stretch;
    background: var(--border);
    margin: 2px 6px;
}

.editor__area {
    min-height: 320px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 18px 20px;
}

.editor__area:focus {
    outline: none;
}

.editor__area:empty:before {
    content: attr(data-placeholder);
    color: #a3a8bb;
    pointer-events: none;
}

.editor__input {
    display: none;
}

.editor__meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
    font-size: .78rem;
    color: var(--muted);
}

/* ---------- Tipografía del contenido enriquecido ---------- */
.rich {
    font-size: 1rem;
}

.rich > *:first-child {
    margin-top: 0;
}

.rich > *:last-child {
    margin-bottom: 0;
}

.rich h1,
.rich h2 {
    font-size: 1.35rem;
    line-height: 1.3;
    margin: 1.3em 0 .5em;
    letter-spacing: -.01em;
}

.rich h3,
.rich h4 {
    font-size: 1.1rem;
    margin: 1.2em 0 .4em;
}

.rich p {
    margin: 0 0 .9em;
}

.rich ul,
.rich ol {
    margin: 0 0 .9em;
    padding-left: 1.5em;
}

.rich li {
    margin-bottom: .3em;
}

.rich blockquote {
    margin: 0 0 1em;
    padding: 10px 16px;
    border-left: 3px solid var(--primary);
    background: #f5f5ff;
    color: #414a63;
    border-radius: 0 8px 8px 0;
}

.rich a {
    color: var(--primary);
    text-decoration: underline;
}

.rich pre {
    background: #1b2033;
    color: #e8eaf5;
    padding: 14px 16px;
    border-radius: 10px;
    overflow-x: auto;
}

.rich pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.rich hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 1.5em 0;
}

/* ---------- Listado en tarjetas ---------- */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.notes-grid .card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform .15s, border-color .15s, box-shadow .15s;
}

.notes-grid .card:hover {
    transform: translateY(-2px);
    border-color: #d6dae8;
    box-shadow: 0 4px 8px rgba(16, 24, 40, .06), 0 14px 32px rgba(16, 24, 40, .08);
}

.card__title {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.35;
}

.card__title a {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text);
    text-decoration: none;
}

.card__title a:hover {
    color: var(--primary);
}

.card__excerpt {
    margin: 0;
    flex: 1;
    color: var(--muted);
    font-size: .92rem;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card__meta {
    margin: 0;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #9aa0b4;
}

.card__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 2px;
}

.card__delete {
    margin: 0 0 0 auto;
}

/* ---------- Nota individual ---------- */
.note-body {
    padding: 28px 32px;
    margin-bottom: 40px;
}

/* ---------- Estado vacío ---------- */
.empty {
    text-align: center;
    padding: 64px 24px;
    background: var(--surface);
    border: 1px dashed #d8dcea;
    border-radius: var(--radius);
}

.empty h2 {
    margin: 0 0 8px;
    font-size: 1.25rem;
}

.empty p {
    margin: 0 0 20px;
    color: var(--muted);
}

/* ---------- Paginación ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 32px;
}

.pagination__info {
    font-size: .85rem;
    color: var(--muted);
}

/* ---------- Pie ---------- */
.footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 20px 0;
}

.footer p {
    margin: 0;
    text-align: center;
    font-size: .82rem;
    color: #9aa0b4;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .page-head {
        align-items: stretch;
    }

    .page-head h1 {
        font-size: 1.45rem;
    }

    .page-head__actions,
    .form-actions {
        width: 100%;
    }

    .form-actions .btn {
        flex: 1;
    }

    .note-form {
        padding: 16px;
    }

    .note-body {
        padding: 20px;
    }

    .search {
        width: 100%;
    }
}

/* ============================================================
   Notas protegidas con contraseña
   ============================================================ */

.is-hidden {
    display: none !important;
}

/* Icono de candado en las tarjetas */
.lock-icon {
    width: 15px;
    height: 15px;
    margin-right: 6px;
    vertical-align: -2px;
    color: var(--primary);
}

.card--locked {
    background: #fbfbfe;
    border-style: dashed;
}

.card--locked .card__excerpt {
    color: #9aa0b4;
    font-style: italic;
}

/* Etiqueta "Con contraseña" */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef0fb;
    color: #4b4fb0;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    vertical-align: 2px;
}

.badge--inline {
    margin-left: 10px;
    vertical-align: middle;
}

/* Caja de la casilla "Proteger esta nota" */
.protect-box {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    background: #fbfbfe;
}

.switch {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
}

.switch input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    accent-color: var(--primary);
    cursor: pointer;
    flex: 0 0 auto;
}

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

.switch__text strong {
    font-size: .95rem;
}

.switch__text small {
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.4;
}

.protect-fields {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed var(--border);
}

.protect-fields .field__label {
    margin-bottom: 6px;
}

.hint {
    margin: 8px 0 0;
    font-size: .8rem;
    line-height: 1.5;
    color: var(--muted);
}

.hint--center {
    text-align: center;
    margin-top: 18px;
}

/* Pantalla de desbloqueo */
.unlock-wrapper {
    display: flex;
    justify-content: center;
    padding: 48px 0 64px;
}

.unlock-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 28px 26px;
    box-shadow: var(--shadow);
    text-align: center;
}

.unlock-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #eef0fb;
    color: var(--primary);
    margin-bottom: 14px;
}

.unlock-card__icon svg {
    width: 26px;
    height: 26px;
}

.unlock-card h1 {
    margin: 0 0 6px;
    font-size: 1.3rem;
    letter-spacing: -.01em;
}

.unlock-card__sub {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: .9rem;
}

.unlock-card .field {
    text-align: left;
    margin-bottom: 16px;
}

.unlock-card .alert {
    text-align: left;
    margin: 0 0 16px;
}

.form-actions--center {
    justify-content: center;
    border-top: 0;
    padding-top: 0;
    margin-top: 4px;
}

.form-actions--center .btn {
    flex: 0 0 auto;
}

.unlock-card .badge {
    margin-bottom: 10px;
}

/* En las tarjetas, el candado va delante del título sin romper el corte de línea */
.card__title .lock-icon {
    flex: 0 0 auto;
}

/* Aviso de contenido cifrado en la vista de la nota */
.note-candado {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 0 0 14px;
    font-size: .82rem;
    color: var(--muted);
}

/* ============================================================
   Cuentas de usuario
   ============================================================ */

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

.topbar__usuario {
    font-size: .85rem;
    color: var(--muted);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar__salir {
    margin: 0;
}

.auth-wrapper {
    display: flex;
    justify-content: center;
    padding: 48px 0 64px;
}

.auth-card {
    width: 100%;
    max-width: 430px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px 28px;
}

.auth-card h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
}

.auth-card__sub {
    margin: 0 0 22px;
    color: var(--muted);
    font-size: .92rem;
}

.auth-card__pie {
    margin: 20px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: .9rem;
    color: var(--muted);
}

@media (max-width: 520px) {
    .topbar__usuario {
        display: none;
    }

    .auth-wrapper {
        padding: 24px 0 40px;
    }

    .auth-card {
        padding: 22px 18px;
    }
}

/* ============================================================
   Copia de notas por correo
   ============================================================ */

.auth-card--ancha {
    max-width: 560px;
}

.copia-datos {
    list-style: none;
    margin: 0 0 22px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.copia-datos li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    font-size: .92rem;
}

.copia-datos li + li {
    border-top: 1px solid var(--border);
}

.copia-datos span {
    color: var(--muted);
}

.copia-datos strong {
    font-weight: 600;
    text-align: right;
    word-break: break-word;
}

.field__ayuda {
    margin: 8px 0 0;
    font-size: .8rem;
    color: var(--muted);
}

.field__ayuda code,
.auth-card code {
    background: #f1f2f7;
    padding: 1px 5px;
    border-radius: 5px;
    font-size: .85em;
}

.input[readonly] {
    background: #f6f7fb;
    color: var(--muted);
}

.btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
}
