/* =========================================================
   Misiones App — CSS base mobile-first
   Sin frameworks. Mobile-first, < 8KB.
   ========================================================= */

:root {
    --c-bg:        #f6f7fb;
    --c-surface:   #ffffff;
    --c-text:      #1f2937;
    --c-muted:     #6b7280;
    --c-border:    #e5e7eb;
    --c-primary:   #0d6efd;
    --c-primary-d: #0b5ed7;
    --c-secondary: #7B2A8E;       /* morado corporativo (Durán Puede Más) */
    --c-secondary-d: #5e1f6e;
    --c-success:   #198754;
    --c-warn:      #f59e0b;
    --c-danger:    #dc3545;
    --c-supervisor:#7B2A8E;       /* supervisor usa el morado de marca */
    --c-admin:     #1a1a2e;       /* admin usa el negro del logo */
    --radius:      12px;
    --shadow:      0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
    --tap:         44px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

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

img { max-width: 100%; height: auto; display: block; }

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

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-main  {
    flex: 1;
    padding: 16px;
    padding-bottom: 88px;
    width: 100%;
    margin: 0 auto;
    /* En desktop: simular ancho de celular. En móvil (< 480px) ignora el max. */
    max-width: 480px;
}

/* Fondo neutro en desktop para que se note el "marco" del teléfono simulado */
@media (min-width: 481px) {
    html, body { background: #e5e7eb; }
}

/* ---------- Header ---------- */
.app-header {
    position: sticky; top: 0; z-index: 30;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 12px 16px;
    display: flex; align-items: center; justify-content: space-between;
    /* En desktop: centrar y limitar ancho como un phone-frame */
    max-width: 480px;
    margin: 0 auto;
    left: 0;
    right: 0;
}
.role-supervisor .app-header { background: var(--c-supervisor); color: #fff; }
.role-supervisor .app-header a, .role-supervisor .app-header .menu-toggle { color: #fff; }
.role-admin .app-header { background: var(--c-admin); color: #fff; }
.role-admin .app-header a, .role-admin .app-header .menu-toggle { color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 1.4em; }
.menu-toggle {
    background: transparent; border: 0; cursor: pointer;
    font-size: 1.6em; padding: 8px; min-height: var(--tap); min-width: var(--tap);
}

/* ---------- Side nav ---------- */
.app-nav {
    position: fixed; top: 0; right: 0; height: 100vh;
    width: 280px; max-width: 80vw;
    background: var(--c-surface);
    box-shadow: -8px 0 24px rgba(0,0,0,.08);
    transform: translateX(100%);
    transition: transform .25s ease;
    padding: 16px;
    z-index: 40;
    display: flex; flex-direction: column; gap: 6px;
    overflow-y: auto;
}
.app-nav.open { transform: translateX(0); }
.app-nav a { display: block; padding: 12px 8px; color: var(--c-text); border-radius: 8px; }
.app-nav a:hover { background: var(--c-bg); text-decoration: none; }
.app-nav hr { border: 0; border-top: 1px solid var(--c-border); margin: 12px 0; }
.nav-user { padding: 8px; color: var(--c-muted); font-size: .9em; }
.nav-logout { color: var(--c-danger) !important; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 480px;
    background: var(--c-surface);
    border-top: 1px solid var(--c-border);
    display: flex; justify-content: space-around;
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    z-index: 20;
}
.bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--c-muted); padding: 6px;
    min-height: var(--tap);
}
.bottom-nav a span { font-size: 1.3em; }
.bottom-nav a small { font-size: .7em; }

/* ---------- Page head ---------- */
.page-head { margin-bottom: 16px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.4rem; }
.page-head p  { margin: 0; color: var(--c-muted); }
.back-link { display: inline-block; margin-bottom: 8px; font-size: .9em; color: var(--c-muted); }

/* ---------- Card grid ---------- */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 540px) {
    .card-grid { grid-template-columns: 1fr 1fr; }
}
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.card-desc { color: var(--c-muted); margin: 0 0 10px; font-size: .92em; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* list cards */
.card-list { display: flex; flex-direction: column; gap: 8px; }
.list-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; }
.list-card-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.list-card-main strong { font-weight: 600; }
.list-card-main small  { color: var(--c-muted); font-size: .82em; }
.list-card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.points { font-weight: 600; color: var(--c-success); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .75em;
    font-weight: 600;
    background: #eef2ff;
    color: var(--c-primary);
    white-space: nowrap;
}
.badge-ok     { background: #d1fae5; color: #065f46; }
.badge-warn   { background: #fef3c7; color: #92400e; }
.badge-off    { background: #fee2e2; color: #991b1b; }
.badge-active { background: #dbeafe; color: #1e40af; }
.badge-points { background: #ede9fe; color: #5b21b6; }

/* ---------- Stats ---------- */
.stats-grid { grid-template-columns: repeat(2, 1fr); }
.stat-card { text-align: center; padding: 20px 12px; }
.stat-num   { display: block; font-size: 2rem; font-weight: 700; color: var(--c-primary); }
.stat-label { display: block; color: var(--c-muted); font-size: .85em; margin-top: 4px; }
.stat-card.warn .stat-num { color: var(--c-warn); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-fieldset {
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--c-surface);
}
.form-fieldset legend { padding: 0 6px; font-weight: 600; }
.form-label { display: flex; flex-direction: column; gap: 4px; font-size: .9em; }
.form-label span { color: var(--c-muted); }
.form-hint  { color: var(--c-muted); font-size: .8em; margin: 4px 0 0; }
.form input, .form select, .form textarea, .form-fieldset input, .form-fieldset select, .form-fieldset textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--c-border);
    border-radius: 10px;
    background: #fff;
    font-size: 1rem;
    min-height: var(--tap);
}
.form textarea { min-height: 80px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* En grid, los items con contenido de tamaño intrínseco (ej. <input type="datetime-local">)
   se desbordan. Forzamos min-width:0 para que el grid los respete y los inputs
   rellenen 100% del espacio disponible. */
.grid-2 > .form-label { min-width: 0; }
.grid-2 > .form-label > input,
.grid-2 > .form-label > select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* ---------- Buttons ---------- */
.btn {
    appearance: none; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; min-height: var(--tap);
    border-radius: 10px; border: 1px solid transparent;
    font-weight: 600; font-size: .95rem;
    background: #f3f4f6; color: var(--c-text);
    text-decoration: none;
    transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: #e5e7eb; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary  { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-d); }
.btn-secondary{ background: #6b7280; color: #fff; }
.btn-secondary:hover { background: #4b5563; }
.btn-danger   { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #b02a37; color: #fff; }
.btn-block    { width: 100%; }
.btn-sm        { padding: 6px 10px; min-height: 36px; font-size: .85rem; gap: 6px; }
.btn-sm.btn-compact { padding: 4px 10px; min-height: 28px; font-size: .82rem; }
.btn-sm svg    { display: block; }
.inline-form  { display: inline; }

/* ---------- Flash messages ---------- */
.flash {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-size: .92em;
}
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-warn    { background: #fef3c7; color: #92400e; }
.flash-info    { background: #dbeafe; color: #1e40af; }

/* ---------- Detail cards ---------- */
.detail-card { margin-bottom: 16px; }
.detail-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 8px 12px; align-items: center; }
.detail-grid strong { color: var(--c-muted); font-weight: 500; }
.warn-card { border-color: var(--c-warn); background: #fffbeb; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center; padding: 48px 16px;
    background: var(--c-surface); border: 1px dashed var(--c-border);
    border-radius: var(--radius); color: var(--c-muted);
}
.empty-icon { font-size: 3em; margin-bottom: 8px; }

/* ---------- Evidence preview ---------- */
.evidence-preview img { border-radius: var(--radius); max-height: 360px; object-fit: cover; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: .88em; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--c-border); text-align: left; }
.data-table th { background: var(--c-bg); font-weight: 600; }

/* ---------- Rank list ---------- */
.rank-list { padding-left: 20px; }
.rank-list li { padding: 4px 0; }

/* ---------- Action row ---------- */
.action-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Inputs file ---------- */
input[type="file"] {
    padding: 8px;
    background: #f9fafb;
}
input[type="file"]::file-selector-button {
    background: var(--c-primary); color: #fff; border: 0; border-radius: 6px;
    padding: 6px 12px; margin-right: 8px; cursor: pointer; font-weight: 600;
}