:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --ink: #1f2937;
    --ink-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #4f46e5;
    --primary-soft: #eef2ff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #d97706;
    --warning-soft: #fffbeb;
}

html, body {
    background: var(--bg);
    color: var(--ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.app-navbar .brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--ink);
    letter-spacing: -0.01em;
}
.app-navbar .brand .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--primary);
    margin-right: 0.4rem;
    vertical-align: 1px;
}
.app-navbar .subtitle {
    color: var(--ink-muted);
    font-size: 0.85rem;
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.card-soft {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.hero h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 0.25rem;
}
.hero p {
    color: var(--ink-muted);
    margin: 0;
}

.dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    background: var(--surface);
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease;
}
.dropzone.is-dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.dropzone svg {
    opacity: 0.6;
    margin-bottom: 0.5rem;
}
.dropzone h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
}
.dropzone p {
    color: var(--ink-muted);
    margin: 0;
    font-size: 0.9rem;
}

.pending-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.4rem;
}
.pending-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fbfbfd;
}
.pending-list .size {
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}
.pending-list .remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 0.2rem;
}

.progress-wrap {
    display: none;
    margin-top: 1rem;
}
.progress-wrap.visible { display: block; }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.status-badge.pending { background: var(--warning-soft); color: var(--warning); }
.status-badge.ok { background: var(--success-soft); color: var(--success); }
.status-badge.error { background: var(--danger-soft); color: var(--danger); }
.status-badge.processing { background: var(--primary-soft); color: var(--primary); }

.table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
}
.table-wrap table {
    margin: 0;
    font-size: 0.88rem;
    min-width: 1200px;
}
.table-wrap thead th {
    background: #fafbff;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: #374151;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    padding: 0.75rem 0.85rem;
}
.table-wrap tbody td {
    padding: 0.65rem 0.85rem;
    vertical-align: middle;
    border-top: 1px solid #f1f2f6;
    white-space: nowrap;
}
.table-wrap tbody tr.error-row td {
    background: var(--danger-soft);
}

/* === Columnas draggable / ocultables === */
.col-draggable {
    position: relative;
    cursor: grab;
    user-select: none;
    padding-right: 2rem !important;
}
.col-draggable:active {
    cursor: grabbing;
}
.col-draggable .col-grab {
    color: var(--ink-muted);
    font-size: 0.7rem;
    margin-right: 0.35rem;
    opacity: 0.5;
    letter-spacing: -2px;
}
.col-draggable:hover .col-grab { opacity: 1; }
.col-draggable .col-hide {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    width: 18px;
    height: 18px;
    line-height: 14px;
    padding: 0;
    color: var(--ink-muted);
    font-size: 0.95rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.col-draggable:hover .col-hide { opacity: 1; }
.col-draggable .col-hide:hover {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #fecaca;
}
.col-draggable.col-dragging {
    opacity: 0.5;
}
.col-draggable.col-drop-target {
    box-shadow: inset 3px 0 0 0 var(--primary);
}
.col-fixed {
    background: #fafbff !important;
}
.error-msg {
    display: block;
    font-size: 0.72rem;
    color: var(--danger);
    margin-top: 0.25rem;
    max-width: 280px;
    white-space: normal;
    line-height: 1.3;
    font-family: ui-monospace, 'SF Mono', monospace;
}
.editable {
    min-width: 90px;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: text;
}
.editable:hover {
    border-color: var(--border);
    background: #fdfdfe;
}
.editable:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.action-btns {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    white-space: nowrap;
}
.action-btns button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2rem 0.55rem;
    cursor: pointer;
    font-size: 0.78rem;
    color: #374151;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.action-btns button:hover { background: #f3f4f6; }
.action-btns .btn-danger { color: var(--danger); border-color: #fecaca; }
.action-btns .btn-danger:hover { background: var(--danger-soft); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    justify-content: flex-end;
}

.hint-input {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.4rem;
}
.hint-input input {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    min-width: 220px;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--ink-muted);
}
.empty-state h4 { color: var(--ink); font-weight: 600; margin-bottom: 0.3rem; }

.footer {
    margin-top: 2.5rem;
    text-align: center;
    color: var(--ink-muted);
    font-size: 0.8rem;
}
.footer a { color: var(--ink-muted); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

.alert-inline {
    display: none;
    background: var(--danger-soft);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    margin-top: 1rem;
    font-size: 0.9rem;
}
.alert-inline.visible { display: block; }

.spinner-small {
    width: 14px;
    height: 14px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Panel asistente === */
.offcanvas { background: var(--surface); }
.nav-tabs .nav-link {
    color: var(--ink-muted);
    font-weight: 500;
    font-size: 0.88rem;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.55rem 0.9rem;
}
.nav-tabs .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

/* Chat */
.chat-messages {
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: #fbfbfd;
    min-height: 0;
}
.chat-bubble {
    max-width: 85%;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.35;
    white-space: pre-wrap;
}
.chat-bubble.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
    align-self: flex-start;
    background: white;
    color: var(--ink);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-empty {
    color: var(--ink-muted);
    text-align: center;
    font-size: 0.85rem;
    margin: auto;
}
.chat-form {
    border-top: 1px solid var(--border);
    padding: 0.75rem;
    background: white;
}
.chat-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    font-size: 0.88rem;
    resize: vertical;
    font-family: inherit;
}
.chat-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.chat-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 0.4rem;
}
.chat-proposed {
    background: var(--success-soft);
    border: 1px solid #a7f3d0;
    padding: 0.65rem 0.85rem;
    margin: 0.5rem 0.75rem;
    border-radius: 10px;
    font-size: 0.85rem;
}
.chat-proposed h6 {
    margin: 0 0 0.3rem;
    font-size: 0.8rem;
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.chat-proposed .actions { margin-top: 0.5rem; display: flex; gap: 0.4rem; }

/* Reglas */
.rule-card {
    background: #fdfdff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.6rem;
    font-size: 0.87rem;
}
.rule-card .rule-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.72rem;
    color: var(--ink-muted);
    margin-bottom: 0.3rem;
}
.rule-card .rule-instruction { line-height: 1.3; }
.rule-card.inactive { opacity: 0.55; }
.rule-badge {
    display: inline-block;
    font-size: 0.68rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
}
.rule-badge.global { background: #eef2ff; color: var(--primary); }
.rule-badge.issuer { background: #ecfdf5; color: var(--success); }
.rule-badge.implicit { background: #fffbeb; color: var(--warning); }

.rule-actions { margin-top: 0.45rem; display: flex; gap: 0.35rem; }
.rule-actions button { font-size: 0.76rem; padding: 0.15rem 0.55rem; }

/* Sugerencias */
.suggestion-card {
    background: var(--warning-soft);
    border: 1px solid #fcd34d;
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    margin-bottom: 0.6rem;
    font-size: 0.87rem;
}
.suggestion-card strong { color: var(--warning); }
.suggestion-card textarea {
    width: 100%;
    font-size: 0.83rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 0.4rem;
}
.suggestion-card .actions { margin-top: 0.5rem; display: flex; gap: 0.4rem; }
