:root {
    --bg: #0f172a;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --accent: #22c55e;
    --danger: #ef4444;
    --warn: #f59e0b;
    --border: #1f2937;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji';
}

.app-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #0b1220, #0f172a);
}

.app-header h1 {
    margin: 0 0 6px;
    font-size: 18px;
}

.app-header .meta {
    color: var(--muted);
    font-size: 12px;
}

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

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

button {
    background: #1f2937;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
}

button.primary {
    background: var(--accent);
    color: #052e16;
    border: none;
}

button.danger {
    background: var(--danger);
    color: #fff;
    border: none;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.status {
    margin-left: 8px;
    color: var(--muted);
}

.status.success {
    color: var(--accent);
}

.status.error {
    color: var(--danger);
}

.rules {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.rules-head,
.rule-row {
    display: grid;
    grid-template-columns: 1.2fr 1.5fr 1.2fr 1fr 1fr 0.6fr 0.6fr;
    gap: 8px;
}

.rules-head {
    background: #0b1220;
    padding: 10px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.rule-row {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.rule-row:last-child {
    border-bottom: none;
}

input,
select,
textarea {
    width: 100%;
    background: #0b1220;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
}

textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}

/* Textareas en filas de reglas: compactos (2 líneas iniciales) */
.rules .comment,
.rules .pattern {
    min-height: 0;
    line-height: 1.3;
}

/* JSON crudo amplio por defecto */
#rawJson {
    min-height: 220px;
}

/* Textareas del modal con altura cómoda */
.modal textarea {
    min-height: 120px;
}

/* Replacement en modal puede ser más bajo */
#mReplacement {
    min-height: 60px;
}

.actions {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.advanced {
    margin-top: 12px;
}

/* Modal */
.modal.hidden {
    display: none;
}

.modal .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal .modal-dialog {
    position: fixed;
    top: 6%;
    left: 50%;
    transform: translateX(-50%);
    width: min(1000px, 92vw);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}

.modal-header,
.modal-footer {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-footer {
    border-top: 1px solid var(--border);
    border-bottom: none;
}

.modal-body {
    padding: 12px;
    overflow: auto;
}

.form-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 12px;
    align-items: center;
    margin-bottom: 10px;
}

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

pre {
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 160px;
}

.muted {
    color: var(--muted);
    font-size: 12px;
    margin-left: 8px;
}