/* =========================================================================
   Bitácora de Trabajos – La Discusión
   CSS propio, sin frameworks. Mobile-first.
   ========================================================================= */

:root {
    --brand: #1f3a5f;
    --brand-600: #2a4d7a;
    --brand-50: #eef3f9;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1c2430;
    --muted: #667085;
    --border: #e3e6eb;
    --pending: #b45309;
    --pending-bg: #fef3c7;
    --done: #15803d;
    --done-bg: #dcfce7;
    --info: #1d4ed8;
    --info-bg: #dbeafe;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font: 15px/1.5 var(--font);
    color: var(--text);
    background: var(--bg);
}

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

h1, h2 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }

code, .mono { font-family: var(--mono); font-size: .9em; }
.mono { white-space: nowrap; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; }
.error-text { color: var(--danger); font-size: .8rem; display: block; }
[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.topbar {
    background: var(--brand);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: .6rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.brand { color: #fff; display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-text small { display: block; font-weight: 400; opacity: .75; font-size: .75rem; }
.brand-mark {
    width: 28px; height: 28px; border-radius: 7px; flex: none;
    background:
        linear-gradient(#fff, #fff) 6px 7px / 16px 3px no-repeat,
        linear-gradient(#fff, #fff) 6px 13px / 16px 3px no-repeat,
        linear-gradient(#fff, #fff) 6px 19px / 10px 3px no-repeat,
        rgba(255, 255, 255, .18);
}
.brand-mark-lg { display: block; width: 48px; height: 48px; margin: 0 auto .75rem; background-color: var(--brand);
    background-size: 28px 5px, 28px 5px, 18px 5px; background-position: 10px 12px, 10px 22px, 10px 32px; }

.nav-toggle {
    margin-left: auto; background: transparent; border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 8px; width: 40px; height: 36px; cursor: pointer;
}
.nav-toggle .bars, .nav-toggle .bars::before, .nav-toggle .bars::after {
    display: block; width: 18px; height: 2px; background: #fff; margin: 0 auto; position: relative; content: "";
}
.nav-toggle .bars::before { position: absolute; top: -6px; }
.nav-toggle .bars::after { position: absolute; top: 6px; }

.nav { display: none; width: 100%; flex-direction: column; gap: .25rem; padding-bottom: .5rem; }
.nav.open { display: flex; }
.nav a { color: #fff; opacity: .85; padding: .45rem .6rem; border-radius: 6px; }
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .1); text-decoration: none; }
.nav a.active { opacity: 1; background: rgba(255, 255, 255, .18); }
.nav-user { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; }
.nav-user-name { opacity: .85; }

@media (min-width: 900px) {
    .nav-toggle { display: none; }
    .nav { display: flex; flex-direction: row; width: auto; margin-left: auto; padding: 0; align-items: center; }
    .nav-user { margin-left: .75rem; padding-left: .75rem; border-left: 1px solid rgba(255, 255, 255, .25); }
}

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.footer { color: var(--muted); font-size: .8rem; text-align: center; padding-bottom: 2rem; }

.page-head {
    display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between;
    margin: .5rem 0 1rem;
}
.page-head h1 { margin: 0; }
.count { font-weight: 400; font-size: 1rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}
.card.narrow { max-width: 640px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.link-sm { font-size: .85rem; }
.empty { color: var(--muted); text-align: center; padding: 1.25rem; }

.grid-2 { display: grid; gap: 1rem; }
@media (min-width: 800px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Contadores ---------- */
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(2, 1fr); margin-bottom: 1rem; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
    display: flex; flex-direction: column; gap: .15rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: .9rem 1rem; color: var(--text); border-top: 3px solid var(--brand);
}
a.stat:hover { text-decoration: none; border-color: var(--brand-600); }
.stat-pending { border-top-color: var(--pending); }
.stat-done { border-top-color: var(--done); }
.stat-sync.is-stale { border-top-color: var(--danger); }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat-value-sm { font-size: 1.15rem; padding: .35rem 0; }
.stat-hint { font-size: .8rem; color: var(--muted); }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list-link { display: flex; flex-direction: column; padding: .55rem 0; color: var(--text); }
.list-link:hover { text-decoration: none; }
.list-link:hover .list-title { color: var(--brand-600); }
.list-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-meta { font-size: .8rem; color: var(--muted); }
.list-row { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; align-items: center; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; font-size: .72rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px;
    background: #eef0f3; color: #475467; white-space: nowrap; vertical-align: middle;
}
.badge-solicitado { background: var(--pending-bg); color: var(--pending); }
.badge-realizado { background: var(--done-bg); color: var(--done); }
.badge-followup { background: var(--info-bg); color: var(--info); }
.badge-kind-solicitud { background: var(--brand-50); color: var(--brand); }
.badge-kind-respuesta { background: var(--done-bg); color: var(--done); }
.badge-outcome-ticket_creado, .badge-run-ok { background: var(--done-bg); color: var(--done); }
.badge-outcome-respuesta { background: var(--done-bg); color: var(--done); }
.badge-outcome-seguimiento { background: var(--info-bg); color: var(--info); }
.badge-outcome-error, .badge-outcome-descartado, .badge-run-fallido { background: var(--danger-bg); color: var(--danger); }
.badge-run-con_errores { background: var(--pending-bg); color: var(--pending); }

/* ---------- Alertas ---------- */
.alert {
    padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent;
    background: var(--info-bg); color: #1e3a8a;
}
.alert-success { background: var(--done-bg); color: #14532d; }
.alert-error { background: var(--danger-bg); color: #7f1d1d; }
.alert-warning { background: var(--pending-bg); color: #78350f; }
.alert-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.inline-forms { display: flex; gap: .5rem; }

/* ---------- Formularios ---------- */
.form { display: flex; flex-direction: column; gap: .75rem; }
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.field input, .field select, .field textarea {
    font: inherit; font-size: 15px; color: var(--text); background: #fff;
    border: 1px solid #cfd4dc; border-radius: 8px; padding: .55rem .65rem; width: 100%; min-width: 0;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid rgba(42, 77, 122, .25); border-color: var(--brand-600);
}
.field-check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
.field-check input { width: auto; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
    padding: .6rem 1rem; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
    text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-success { background: var(--done); color: #fff; }
.btn-ghost { background: #fff; color: var(--brand); border-color: #cfd4dc; }
.topbar .btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .4); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; }

.filters summary { cursor: pointer; font-weight: 600; }
.filter-grid { display: grid; gap: .75rem; margin-top: .75rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .filter-grid { grid-template-columns: repeat(3, 1fr); } .field-wide { grid-column: 1 / -1; } }
@media (min-width: 1000px) { .filter-grid { grid-template-columns: repeat(4, 1fr); } .field-wide { grid-column: span 2; } }
.filter-actions { display: flex; gap: .5rem; align-items: flex-end; }
.filter-inline { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-inline .field { min-width: 180px; flex: 1; }

.radio-group { border: 0; padding: 0; margin: 0; display: flex; gap: 1.25rem; flex-wrap: wrap; }
.radio-group legend { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }

/* ---------- Tablas (se convierten en tarjetas en móvil) ---------- */
.table-wrap { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
    background: #fafbfc; padding: .6rem .75rem; border-bottom: 1px solid var(--border);
}
.table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover { background: #fafbfd; }
.cell-subject .subject { font-weight: 600; color: var(--text); display: block; }
.cell-subject .preview { display: block; color: var(--muted); font-size: .85rem; }
.meta-icons { display: inline-flex; gap: .6rem; font-size: .8rem; color: var(--muted); }

@media (max-width: 760px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
    .table-cards tbody tr:last-child { border-bottom: 0; }
    .table-cards td { border: 0; padding: .1rem 0; }
    /* Etiqueta y valor en la misma línea para tarjetas compactas */
    .table-cards td[data-label] { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: .5rem; align-items: baseline; }
    .table-cards td[data-label]::before {
        content: attr(data-label); font-size: .7rem; color: var(--muted);
        text-transform: uppercase; letter-spacing: .03em;
    }
    .table-cards td.cell-subject { display: block; padding: .25rem 0 .4rem; }
    .table-cards td.cell-subject::before { display: none; }
}

.pagination { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin: 1rem 0; }
.pagination a, .pagination span {
    padding: .4rem .7rem; border-radius: 6px; border: 1px solid var(--border); background: #fff; font-size: .9rem;
}
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination .gap { border: 0; background: transparent; }

/* ---------- Detalle de ticket ---------- */
.ticket-head h1 { margin: .25rem 0; word-break: break-word; }
.ticket-badges { display: flex; gap: .4rem; flex-wrap: wrap; }
.ticket-layout { display: grid; gap: 1rem; }
@media (min-width: 1000px) { .ticket-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } }

.timeline { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.message {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: .9rem 1rem; border-left: 4px solid var(--brand);
}
.message-out { border-left-color: var(--done); background: #fbfefc; }
.message-seguimiento.message-in { border-left-color: var(--info); }
.message-head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.message-head time { margin-left: auto; }
.message-recipients { margin-top: .25rem; word-break: break-word; }
.message-body { margin-top: .6rem; white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
.message-body.quoted { color: #475467; font-size: .9rem; border-left: 3px solid var(--border); padding-left: .75rem; }
.message-more { margin-top: .6rem; }
.message-more summary { cursor: pointer; font-size: .85rem; color: var(--brand-600); }
.message-html { margin-top: .5rem; padding: .75rem; border: 1px dashed var(--border); border-radius: 8px; overflow-x: auto; font-size: .9rem; }
.message-html table { border-collapse: collapse; }
.message-html td, .message-html th { border: 1px solid var(--border); padding: .25rem .4rem; }
.attachments { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-direction: column; gap: .25rem; }
.attachments li { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }

.details { margin: 0; display: grid; grid-template-columns: 1fr; gap: .1rem; }
.details dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: .5rem; }
.details dd { margin: 0; word-break: break-word; }

.notes { list-style: none; padding: 0; margin: 0 0 .75rem; }
.notes li { border-top: 1px solid var(--border); padding: .6rem 0; }
.notes li:first-child { border-top: 0; }
.note-body { margin-top: .2rem; white-space: normal; }

.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .4rem 0; border-top: 1px solid var(--border); }
.history li:first-child { border-top: 0; }

/* ---------- Login / errores ---------- */
body.guest { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.guest-wrap { width: 100%; max-width: 400px; }
.login-card { padding: 1.75rem 1.5rem; }
.login-head { text-align: center; margin-bottom: 1.25rem; }
.login-head h1 { font-size: 1.25rem; margin: 0; }
.login-head p { margin: .2rem 0 0; }

.error-page { text-align: center; margin: 2rem auto; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--brand); margin: 0; }
.debug { text-align: left; white-space: pre-wrap; font-size: .75rem; background: #111827; color: #e5e7eb; padding: 1rem; border-radius: 8px; overflow-x: auto; }
