/* Lamas Pisano — estilos base. Paleta tomada del logo (cartel azul noche +
   texto hueso). Desktop-first para gestión, responsive para chat/notif. */

:root {
    --color-bg: #f5f3ee;
    --color-surface: #ffffff;
    --color-border: #e4ded1;
    --color-text: #23283a;
    --color-muted: #6b6f7d;
    --color-primary: #3b4568;
    --color-primary-dark: #1f2436;
    --color-accent: #ede6d3;
    --color-danger: #dc2626;
    --color-ok: #16a34a;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 1px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 2rem 4rem; }

.muted { color: var(--color-muted); }
.hint { color: var(--color-muted); font-size: .85rem; margin-top: .25rem; }

/* Layout general: menú lateral vertical + contenido a la derecha */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
    width: 230px; flex-shrink: 0;
    background: var(--color-primary-dark); color: #fff;
    display: flex; flex-direction: column;
}
.sidebar__brand { padding: 1rem 1.1rem; display: flex; align-items: center; justify-content: space-between; }
.sidebar__brand a { color: #fff; font-weight: 700; font-size: 1.1rem; }
.sidebar__logo { display: block; line-height: 0; }
.sidebar__logo img {
    width: 64px; height: 64px; object-fit: cover; border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.sidebar__cerrar { display: none; background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer; }
.sidebar__nav { display: flex; flex-direction: column; gap: .1rem; padding: .5rem; flex: 1; overflow-y: auto; }
.sidebar__nav a {
    color: rgba(255,255,255,.8); padding: .6rem .75rem; border-radius: 6px; font-size: .92rem;
}
.sidebar__nav a:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.sidebar__nav a.is-active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.sidebar__user {
    padding: 1rem 1.1rem; border-top: 1px solid rgba(255,255,255,.15);
    display: flex; flex-direction: column; gap: .5rem; font-size: .85rem; color: rgba(255,255,255,.9);
}
.sidebar__fondo { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-mini {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem 1.5rem; border-bottom: 1px solid var(--color-border); background: var(--color-surface);
}
.topbar-mini__acciones { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

[data-sidebar-abrir] { display: none; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; width: 260px;
        transform: translateX(-100%); transition: transform .2s ease; z-index: 100;
    }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar__cerrar { display: block; }
    [data-sidebar-abrir] { display: inline-flex; }
}

.link-button {
    background: none; border: none; color: var(--color-primary); cursor: pointer;
    font-size: .9rem; padding: 0; text-decoration: underline;
}
.link-button--claro { color: rgba(255,255,255,.85); }
.inline-form { display: inline; }

/* Cards / grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.card--stat { text-align: center; }
.card--stat__label { display: block; color: var(--color-muted); font-size: .85rem; }
.card--stat__value { display: block; font-size: 1.75rem; font-weight: 700; margin-top: .25rem; }
.card--link { display: block; color: inherit; }
.card--link:hover { text-decoration: none; border-color: var(--color-primary); }

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 800px) {
    .two-col { grid-template-columns: 1fr; }
    .container { padding: 1rem; }
    .topbar { padding: .75rem 1rem; gap: 1rem; }
}

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: .65rem .9rem; border-bottom: 1px solid var(--color-border); text-align: left; }
.table th { background: #fafbfc; font-size: .8rem; text-transform: uppercase; color: var(--color-muted); letter-spacing: .02em; }
.table tbody tr:hover { background: #f8fafc; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .5rem 0; border-bottom: 1px solid var(--color-border); }
.list li:last-child { border-bottom: none; }

.def-list { display: grid; grid-template-columns: 140px 1fr; row-gap: .5rem; margin: 0; }
.def-list dt { color: var(--color-muted); font-size: .85rem; }
.def-list dd { margin: 0; }

/* Badges */
.badge {
    display: inline-block; padding: .15rem .55rem; border-radius: 999px;
    background: #eef2ff; color: #3730a3; font-size: .75rem; font-weight: 600;
}
.badge--abierto { background: #dcfce7; color: #166534; }
.badge--en_tramite { background: #fef9c3; color: #854d0e; }
.badge--suspendido { background: #fee2e2; color: #991b1b; }
.badge--cerrado { background: #e5e7eb; color: #374151; }
.badge--archivado { background: #f1f5f9; color: #64748b; }
.badge--modulo { background: #e0e7ff; color: #3730a3; }

/* Forms */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 640px;
    box-shadow: var(--shadow);
}
.form-row { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .35rem; }
.form-row-group { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
label { font-size: .85rem; font-weight: 600; color: #374151; }
input, select, textarea {
    padding: .55rem .7rem; border: 1px solid var(--color-border); border-radius: 6px;
    font-size: .95rem; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.checkbox-list { display: flex; flex-direction: column; gap: .4rem; max-height: 200px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: 6px; padding: .6rem; }
.checkbox-list__item { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkbox-list__item input { width: auto; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }
.error-msg { color: var(--color-danger); font-size: .8rem; }

/* Buttons */
.btn {
    display: inline-block; padding: .5rem 1rem; border-radius: 6px; border: 1px solid var(--color-border);
    background: var(--color-surface); color: var(--color-text); cursor: pointer; font-size: .9rem; font-weight: 600;
}
.btn:hover { text-decoration: none; background: #f3f4f6; }
.btn--primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn--primary:hover { background: var(--color-primary-dark); }
.btn--sm { padding: .3rem .7rem; font-size: .8rem; }
.btn--block { width: 100%; text-align: center; }

/* Page layout helpers */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }
.page-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9rem; }
.alert--ok { background: #dcfce7; color: #166534; }
.alert--error { background: #fee2e2; color: #991b1b; }

/* Auth */
.auth-body { display: flex; align-items: flex-start; justify-content: center; min-height: 100vh; background: var(--color-primary-dark); padding: 3rem 1rem; }
.auth-wrap { display: flex; gap: 2rem; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.auth-card {
    background: #fff; padding: 2.5rem; border-radius: var(--radius); width: 100%; max-width: 380px;
    display: flex; flex-direction: column; gap: .9rem; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.auth-card h1 { margin-bottom: 0; }
.auth-card__logo { width: 100%; max-width: 220px; border-radius: var(--radius); align-self: center; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.auth-card__subtitle { margin: 0 0 .5rem; color: var(--color-muted); text-align: center; }

/* Login rápido (solo desarrollo) */
.dev-login { max-width: 420px; gap: .5rem; }
.dev-login__badge {
    background: #fef3c7; color: #92400e; padding: .5rem .75rem; border-radius: 6px;
    font-size: .8rem; font-weight: 600; margin: 0 0 .5rem;
}
.dev-login h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--color-muted); margin: .5rem 0 .35rem; }
.dev-login__grid { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.dev-login__btn { font-size: .85rem; padding: .4rem .8rem; }

/* Tabs */
.tabs__nav { display: flex; gap: .25rem; border-bottom: 2px solid var(--color-border); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs__btn {
    background: none; border: none; padding: .6rem 1rem; cursor: pointer; font-size: .9rem; font-weight: 600;
    color: var(--color-muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tabs__btn.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tabs__panel { display: none; }
.tabs__panel.is-active { display: block; }

/* Sub-pestañas anidadas (ej. Finanzas dentro de un caso) — un toque más chicas */
.tabs--anidadas > .tabs__nav { margin-bottom: 1rem; border-bottom-width: 1px; }
.tabs--anidadas > .tabs__nav .tabs__btn { padding: .45rem .8rem; font-size: .85rem; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item { padding: .75rem 0; border-left: 2px solid var(--color-border); padding-left: 1rem; margin-left: .4rem; }
.timeline__fecha { color: var(--color-muted); font-size: .8rem; margin-right: .5rem; }

@media (max-width: 600px) {
    .form-row-group { grid-template-columns: 1fr; }
    .def-list { grid-template-columns: 1fr; }
}

/* Notificaciones */
.icon-button {
    background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer;
    position: relative; padding: .25rem .4rem; border-radius: 6px;
}
.icon-button:hover { background: rgba(255,255,255,.12); }
.icon-button--oscuro { color: var(--color-text); }
.icon-button--oscuro:hover { background: #f1f5f9; }
.notif-badge {
    position: absolute; top: -2px; right: -2px; background: var(--color-danger); color: #fff;
    font-size: .65rem; font-weight: 700; border-radius: 999px; min-width: 16px; height: 16px;
    align-items: center; justify-content: center; padding: 0 3px;
}
.notif-badge:not([hidden]) { display: flex; }
.notif-panel {
    position: absolute; right: 0; top: calc(100% + 8px); width: 320px; max-height: 400px; overflow-y: auto;
    background: var(--color-surface); color: var(--color-text); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.25);
    z-index: 50; border: 1px solid var(--color-border);
}
.notif-panel__header { padding: .75rem 1rem; font-weight: 700; border-bottom: 1px solid var(--color-border); }
.notif-item { display: block; padding: .65rem 1rem; border-bottom: 1px solid var(--color-border); font-size: .85rem; color: inherit; }
.notif-item:hover { background: #f8fafc; text-decoration: none; }
.notif-item.is-unread { background: #eff6ff; }

/* Modal de "¿avisarle a alguien?" */
.notif-modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; align-items: center; justify-content: center; padding: 1rem; }
.notif-modal:not([hidden]) { display: flex; }
.notif-modal__caja { background: var(--color-surface); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.notif-modal__caja h3 { margin-top: 0; }
.notif-modal__caja .checkbox-list { margin: 1rem 0; max-height: 240px; }

/* Chat */
.chat-widget { display: flex; flex-direction: column; height: 420px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
.chat-widget__lista { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.chat-msg__meta { font-size: .75rem; color: var(--color-muted); margin-bottom: .15rem; }
.chat-msg__cuerpo { font-size: .9rem; white-space: pre-wrap; word-break: break-word; }
.chat-msg__adjunto { display: inline-block; margin-top: .25rem; font-size: .85rem; }
.chat-mencion { background: #eef2ff; color: #3730a3; padding: 0 .2rem; border-radius: 4px; font-weight: 600; }
.chat-widget__form { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid var(--color-border); align-items: flex-end; }
.chat-widget__form textarea { flex: 1; resize: none; min-height: 40px; }
.chat-widget__form input[type="file"] { max-width: 140px; font-size: .75rem; }

/* Stats de facturación */
.stat-inline { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-inline__item { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: .75rem 1.25rem; }
.stat-inline__item strong { display: block; font-size: 1.25rem; }

.badge--pendiente { background: #fef9c3; color: #854d0e; }
.badge--parcial { background: #dbeafe; color: #1e40af; }
.badge--saldada { background: #dcfce7; color: #166534; }
.badge--vencida { background: #fee2e2; color: #991b1b; }
.badge--completada { background: #dcfce7; color: #166534; }

/* Campos personalizados (editor Quill) */
.campo-editor { background: #fff; margin-bottom: .75rem; }
.campo-editor .ql-editor { min-height: 120px; font-size: .9rem; }
.campo-editor-fuente { display: none; }

/* Agenda — filtros */
.agenda-filtros {
    display: flex; gap: 1.75rem; flex-wrap: wrap; align-items: flex-start;
    padding: 1rem 1.25rem; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius); margin-bottom: 1.25rem;
}
.agenda-filtro { display: flex; flex-direction: column; gap: .4rem; min-width: 160px; }
.agenda-filtro label { font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; color: var(--color-muted); }
.agenda-filtro__acciones { display: flex; gap: .4rem; margin-bottom: .1rem; }
.agenda-filtro__acciones button { font-size: .75rem; padding: .2rem .55rem; }
.agenda-filtro .checkbox-list { max-height: 140px; border: none; padding: 0; gap: .25rem; }
.agenda-filtro .checkbox-list__item { font-size: .85rem; font-weight: 400; }

/* Agenda — calendario mensual */
.calendario-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.calendario-header h2 { margin: 0; flex: 1; text-transform: capitalize; }
.calendario {
    display: grid; grid-template-columns: repeat(7, 1fr);
    border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden;
    background: var(--color-border);
    gap: 1px;
}
.calendario__dia-header {
    background: #fafbfc; padding: .5rem; text-align: center; font-size: .72rem;
    text-transform: uppercase; color: var(--color-muted); font-weight: 700;
}
.calendario__celda { min-height: 108px; padding: .3rem; background: #fff; display: flex; flex-direction: column; gap: .2rem; }
.calendario__celda.fuera-de-mes { background: #fafbfc; }
.calendario__celda.fuera-de-mes .calendario__numero { color: #cbd5e1; }
.calendario__celda.es-hoy { background: #eff6ff; }
.calendario__numero { font-size: .78rem; font-weight: 700; color: var(--color-text); }
.calendario__eventos { display: flex; flex-direction: column; gap: .15rem; overflow-y: auto; max-height: 78px; }
.calendario__evento {
    /* El color de fondo lo pone JS inline (background-color), según el
       tipo de recordatorio elegido — los tipos ahora son configurables. */
    font-size: .7rem; padding: .1rem .4rem; border-radius: 4px; color: #fff; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.calendario__evento.is-completado { opacity: .5; text-decoration: line-through; }

.evento-modal__meta { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }

@media (max-width: 800px) {
    .calendario__celda { min-height: 70px; }
    .calendario__dia-header { font-size: .62rem; padding: .3rem .15rem; }
    .calendario__evento { font-size: .62rem; }
}
