* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f5f1;
    --bg-tertiary: #ecebe5;
    --border: rgba(0, 0, 0, 0.12);
    --border-strong: rgba(0, 0, 0, 0.22);
    --text-primary: #1a1a1a;
    --text-secondary: #6b6b66;
    --text-tertiary: #a0a098;
    --accent: #8f6d3e;
    --accent-light: #b8935a;
    --danger: #c0392b;
    --warning: #b8860b;
    --radius: 6px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* TOPBAR */
.topbar {
    background: var(--bg-primary);
    border-bottom: 0.5px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.brand .logo {
    color: var(--accent);
    letter-spacing: 1.5px;
    font-weight: 500;
    font-size: 16px;
}
.brand .tag {
    color: var(--text-secondary);
    font-size: 13px;
}
.userbar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}
.userbar .sep { color: var(--text-tertiary); }
.userbar a {
    color: var(--accent);
    text-decoration: none;
}
.userbar a:hover { color: var(--accent-light); text-decoration: underline; }

/* MAIN */
main {
    padding: 0 20px;
    max-width: 1200px;
    margin: 24px auto;
}

/* SEARCH ROW */
.search-row {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}
.search-row input[type="search"] {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-primary);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    color: var(--text-primary);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.search-row input[type="search"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(143, 109, 62, 0.10);
}
.search-row input[type="search"]::placeholder { color: var(--text-tertiary); }
.search-row select {
    width: 160px;
    padding: 12px 14px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-primary);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%236b6b66' stroke-width='1.2' d='M1 1l4 4 4-4'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
}
.search-row select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(143, 109, 62, 0.10);
}

/* TABLE */
.table-wrap {
    background: var(--bg-primary);
    border: 0.5px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.table-head {
    background: var(--bg-secondary);
    border-bottom: 0.5px solid var(--border);
    padding: 10px 16px;
    font-size: 12px;
    color: var(--text-secondary);
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead th {
    text-align: left;
    font-weight: 500;
    font-size: 11px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 10px 14px;
    border-bottom: 0.5px solid var(--border);
    background: var(--bg-primary);
}
thead th.num { text-align: right; }
thead th.act { text-align: right; width: 90px; }

tbody td {
    padding: 10px 14px;
    border-bottom: 0.5px solid var(--border);
    vertical-align: middle;
    font-size: 14px;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-secondary); }

td.numero { font-weight: 500; }
td.fecha { white-space: nowrap; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
td.importe { text-align: right; font-variant-numeric: tabular-nums; }
td.acciones { text-align: right; }

.empty {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* BADGES */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    font-weight: 500;
}
.badge.presupuesto { background: #E1F5EE; color: #085041; }
.badge.factura { background: #FAEEDA; color: #633806; }

/* BUTTON VER */
.btn-ver {
    padding: 4px 12px;
    font-size: 11px;
    font-family: inherit;
    background: var(--bg-primary);
    border: 0.5px solid var(--border-strong);
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}
.btn-ver:hover {
    background: var(--bg-secondary);
    border-color: var(--accent);
    color: var(--accent);
}

/* VISOR PDF */
.visor {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}
.visor.oculto { display: none; }
.visor-header {
    background: #1a1a1a;
    color: #fff;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.visor-header a, .visor-header button {
    color: #fff;
    background: transparent;
    border: 0.5px solid #555;
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 12px;
    font-family: inherit;
    margin-left: 8px;
    cursor: pointer;
    transition: background 100ms ease, border-color 100ms ease;
}
.visor-header a:hover, .visor-header button:hover {
    background: rgba(255,255,255,0.06);
    border-color: #888;
}
.visor iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: #333;
}

/* ALERTS */
.alert {
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.alert.error { background: #fde8e6; color: var(--danger); }
.alert.warning { background: #fdf5e3; color: var(--warning); }

/* LOGIN */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-secondary);
}
.login-box {
    background: var(--bg-primary);
    border: 0.5px solid var(--border);
    border-radius: 8px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.login-brand {
    color: var(--accent);
    letter-spacing: 1.5px;
    font-weight: 500;
    font-size: 18px;
    margin-bottom: 4px;
}
.login-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 28px;
}
.login-box form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
input, select {
    font: inherit;
    padding: 9px 12px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(143, 109, 62, 0.10);
}
.login-box input { width: 100%; margin-top: 4px; }
.login-box button {
    font: inherit;
    padding: 9px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    border: none;
    font-weight: 500;
    font-size: 14px;
    transition: background 150ms;
    width: 100%;
}
.login-box button:hover { background: var(--accent-light); }

/* RESPONSIVE */
@media (max-width: 640px) {
    /* Topbar compacto */
    .topbar { padding: 10px 14px; }
    .brand .logo { font-size: 14px; }
    .brand .tag { font-size: 12px; }
    .userbar { font-size: 12px; }

    /* Main */
    main { padding: 12px 14px; margin: 12px auto; }

    /* Search apilado */
    .search-row { flex-direction: column; }
    .search-row input[type="search"],
    .search-row select { width: 100%; }

    /* Tabla compacta con anchos fijos */
    table { table-layout: fixed; }
    thead th:nth-child(1) { width: 36px; }
    thead th:nth-child(2) { width: 80px; }
    thead th:nth-child(6) { width: 56px; }

    /* Ocultar Fecha e Importe */
    thead th:nth-child(4),
    thead th:nth-child(5) { display: none; }
    tbody td.fecha,
    tbody td.importe      { display: none; }

    /* Cliente truncado */
    tbody td:nth-child(3) {
        max-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Paddings compactos */
    thead th, tbody td { padding: 8px 6px; font-size: 12px; }

    /* Sin hover pegado en touch */
    tbody tr:hover td { background: transparent; }

    /* Badges → círculos P / F */
    .badge.presupuesto,
    .badge.factura {
        font-size: 0;
        width: 22px;
        height: 22px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }
    .badge.presupuesto::before { content: "P"; font-size: 11px; font-weight: 600; }
    .badge.factura::before     { content: "F"; font-size: 11px; font-weight: 600; }

    /* Botón Ver compacto */
    .btn-ver { min-height: 32px; font-size: 11px; padding: 0 8px; width: auto; }
}
