:root {
    --bg: #0B0D12;
    --surface: #151923;
    --surface-2: #1C2130;
    --border: #262C3B;
    --text: #F2F4F8;
    --muted: #ABB3C2;
    --accent: #E5484D;
    --accent-soft: rgba(229, 72, 77, 0.14);
    --ok: #3DD68C;
    --ok-soft: rgba(61, 214, 140, 0.14);
    --warn: #F5C451;
    --warn-soft: rgba(245, 196, 81, 0.14);
    --danger: #FF6B6B;
    --danger-soft: rgba(255, 107, 107, 0.14);
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 650;
    letter-spacing: -0.01em;
}

p {
    margin: 0;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    left: -999px;
    top: 8px;
    background: var(--surface-2);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    z-index: 100;
}

.skip-link:focus {
    left: 8px;
}

/* ---------- Estructura ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    background: rgba(11, 13, 18, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    margin-right: auto;
}

.brand strong {
    font-size: 17px;
    letter-spacing: -0.02em;
}

.brand span {
    color: var(--muted);
    font-size: 12px;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}

.app-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 20px 96px;
}

.page-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.page-title h1 {
    font-size: 24px;
}

.page-title .muted {
    font-size: 13px;
}

/* ---------- Tarjetas y telas ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}

.grid {
    display: grid;
    gap: 14px;
}

.grid-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-profiles {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.summary {
    padding: 16px 18px;
}

.summary .label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.summary .value {
    font-size: 26px;
    font-weight: 700;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.summary .value small {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.summary.overdue .value {
    color: var(--danger);
}

.profile-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
}

.profile-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-weight: 700;
    color: var(--muted);
    flex: none;
}

.avatar.owner {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
}

.profile-name {
    font-weight: 650;
    font-size: 16px;
}

.profile-sub {
    color: var(--muted);
    font-size: 12.5px;
}

.profile-owner {
    border-color: rgba(229, 72, 77, 0.35);
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}

.badge.ok {
    background: var(--ok-soft);
    color: var(--ok);
    border-color: transparent;
}

.badge.warn {
    background: var(--warn-soft);
    color: var(--warn);
    border-color: transparent;
}

.badge.danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: transparent;
}

.badge.accent {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
}

.rows {
    display: grid;
    gap: 4px;
    font-size: 13.5px;
}

.rows .row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.rows .row span:first-child {
    color: var(--muted);
}

.rows .row span:last-child {
    font-variant-numeric: tabular-nums;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
}

/* ---------- Botones ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}

.btn:hover {
    background: #232937;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: #d13b40;
}

.btn-ghost {
    background: transparent;
}

.btn-danger {
    background: var(--danger-soft);
    border-color: transparent;
    color: var(--danger);
}

.btn-small {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

/* ---------- Formularios ---------- */

.field {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
}

.field label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
}

.field textarea {
    min-height: 80px;
    resize: vertical;
}

.field .hint {
    font-size: 12px;
    color: var(--muted);
}

.field .error {
    font-size: 12.5px;
    color: var(--danger);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    color: var(--muted);
    margin-bottom: 14px;
}

.check input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--accent);
}

.form-error {
    background: var(--danger-soft);
    color: var(--danger);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13.5px;
    margin-bottom: 14px;
}

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(3, 5, 9, 0.72);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
    padding: 0;
}

.modal {
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    padding: 20px;
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-head h2 {
    font-size: 19px;
}

.modal-head p {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
    flex-wrap: wrap;
}

.modal-actions .btn {
    flex: 1 1 auto;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
    flex: none;
}

/* ---------- PIN ---------- */

.pin-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin: 12px 0;
}

.pin-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 30px;
    letter-spacing: 0.35em;
    font-weight: 700;
}

/* ---------- Listas y tablas ---------- */

.list {
    display: grid;
    gap: 10px;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.list-item .grow {
    min-width: 0;
    flex: 1;
}

.list-item .title {
    font-weight: 600;
}

.list-item .sub {
    color: var(--muted);
    font-size: 12.5px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
    align-items: center;
}

.toolbar .field {
    margin: 0;
}

.toolbar select,
.toolbar input {
    min-width: 140px;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.skeleton {
    background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: var(--radius);
    height: 140px;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* ---------- Navegacion ---------- */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(11, 13, 18, 0.97);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 11px;
    min-height: 56px;
}

.bottom-nav a.active {
    color: var(--accent);
}

.bottom-nav svg {
    width: 22px;
    height: 22px;
}

/* ---------- Avisos ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 76px;
    transform: translateX(-50%);
    z-index: 80;
    max-width: min(92vw, 520px);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 13.5px;
    box-shadow: var(--shadow);
}

.toast.ok { border-color: rgba(61, 214, 140, 0.5); }
.toast.error { border-color: rgba(255, 107, 107, 0.55); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.stack { display: grid; gap: 14px; }
.mt { margin-top: 14px; }
.hidden { display: none !important; }

/* ---------- Login ---------- */

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 26px;
}

.auth-card .brand {
    margin-bottom: 22px;
}

/* ---------- Escritorio ---------- */

@media (min-width: 860px) {
    .app-main {
        padding-bottom: 40px;
    }

    .bottom-nav {
        display: none;
    }

    .modal-backdrop {
        align-items: center;
        padding: 24px;
    }

    .modal {
        border-radius: 18px;
    }

    .toast {
        bottom: 28px;
    }
}

@media (max-width: 720px) {
    .grid-summary {
        grid-template-columns: 1fr 1fr;
    }

    .grid-summary .summary:last-child {
        grid-column: span 2;
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .app-main {
        padding: 16px 14px 96px;
    }

    .app-header {
        padding: 12px 14px;
    }

    .page-title h1 {
        font-size: 21px;
    }
}

@media (min-width: 721px) {
    .nav-desktop {
        display: flex;
        gap: 4px;
    }

    .nav-desktop a {
        padding: 8px 12px;
        border-radius: 10px;
        text-decoration: none;
        color: var(--muted);
        font-size: 13.5px;
        font-weight: 600;
    }

    .nav-desktop a.active {
        background: var(--surface-2);
        color: var(--text);
    }
}

@media (max-width: 720px) {
    .nav-desktop {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}
.h3 { font-size: 18px; font-weight: 650; margin-bottom: 2px; }
