:root {
    --bg: #14171c;
    --bg-card: #1e232b;
    --bg-input: #262c36;
    --border: #313945;
    --text: #e8eaed;
    --text-dim: #9aa4b2;
    --accent: #4f8cff;
    --verde: #2fbf71;
    --rojo: #e5484d;
    --amarillo: #e5b93d;
    --azul: #4f8cff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

.hidden { display: none !important; }

.centered-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
}

.card h1, .card h2 { margin-top: 0; text-align: center; }

label {
    display: block;
    margin: 12px 0 4px;
    font-size: 14px;
    color: var(--text-dim);
}

.form-group {
    margin-bottom: 18px;
    padding-bottom: 4px;
}

.form-group label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 6px;
}

.form-group .hint {
    font-size: 12px;
    color: var(--text-dim);
    margin: 2px 0 6px;
}

input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
}

.form-group input:focus {
    border-color: var(--accent);
    outline: none;
}

textarea { resize: vertical; min-height: 60px; }

button {
    cursor: pointer;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: 600;
    background: var(--accent);
    color: white;
    margin-top: 16px;
    width: 100%;
}

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

button.danger { background: var(--rojo); }
button.small { width: auto; padding: 6px 12px; font-size: 13px; margin-top: 0; }

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    width: auto;
    padding: 0;
    margin-top: 12px;
    font-size: 14px;
    text-decoration: underline;
}

.error-msg { color: var(--rojo); font-size: 14px; margin-top: 8px; }
.ok-msg { color: var(--verde); font-size: 14px; margin-top: 8px; }

.recovery-box {
    background: var(--bg-input);
    border: 1px dashed var(--amarillo);
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
    word-break: break-all;
    font-family: monospace;
    font-size: 15px;
    text-align: center;
}

/* App layout */
#view-app { display: flex; flex-direction: column; min-height: 100vh; }

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

.topbar h1 { font-size: 18px; margin: 0; }

nav.tabs {
    display: flex;
    overflow-x: auto;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

nav.tabs button {
    background: none;
    color: var(--text-dim);
    border-radius: 0;
    margin: 0;
    padding: 12px 18px;
    white-space: nowrap;
    font-weight: 500;
    border-bottom: 3px solid transparent;
}

nav.tabs button.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

main { flex: 1; padding: 16px; max-width: 1000px; width: 100%; margin: 0 auto; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.section-header h2 { margin: 0; }
.section-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section-header button { width: auto; margin-top: 0; }

/* Dashboard cocheras grid */
.cocheras-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
}

.cochera-tile {
    aspect-ratio: 1;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 700;
    font-size: 22px;
    color: #0b0d10;
    border: none;
    padding: 8px;
    text-align: center;
}

.cochera-tile small { font-size: 11px; font-weight: 500; margin-top: 4px; }

.cochera-libre { background: var(--verde); }
.cochera-semiocupada { background: var(--amarillo); }
.cochera-ocupada { background: var(--rojo); color: white; }
.cochera-reservada-flag { background: var(--azul); color: white; }

.cochera-tile {
    transition: box-shadow 0.15s, outline 0.15s;
    touch-action: none;
    user-select: none;
}

.cochera-tile.dragging {
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 50;
    position: relative;
    cursor: grabbing;
}

.cochera-tile.drop-target {
    outline: 3px dashed var(--text);
    outline-offset: 2px;
}

.legend { display: flex; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* Lists / tables */
.list-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 10px;
}

.list-item .row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.list-item .meta { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.list-item .btns { display: flex; gap: 8px; margin-top: 8px; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-activo { background: var(--verde); color: #0b0d10; }
.badge-baja { background: var(--rojo); color: white; }
.badge-pausado { background: var(--amarillo); color: #0b0d10; }

.caja-resumen {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.caja-resumen .stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}

.caja-resumen .stat .label { font-size: 12px; color: var(--text-dim); }
.caja-resumen .stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.caja-resumen .stat.saldo .value { color: var(--accent); }
.caja-resumen .stat.ingresos .value { color: var(--verde); }
.caja-resumen .stat.salidas .value { color: var(--rojo); }
.caja-resumen .stat.aportes .value { color: var(--amarillo); }

.movimiento-ingreso_cliente { border-left: 4px solid var(--verde); }
.movimiento-salida { border-left: 4px solid var(--rojo); }
.movimiento-aporte { border-left: 4px solid var(--amarillo); }

.badge-tipo {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}
.badge-tipo-ingreso_cliente { background: var(--verde); color: #0b0d10; }
.badge-tipo-salida { background: var(--rojo); color: white; }
.badge-tipo-aporte { background: var(--amarillo); color: #0b0d10; }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; z-index: 100;
}

.modal {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h3 { margin-top: 0; }

@media (min-width: 700px) {
    .cocheras-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

.app-footer {
    text-align: center;
    padding: 14px 16px;
    font-size: 12px;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
}
