:root {
    --bg: #f4f3f1;
    --surface: #ffffff;
    --text: #262220;
    --text-muted: #8a8078;
    --border: #e6e1db;
    --primary: #a8654f;
    --primary-dark: #8f5140;
    --danger: #b9483a;
    --danger-bg: #fbe9e6;
    --curso: #b7791f;
    --curso-bg: #fdf3dd;
    --entregado: #2f7a4f;
    --entregado-bg: #e4f3e9;
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px 40px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar h1 {
    font-size: 1.15rem;
    margin: 0;
    flex: 1;
}

.link-muted {
    color: var(--text-muted);
    font-size: 0.95rem;
    white-space: nowrap;
}

/* --- Buttons --- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius);
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn-block {
    width: 100%;
}

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

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

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.btn-new {
    margin: 16px 0 20px;
}

/* --- Login --- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 1.4rem;
    text-align: center;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin: 0 0 24px;
    font-size: 0.95rem;
}

/* --- Forms --- */

.form, form.filters {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 12px 0 6px;
}

.login-card label:first-of-type {
    margin-top: 0;
}

input, select {
    width: 100%;
    font-size: 1rem;
    padding: 13px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}

input:focus, select:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form button[type="submit"] {
    margin-top: 24px;
}

.delete-form {
    margin-top: 16px;
}

.hidden-form {
    display: none;
}

/* --- Phone input --- */

.phone-grid {
    display: grid;
    grid-template-columns: 62px 72px 1fr;
    gap: 8px;
}

.small-label {
    font-size: 0.72rem;
    margin: 0 0 4px;
    color: var(--text-muted);
}

.hint {
    font-size: 0.82rem;
    color: var(--entregado);
    margin: 6px 0 0;
}

/* --- Fotos --- */

input[type="file"] {
    border: 1px dashed var(--border);
    background: var(--surface);
    padding: 12px 14px;
}

.fotos-existentes {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.foto-item {
    position: relative;
    width: 84px;
    height: 84px;
}

.foto-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
    display: block;
}

.foto-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: var(--danger);
    color: #fff;
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
}

.alert {
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

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

.success {
    background: var(--entregado-bg);
    color: var(--entregado);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

/* --- Checkbox --- */

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px 14px;
    margin-top: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* --- Configuración --- */

.config-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.config-section h2 {
    margin: 0 0 6px;
    font-size: 1.05rem;
}

.section-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0 0 16px;
}

.campanas-list {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.campanas-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
}

.campanas-list .foto-delete {
    position: static;
}

/* --- Lightbox --- */

.lightbox-trigger {
    cursor: pointer;
}

.lightbox-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.lightbox-overlay.open {
    display: flex;
}

.lightbox-overlay img {
    max-width: 100%;
    max-height: 82vh;
    border-radius: 10px;
    object-fit: contain;
}

.lightbox-close,
.lightbox-nav {
    position: absolute;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    line-height: 1;
}

.lightbox-close {
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
}

.lightbox-nav {
    top: 50%;
    transform: translateY(-50%);
    width: 46px;
    height: 46px;
    font-size: 1.6rem;
}

.lightbox-prev {
    left: 10px;
}

.lightbox-next {
    right: 10px;
}

.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 12px;
    border-radius: 999px;
}

/* --- Filters --- */

.filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    gap: 10px;
}

.filters input[type="search"] {
    margin-bottom: 2px;
}

.filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* --- Cards / list --- */

.cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 5px solid var(--text-muted);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.card.estado-en-curso {
    border-left-color: var(--curso);
}

.card.estado-entregado {
    border-left-color: var(--entregado);
}

.card.urgente {
    border-left-color: var(--danger);
    background: var(--danger-bg);
}

.card-alerta {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    margin-bottom: 8px;
}

.card-top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.card-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.cliente {
    font-weight: 700;
    font-size: 1.05rem;
    flex: 1;
}

.badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.badge-en-curso {
    background: var(--curso-bg);
    color: var(--curso);
}

.badge-entregado {
    background: var(--entregado-bg);
    color: var(--entregado);
}

.card-desc {
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 3px 0;
}

.card-row.precios {
    border-top: 1px dashed var(--border);
    margin-top: 6px;
    padding-top: 8px;
    color: var(--text);
}

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 0;
}

@media (max-width: 380px) {
    .form-grid, .filter-row {
        grid-template-columns: 1fr;
    }

    .phone-grid {
        grid-template-columns: 52px 60px 1fr;
        gap: 6px;
    }

    .phone-grid input {
        padding: 13px 8px;
    }
}
