/* =============================================================
   IntegrationHub Design System
   Inspired by Shopify Polaris / modern SaaS dashboards.
============================================================= */

:root {
    /* Colors - Surface */
    --color-bg: #f6f6f7;
    --color-surface: #ffffff;
    --color-surface-hover: #f9fafb;
    --color-surface-subdued: #fafbfb;
    --color-surface-pressed: #f1f2f3;

    /* Colors - Border */
    --color-border: #e1e3e5;
    --color-border-subdued: #ebebeb;
    --color-border-strong: #c9cccf;

    /* Colors - Text */
    --color-text: #1a1a1a;
    --color-text-strong: #0a0a0a;
    --color-text-secondary: #616161;
    --color-text-muted: #8c8c8c;
    --color-text-disabled: #b5b5b5;
    --color-text-inverse: #ffffff;

    /* Colors - Brand & Action */
    --color-primary: #2c6ecb;
    --color-primary-hover: #1f5aab;
    --color-primary-pressed: #103a73;
    --color-primary-subdued: #ebf1fb;

    /* Status */
    --color-success: #008060;
    --color-success-bg: #e3f1df;
    --color-success-text: #0c5132;
    --color-warning: #b98900;
    --color-warning-bg: #fff3d6;
    --color-warning-text: #7a5b00;
    --color-danger: #d72c0d;
    --color-danger-bg: #fde2dd;
    --color-danger-text: #8e1100;
    --color-info: #2c6ecb;
    --color-info-bg: #ebf1fb;
    --color-info-text: #103a73;

    /* Sidebar */
    --color-sidebar-bg: #1a1a1a;
    --color-sidebar-surface: #2a2a2a;
    --color-sidebar-text: #d2d2d3;
    --color-sidebar-text-muted: #8c8c8c;
    --color-sidebar-active: #ffffff;
    --color-sidebar-active-bg: rgba(255, 255, 255, 0.08);
    --color-sidebar-hover-bg: rgba(255, 255, 255, 0.04);
    --color-sidebar-border: #2e2e2e;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 999px;

    /* Shadows */
    --shadow-xs: 0 1px 0 rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.06), 0 4px 8px rgba(0, 0, 0, 0.04);
    --shadow-focus: 0 0 0 3px rgba(44, 110, 203, 0.18);

    /* Typography */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, Monaco, monospace;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 60px;
    --content-max-width: 1400px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
}

/* ============= Base ============= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { color: var(--color-text-strong); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 24px; line-height: 1.25; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 17px; line-height: 1.35; }
h4 { font-size: 15px; line-height: 1.4; }
h5 { font-size: 13px; line-height: 1.4; }
h6 { font-size: 12px; line-height: 1.4; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); font-weight: 600; }
p { margin: 0; color: var(--color-text-secondary); }
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary-hover); }

code, pre { font-family: var(--font-mono); font-size: 12.5px; }
code {
    padding: 1px 6px;
    background: var(--color-surface-pressed);
    border-radius: var(--radius-sm);
    color: var(--color-text-strong);
    font-size: 12.5px;
}
pre {
    margin: 0;
    padding: var(--space-4);
    background: var(--color-surface-subdued);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    color: var(--color-text);
}
pre code { padding: 0; background: transparent; }

/* ============= Layout ============= */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
    transition: grid-template-columns var(--transition-base);
}

.app-sidebar { grid-area: sidebar; background: var(--color-sidebar-bg); color: var(--color-sidebar-text); border-right: 1px solid var(--color-sidebar-border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; transition: transform var(--transition-base); overflow: hidden; }
.app-topbar { grid-area: topbar; background: var(--color-surface); border-bottom: 1px solid var(--color-border); padding: 0 var(--space-6); display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); position: sticky; top: 0; z-index: 20; }
.app-main { grid-area: main; padding: var(--space-6) var(--space-8); width: 100%; min-width: 0; }

/* Sidebar hidden (desktop) */
.app-shell.sidebar-collapsed { grid-template-columns: 0 1fr; }
.app-shell.sidebar-collapsed .app-sidebar { transform: translateX(-100%); border-right: none; }
.app-shell .sidebar-show-btn { display: none; }
.app-shell.sidebar-collapsed .sidebar-show-btn { display: inline-flex; }
.app-shell.sidebar-collapsed .sidebar-hide-btn { display: none; }

/* ============= Sidebar ============= */
.sidebar-header { padding: var(--space-5) var(--space-5) var(--space-4); border-bottom: 1px solid var(--color-sidebar-border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.sidebar-hide-btn {
    width: 30px; height: 30px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid var(--color-sidebar-border);
    color: var(--color-sidebar-text);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition-fast);
    flex-shrink: 0;
}
.sidebar-hide-btn:hover { background: var(--color-sidebar-hover-bg); color: var(--color-sidebar-active); }
.sidebar-hide-btn svg { width: 16px; height: 16px; }
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; min-width: 0; flex: 1; }
.sidebar-brand:hover { color: var(--color-sidebar-active); }
.sidebar-logo {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #2c6ecb 0%, #6366f1 100%);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 14px; letter-spacing: -0.02em;
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.3);
}
.sidebar-brand-text { color: var(--color-sidebar-active); font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.sidebar-brand-subtitle { display: block; font-size: 11px; color: var(--color-sidebar-text-muted); font-weight: 400; letter-spacing: 0.04em; }

.sidebar-nav { flex: 1; padding: var(--space-3) var(--space-3); overflow-y: auto; }
.sidebar-section { margin-bottom: var(--space-4); }
.sidebar-section-title { padding: var(--space-2) var(--space-3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-sidebar-text-muted); font-weight: 600; margin-top: var(--space-3); }

.sidebar-link {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 9px var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-sidebar-text);
    font-weight: 500; font-size: 13.5px;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
    margin-bottom: 2px;
}
.sidebar-link:hover { background: var(--color-sidebar-hover-bg); color: var(--color-sidebar-active); }
.sidebar-link.active { background: var(--color-sidebar-active-bg); color: var(--color-sidebar-active); font-weight: 600; }
.sidebar-link .sidebar-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.sidebar-link.active .sidebar-icon { opacity: 1; }
.sidebar-link-count { margin-left: auto; background: rgba(255, 255, 255, 0.08); color: var(--color-sidebar-text); padding: 2px 8px; border-radius: var(--radius-full); font-size: 11px; font-weight: 600; }

.sidebar-footer { padding: var(--space-4); border-top: 1px solid var(--color-sidebar-border); }
.sidebar-user { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2); border-radius: var(--radius-md); }
.sidebar-user-avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    background: linear-gradient(135deg, #2c6ecb, #6366f1);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; color: var(--color-sidebar-active); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-email { font-size: 11.5px; color: var(--color-sidebar-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============= Topbar ============= */
.topbar-title { font-size: 14px; color: var(--color-text-secondary); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.topbar-search {
    position: relative;
    flex: 1;
    max-width: 480px;
}
.topbar-search input {
    width: 100%; height: 36px;
    padding: 0 var(--space-4) 0 36px;
    background: var(--color-surface-pressed);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 13px;
    transition: all var(--transition-fast);
}
.topbar-search input:focus { background: var(--color-surface); border-color: var(--color-primary); outline: none; box-shadow: var(--shadow-focus); }
.topbar-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); width: 16px; height: 16px; }

.topbar-iconbtn {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-secondary);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition-fast);
    position: relative;
}
.topbar-iconbtn:hover { background: var(--color-surface-pressed); color: var(--color-text); }
.topbar-iconbtn .icon { width: 18px; height: 18px; }
.topbar-iconbtn .dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-danger); border: 2px solid var(--color-surface); }

.mobile-menu-toggle { display: none; }
.sidebar-show-btn {
    align-items: center; justify-content: center; gap: var(--space-2);
}
.sidebar-show-btn .icon { width: 18px; height: 18px; }

/* ============= Page header ============= */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-header-content { flex: 1; min-width: 0; }
.page-title { font-size: 22px; font-weight: 600; color: var(--color-text-strong); letter-spacing: -0.01em; margin-bottom: 4px; }
.page-subtitle { font-size: 14px; color: var(--color-text-secondary); }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ============= Page toolbar (card variant del page-header) ============= */
.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: var(--space-6);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.page-toolbar-info { display: flex; align-items: center; gap: var(--space-3); flex: 1; min-width: 0; }
.page-toolbar-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #eef4ff 0%, #dbe7ff 100%);
    color: #1d4ed8;
    flex-shrink: 0;
}
.page-toolbar-text { min-width: 0; }
.page-toolbar-text .page-title { margin-bottom: 2px; font-size: 18px; }
.page-toolbar-text .page-subtitle { font-size: 12.5px; line-height: 1.4; }
.page-toolbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.page-toolbar-divider {
    width: 1px; height: 24px;
    background: var(--color-border);
    margin: 0 var(--space-1);
}

/* Botones agrupados (segmented control) */
.btn-group { display: inline-flex; align-items: stretch; }
.btn-group > .btn { border-radius: 0; margin-left: -1px; position: relative; }
.btn-group > .btn:first-child { border-top-left-radius: var(--radius-md, 6px); border-bottom-left-radius: var(--radius-md, 6px); margin-left: 0; }
.btn-group > .btn:last-child { border-top-right-radius: var(--radius-md, 6px); border-bottom-right-radius: var(--radius-md, 6px); }
.btn-group > .btn:hover, .btn-group > .btn:focus { z-index: 1; }
.btn-group > .btn svg { flex-shrink: 0; }

@media (max-width: 880px) {
    .page-toolbar { padding: 12px 14px; }
    .page-toolbar-actions { width: 100%; justify-content: flex-end; }
}
@media (max-width: 640px) {
    .page-toolbar { flex-direction: column; align-items: stretch; }
    .page-toolbar-info { width: 100%; }
    .page-toolbar-actions { width: 100%; }
    .page-toolbar-divider { display: none; }
    .btn-group { flex: 1; }
    .btn-group > .btn { flex: 1; justify-content: center; }
}

/* ============= Cards ============= */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.card-title { font-size: 14px; font-weight: 600; color: var(--color-text-strong); }
.card-subtitle { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }
.card-body { padding: var(--space-5); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); background: var(--color-surface-subdued); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-section { padding: var(--space-5); border-top: 1px solid var(--color-border); }
.card-section:first-child { border-top: none; }

/* ============= Metric cards ============= */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.metric-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base);
    position: relative;
    overflow: hidden;
}
.metric-card:hover { box-shadow: var(--shadow-md); }
.metric-card-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: var(--space-3);
}
.metric-card-icon.is-primary { background: var(--color-primary-subdued); color: var(--color-primary); }
.metric-card-icon.is-success { background: var(--color-success-bg); color: var(--color-success-text); }
.metric-card-icon.is-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.metric-card-icon.is-danger { background: var(--color-danger-bg); color: var(--color-danger-text); }
.metric-card-icon svg { width: 20px; height: 20px; }
.metric-card-label { font-size: 12.5px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-bottom: var(--space-1); }
.metric-card-value { font-size: 28px; font-weight: 700; color: var(--color-text-strong); letter-spacing: -0.02em; line-height: 1.1; }
.metric-card-meta { font-size: 12.5px; color: var(--color-text-muted); margin-top: var(--space-2); }
.metric-card-trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); margin-top: var(--space-2); }
.metric-card-trend.up { color: var(--color-success-text); background: var(--color-success-bg); }
.metric-card-trend.down { color: var(--color-danger-text); background: var(--color-danger-bg); }

/* ============= Buttons ============= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 13px; font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    min-height: 36px;
    white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: #fff; }
.btn-primary:active { background: var(--color-primary-pressed); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-hover); color: var(--color-text-strong); border-color: var(--color-border-strong); }

.btn-ghost { background: transparent; color: var(--color-text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--color-surface-pressed); color: var(--color-text); }

.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: #b62308; border-color: #b62308; color: #fff; }

.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-success:hover { background: #006a4f; color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 28px; border-radius: var(--radius-sm); }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { padding: 10px 18px; font-size: 14px; min-height: 42px; }

.btn-icon { width: 32px; height: 32px; padding: 0; }
.btn-icon.btn-sm { width: 28px; height: 28px; }

/* ============= Badges ============= */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 11.5px; font-weight: 600;
    line-height: 1.3;
    text-transform: none;
    letter-spacing: 0;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge-default { background: var(--color-surface-pressed); color: var(--color-text-secondary); }
.badge-primary { background: var(--color-primary-subdued); color: var(--color-primary-pressed); }
.badge-success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger-text); }
.badge-info { background: var(--color-info-bg); color: var(--color-info-text); }
.badge-soft { background: var(--color-surface-pressed); color: var(--color-text); }
.badge-soft::before { display: none; }

/* ============= Forms ============= */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--color-text); margin-bottom: 6px; }
.form-label .required { color: var(--color-danger); }
.form-help { font-size: 12.5px; color: var(--color-text-muted); margin-top: 4px; }
.form-error { font-size: 12.5px; color: var(--color-danger-text); margin-top: 4px; }

.form-control, .form-select, input.form-control, select.form-select, textarea.form-control {
    width: 100%;
    padding: 8px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    font-size: 13.5px;
    color: var(--color-text);
    transition: all var(--transition-fast);
    min-height: 36px;
    font-family: inherit;
}
.form-control:focus, .form-select:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.form-control::placeholder { color: var(--color-text-muted); }
.form-control:disabled { background: var(--color-surface-pressed); cursor: not-allowed; }
textarea.form-control { min-height: 88px; resize: vertical; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }

.input-group { display: flex; align-items: stretch; }
.input-group .form-control { border-radius: 0; }
.input-group .form-control:first-child { border-top-left-radius: var(--radius-md); border-bottom-left-radius: var(--radius-md); }
.input-group .form-control:last-child { border-top-right-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }

.form-check { display: flex; align-items: center; gap: var(--space-2); }
.form-check-input { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }
.form-check-label { font-size: 13px; color: var(--color-text); cursor: pointer; }

.field-secret-wrap { position: relative; }
.field-secret-wrap .form-control { padding-right: 80px; }
.field-secret-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: transparent; color: var(--color-text-muted); font-size: 12px; font-weight: 600; padding: 4px 8px; cursor: pointer; border-radius: var(--radius-sm); }
.field-secret-toggle:hover { background: var(--color-surface-pressed); color: var(--color-text); }

/* ============= Tables / DataTables ============= */
.data-table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.data-table-toolbar { padding: var(--space-4) var(--space-5); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; border-bottom: 1px solid var(--color-border-subdued); }

table.app-table { width: 100%; border-collapse: separate; border-spacing: 0; }
table.app-table thead th { padding: 11px 16px; text-align: left; font-size: 11.5px; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--color-surface-subdued); border-bottom: 1px solid var(--color-border); }
table.app-table tbody td { padding: 13px 16px; font-size: 13px; color: var(--color-text); border-bottom: 1px solid var(--color-border-subdued); vertical-align: middle; }
table.app-table tbody tr:hover td { background: var(--color-surface-hover); }
table.app-table tbody tr:last-child td { border-bottom: none; }
table.app-table td .row-actions { display: inline-flex; gap: 4px; opacity: 0.85; }
table.app-table tbody tr:hover .row-actions { opacity: 1; }

/* DataTables overrides */
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { color: var(--color-text-secondary); font-size: 12.5px; padding: var(--space-3) var(--space-5); }
.dataTables_wrapper .dataTables_filter input { padding: 6px 12px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); font-size: 13px; margin-left: 8px; min-width: 240px; }
.dataTables_wrapper .dataTables_filter input:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.dataTables_wrapper .dataTables_length select { padding: 6px 28px 6px 10px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); font-size: 13px; }
.dataTables_wrapper .dataTables_paginate .paginate_button { padding: 5px 10px !important; margin: 0 2px; border-radius: var(--radius-md) !important; border: 1px solid transparent !important; background: transparent !important; color: var(--color-text-secondary) !important; font-size: 12.5px; font-weight: 500; min-width: 32px; text-align: center; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { background: var(--color-surface-pressed) !important; color: var(--color-text) !important; border-color: transparent !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { background: var(--color-primary) !important; color: #fff !important; border-color: var(--color-primary) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover { opacity: 0.45; cursor: not-allowed; }

/* ============= Alerts ============= */
.alert-modern {
    display: flex; align-items: flex-start; gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: 13.5px;
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-xs);
}
.alert-modern .alert-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.alert-modern .alert-body { flex: 1; }
.alert-modern .alert-title { font-weight: 600; color: var(--color-text-strong); margin-bottom: 2px; }
.alert-modern .alert-close { background: transparent; border: none; padding: 0; cursor: pointer; color: var(--color-text-muted); opacity: 0.7; }
.alert-modern .alert-close:hover { opacity: 1; }

.alert-modern.is-success { background: var(--color-success-bg); border-color: rgba(0, 128, 96, 0.22); color: var(--color-success-text); }
.alert-modern.is-warning { background: var(--color-warning-bg); border-color: rgba(185, 137, 0, 0.25); color: var(--color-warning-text); }
.alert-modern.is-danger { background: var(--color-danger-bg); border-color: rgba(215, 44, 13, 0.22); color: var(--color-danger-text); }
.alert-modern.is-info { background: var(--color-info-bg); border-color: rgba(44, 110, 203, 0.18); color: var(--color-info-text); }

/* ============= Empty states ============= */
.empty-state { text-align: center; padding: var(--space-10) var(--space-6); color: var(--color-text-muted); }
.empty-state-icon { width: 56px; height: 56px; margin: 0 auto var(--space-4); border-radius: var(--radius-full); background: var(--color-surface-pressed); display: flex; align-items: center; justify-content: center; color: var(--color-text-secondary); }
.empty-state-icon svg { width: 28px; height: 28px; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--color-text-strong); margin-bottom: 4px; }
.empty-state-text { font-size: 13.5px; color: var(--color-text-muted); max-width: 360px; margin: 0 auto var(--space-4); }

/* ============= Status pills (records) ============= */
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; line-height: 1.4; }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.status-pill.is-enviado { background: var(--color-success-bg); color: var(--color-success-text); }
.status-pill.is-enviado .dot { background: var(--color-success); }
.status-pill.is-error { background: var(--color-danger-bg); color: var(--color-danger-text); }
.status-pill.is-error .dot { background: var(--color-danger); }
.status-pill.is-leido { background: var(--color-info-bg); color: var(--color-info-text); }
.status-pill.is-leido .dot { background: var(--color-primary); }
.status-pill.is-pendiente { background: var(--color-surface-pressed); color: var(--color-text-secondary); }
.status-pill.is-pendiente .dot { background: var(--color-text-muted); }
.status-pill.is-reintentando { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-pill.is-reintentando .dot { background: var(--color-warning); }

/* ============= Utilities ============= */
.text-muted { color: var(--color-text-muted) !important; }
.text-secondary { color: var(--color-text-secondary) !important; }
.text-strong { color: var(--color-text-strong) !important; font-weight: 600; }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-mono { font-family: var(--font-mono); }

.stack { display: flex; }
.stack-vertical { flex-direction: column; }
.stack-1 { gap: var(--space-1); }
.stack-2 { gap: var(--space-2); }
.stack-3 { gap: var(--space-3); }
.stack-4 { gap: var(--space-4); }
.stack-6 { gap: var(--space-6); }
.stack-spread { justify-content: space-between; align-items: center; }
.stack-center { align-items: center; }

.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }

.divider { border: 0; border-top: 1px solid var(--color-border-subdued); margin: var(--space-4) 0; }

.kbd { font-family: var(--font-mono); font-size: 11.5px; padding: 2px 6px; background: var(--color-surface-pressed); border: 1px solid var(--color-border); border-radius: var(--radius-sm); color: var(--color-text-secondary); }

/* ============= Plugin cards ============= */
.plugin-card { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.plugin-card-logo { width: 40px; height: 40px; border-radius: var(--radius-md); background: linear-gradient(135deg, #2c6ecb, #6366f1); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; text-transform: uppercase; }
.plugin-card-body { flex: 1; min-width: 0; }
.plugin-card-name { font-size: 13.5px; font-weight: 600; color: var(--color-text-strong); }
.plugin-card-meta { font-size: 12px; color: var(--color-text-muted); }

/* ============= Toast / animations ============= */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn 0.2s ease forwards; }
.animate-slide-up { animation: slideUp 0.25s ease forwards; }

/* ============= Responsive ============= */
@media (max-width: 992px) {
    .app-shell, .app-shell.sidebar-collapsed { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
    .app-sidebar { position: fixed; left: 0; top: 0; width: 280px; height: 100vh; z-index: 100; transform: translateX(-100%); transition: transform var(--transition-base); box-shadow: var(--shadow-lg); }
    .app-sidebar.is-open { transform: translateX(0); }
    .app-shell.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
    .app-shell.sidebar-collapsed .app-sidebar.is-open { transform: translateX(0); }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99; opacity: 0; pointer-events: none; transition: opacity var(--transition-base); }
    .sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }
    .mobile-menu-toggle { display: inline-flex; }
    .app-shell .sidebar-show-btn { display: inline-flex; }
    .topbar-search { display: none; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .app-main { padding: var(--space-4); }
    .metric-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-actions { flex-wrap: wrap; gap: var(--space-2); }

    /* Topbar mas compacto */
    .app-topbar { padding: 0 var(--space-3); }
    .topbar-actions { gap: var(--space-1); }
    .topbar-actions .topbar-iconbtn { padding: 6px; }

    /* Alerts ocupan todo el ancho con padding menor */
    .alert-modern { padding: var(--space-3); gap: var(--space-2); }
    .alert-body { font-size: 12px; }

    /* Cards con menos padding */
    .connection-card { border-radius: 8px; }
    .connection-card .card-header[data-toggle-body] { padding: 10px 12px; gap: 8px; }
    .connection-card .row-actions { width: 100%; justify-content: flex-start; }
    .connection-card .row-actions .btn { flex: 1; min-width: 0; }
    .connection-card .row-actions form { flex: 1; }
    .connection-card .row-actions form .btn { width: 100%; }

    /* Tree node: stack vertical (info arriba, controles abajo) */
    .tree-node {
        grid-template-columns: 1fr;
        grid-template-areas:
            "info"
            "reorder"
            "curl"
            "run";
        gap: 6px;
        padding: 8px 10px;
        font-size: 12px;
    }
    .tree-node > .info { grid-area: info; }
    .tree-node > .reorder-cell { grid-area: reorder; flex-direction: row; justify-content: flex-start; gap: 4px; }
    .tree-node > .reorder-cell .reorder-form .reorder-btn { width: 36px !important; height: 22px !important; min-height: 22px !important; }
    .tree-node > [data-pipeline-curl],
    .tree-node > [data-write-curl] { grid-area: curl; }
    .tree-node > form { grid-area: run; }
    .tree-node > form .btn,
    .tree-node > .btn { width: 100%; }

    .tree-graph .branch { margin-left: 8px; padding-left: 14px; }
    .tree-graph .branch::after { width: 12px; top: 18px; }

    /* Status panel: 1 columna y cards mas compactas */
    .status-panel-grid { grid-template-columns: 1fr; }
    .status-card { padding: 8px 10px; }

    /* Match key inline: wrap mas chico, ocultar columnas individuales (mostrar solo etiqueta + modo) */
    .match-key-inline .mk-col { display: none; }
    .match-key-inline { font-size: 10px; gap: 3px; }

    /* Modal: full screen friendly */
    .modal-dialog { margin: 0.5rem; max-width: calc(100% - 1rem); }
}

/* Tablet: tree node stack hibrido (info arriba, controles en fila) */
@media (max-width: 880px) and (min-width: 641px) {
    .tree-node {
        grid-template-columns: 1fr 44px 90px 110px;
        gap: 8px;
        padding: 8px 12px;
    }
    .connection-card .row-actions { flex-wrap: wrap; }
}

/* Aprovechar bien el ancho en monitores grandes: sin max-width, padding mayor para no pegarse al borde */
@media (min-width: 1600px) {
    .app-main { padding: var(--space-6) 48px; }
}
@media (min-width: 1920px) {
    .app-main { padding: var(--space-6) 64px; }
}
