:root {
    --blue: #3B82F6;
    --blue-dark: #2563EB;
    --blue-darker: #1D4ED8;
    --green: #10B981;
    --green-dark: #059669;
    --red: #EF4444;
    --red-dark: #DC2626;
    --border: #D1D5DB;
    --text: #111827;
}

* { box-sizing: border-box; }

body {
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    margin: 0;
    color: var(--text);
    background: #F3F4F6;
    font-size: 13px;
}

body.app-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 14px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
}
.logo img { height: 28px; width: auto; display: block; }
.logo span { font-weight: 400; color: #6B7280; }

.debug-banner {
    padding: 4px 10px;
    border: 1px solid #DC2626;
    border-radius: 4px;
    color: #DC2626;
    background: #FEE2E2;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.filter-field, .date-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.settings-nav {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

label { font-weight: 500; }

input[type="checkbox"] { width: auto; margin: 0; flex: none; vertical-align: middle; }
label:has(> input[type="checkbox"]) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

input[type="text"], input[type="password"], input[type="date"], input[type="file"], select {
    border: 2px solid var(--border);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    background: white;
}

.btn {
    border: none;
    border-radius: 4px;
    padding: 8px 14px;
    font-weight: 500;
    cursor: pointer;
    color: white;
    background: var(--blue);
    transition: background 0.15s;
    text-decoration: none;
    display: inline-block;
}
.btn:hover { background: var(--blue-dark); }
.btn:active { background: var(--blue-darker); }
.btn-secondary { background: #6B7280; }
.btn-secondary:hover { background: #4B5563; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: var(--red-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

header.topbar { flex: none; }

main {
    padding: 12px 16px;
}

.app-body main {
    flex: 1;
    display: flex;
    min-height: 0;
}

.table-wrap {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}

table { border-collapse: collapse; width: 100%; }
thead th {
    position: sticky; top: 0;
    background: #F9FAFB;
    border-bottom: 2px solid var(--border);
    padding: 8px;
    text-align: left;
    font-size: 12px;
}
tbody td {
    border-bottom: 1px solid #E5E7EB;
    padding: 6px 8px;
    font-size: 12px;
}

tr.header-row.pending { background: #FFA0A0; }
tr.header-row.created { background: #90EE90; }
tr.item-row td input {
    width: 70px;
    padding: 3px 5px;
    font-size: 12px;
}
tr.item-row.disabled input { background: #F3F4F6; color: #9CA3AF; }

.action-cell {
    display: inline-block;
    padding: 4px 10px;
    background: var(--blue);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    text-align: center;
}
.action-cell:hover { background: var(--blue-dark); }

.action-cell.action-danger { background: var(--red); }
.action-cell.action-danger:hover { background: var(--red-dark); }

.action-add, .action-remove {
    display: inline-block;
    position: relative;
    vertical-align: middle;
    width: 24px; height: 24px;
    border-radius: 4px;
    cursor: pointer;
    color: white;
    /* el glifo "+"/"-" se dibuja con pseudo-elementos para centrarlo con exactitud */
    font-size: 0;
    line-height: 0;
}
.action-add::before,
.action-add::after,
.action-remove::before {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 10px; height: 2px;
    margin: -1px 0 0 -5px;
    background: currentColor;
    border-radius: 1px;
}
.action-add::after { transform: rotate(90deg); }
.action-add { background: var(--green); }
.action-add:hover { background: var(--green-dark); }
.action-remove { background: var(--red); }
.action-remove:hover { background: var(--red-dark); }

footer {
    padding: 0 16px 4px;
    flex: none;
    position: relative;
}

.copyright {
    flex: none;
    padding: 0 16px 4px;
    text-align: center;
    color: #6B7280;
    font-size: 11px;
}
#logBox {
    width: 100%;
    height: 110px;
    resize: none;
    font-family: Consolas, monospace;
    font-size: 12px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #111827;
    color: #D1FAE5;
    display: block;
}

/* El tirador nativo del textarea vive abajo a la derecha y no se puede mover, así que se sustituye. */
.log-resize {
    position: absolute;
    top: 2px;
    right: 34px;
    width: 22px; height: 14px;
    cursor: ns-resize;
    z-index: 10;
    background:
        linear-gradient(to right, #6B7280 0 100%) center 4px / 14px 2px no-repeat,
        linear-gradient(to right, #6B7280 0 100%) center 8px / 14px 2px no-repeat;
    opacity: 0.6;
}
.log-resize:hover { opacity: 1; }

.log-fab {
    position: absolute;
    bottom: 26px;
    right: 40px;
    width: 36px; height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--blue);
    color: white;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    z-index: 10;
}
.log-fab:hover { background: var(--blue-dark); }

#logModal {
    width: 1100px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#logModalBox {
    flex: 1;
    min-height: 0;
    width: 100%;
    resize: none;
    font-family: Consolas, monospace;
    font-size: 12px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #111827;
    color: #D1FAE5;
}

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
    background: white;
    border-radius: 8px;
    padding: 20px;
    width: 640px;
    max-width: 95vw;
    max-height: 90vh;
    overflow: auto;
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal label { display: block; margin: 10px 0 4px; }
.modal select, .modal input[type="text"] { width: 100%; }
.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 10px;
}
.modal-grid pre {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 11px;
    max-height: 130px;
    overflow: auto;
    background: #F9FAFB;
    padding: 6px;
    border-radius: 4px;
}
.modal-row { display: flex; gap: 20px; }
.modal-row > div { flex: 1; }
.modal-buttons { margin-top: 16px; display: flex; gap: 10px; justify-content: center; }
.hidden { display: none !important; }

.settings-page { max-width: 900px; margin: 24px auto; background: white; padding: 20px; border-radius: 8px; border: 1px solid var(--border); }
.settings-page h1 { margin-top: 0; }
.settings-page textarea { width: 100%; height: 420px; font-family: Consolas, monospace; font-size: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; }
.settings-page .actions { margin-top: 12px; display: flex; gap: 10px; }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.alert-error { background: #FEE2E2; color: #991B1B; }
.alert-success { background: #D1FAE5; color: #065F46; }
.inline-form { display: inline; margin-left: 6px; }

.tab-bar { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn {
    padding: 8px 14px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: transparent;
    font-size: 13px;
    color: #4B5563;
    cursor: pointer;
    margin-bottom: -1px;
}
.tab-btn:hover { background: #F3F4F6; }
.tab-btn.active { background: white; border-color: var(--border); color: #111827; font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel > h2:first-child { margin-top: 0; }

.login-body { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
    width: 320px;
    background: white;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.login-card .logo { margin-bottom: 14px; }
.login-card label { font-weight: 600; margin-top: 6px; }
.login-card input[type="text"], .login-card input[type="password"] {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}
.login-card .login-remember { font-weight: 400; display: flex; align-items: center; gap: 6px; margin: 12px 0; }
.login-card .btn { text-align: center; }

.adv-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; }
.adv-list { border: 1px solid var(--border); border-radius: 6px; background: white; }
.adv-list h3 { margin: 0; padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.adv-list ul { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; }
.adv-list li { padding: 8px 10px; border-bottom: 1px solid #F3F4F6; }
.adv-add-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.cred-card, .tag-card { border: 1px solid var(--border); border-radius: 6px; padding: 14px; margin-bottom: 14px; background: white; }
.cred-card .field, .tag-card .field { margin-bottom: 10px; }
.cred-card label, .tag-card label { display: block; font-size: 12px; margin-bottom: 4px; }
.cred-card input, .tag-card input, .cred-card select, .tag-card textarea { width: 100%; }
.cred-card input[type="checkbox"], .tag-card input[type="checkbox"] { width: auto; }
.tag-card textarea { height: 90px; font-family: Consolas, monospace; }
.steps-list { margin-bottom: 8px; }
.step-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.step-row select { flex: 1; }
.step-row .btn { padding: 6px 10px; line-height: 1; }
.seur-zones { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 2px 0 8px; }
.seur-zones label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: #6B7280; font-weight: 400; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dept-info { font-size: 11px; white-space: pre-wrap; background: #F9FAFB; padding: 8px; border-radius: 4px; margin-top: 6px; }

.status-table td { font-size: 12px; vertical-align: top; }
.status-table td:last-child { color: #4B5563; }
.status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.status-ok { background: #D1FAE5; color: #065F46; }
.status-warn { background: #FEF3C7; color: #92400E; }
.status-fail { background: #FEE2E2; color: #991B1B; }
