/* ============================================================
   FlexCop — estilos base (responsive + modo claro/oscuro con CSS
   variables; el toggle manual y mas componentes llegan en la
   etapa de plantillas).
   ============================================================ */

:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1c2330;
    --muted: #64707f;
    --border: #d9dfe6;
    --primary: #2f6fed;
    --primary-text: #ffffff;
    --ok: #1c7c3c;
    --ok-bg: #e7f6ec;
    --bad: #b3261e;
    --bad-bg: #fdecea;
    --warn: #b45309;
    --warn-bg: #fef3e2;
    --row-alt: #f7f9fb;
    --row-hover: #eef3fb;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14181f;
        --card: #1d232c;
        --text: #e6eaf0;
        --muted: #94a0b0;
        --border: #303a47;
        --primary: #4d8bf7;
        --primary-text: #ffffff;
        --ok: #5fc983;
        --ok-bg: #17301f;
        --bad: #f08080;
        --bad-bg: #331a1a;
        --warn: #f0b35c;
    --warn-bg: #33261a;
        --row-alt: #212a35;
        --row-hover: #263041;
    }
}

/* Tema explicito (toggle en dashboard.js): gana sobre prefers-color-scheme */
:root[data-theme="light"] {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1c2330;
    --muted: #64707f;
    --border: #d9dfe6;
    --primary: #2f6fed;
    --primary-text: #ffffff;
    --ok: #1c7c3c;
    --ok-bg: #e7f6ec;
    --bad: #b3261e;
    --bad-bg: #fdecea;
    --warn: #b45309;
    --warn-bg: #fef3e2;
    --row-alt: #f7f9fb;
    --row-hover: #eef3fb;
}
:root[data-theme="dark"] {
    --bg: #14181f;
    --card: #1d232c;
    --text: #e6eaf0;
    --muted: #94a0b0;
    --border: #303a47;
    --primary: #4d8bf7;
    --primary-text: #ffffff;
    --ok: #5fc983;
    --ok-bg: #17301f;
    --bad: #f08080;
    --bad-bg: #331a1a;
    --warn: #f0b35c;
    --warn-bg: #33261a;
    --row-alt: #212a35;
    --row-hover: #263041;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* ---------- Topbar ---------- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.topnav { display: flex; gap: 1rem; }
.topnav a {
    color: var(--text);
    text-decoration: none;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
}
.topnav a:hover { background: var(--border); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.8rem; }
.topbar-user { color: var(--muted); font-size: 0.9rem; }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem; }
.container.narrow { max-width: 520px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.card-head h1 { font-size: 1.3rem; margin: 0; }
h1 { font-size: 1.3rem; }
h3 { margin: 0 0 0.5rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* ---------- Formularios ---------- */
.form-stack { display: flex; flex-direction: column; gap: 0.8rem; }
.form-stack label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
input, select {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    color: var(--text);
    font-size: 0.95rem;
}
input:disabled { opacity: 0.6; }
.form-panel {
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
}
.form-actions { display: flex; gap: 0.6rem; }

/* ---------- Botones ---------- */
.btn {
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
}
.btn:hover { filter: brightness(0.96); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-ghost { background: transparent; }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-warn { color: var(--warn); border-color: currentColor; }

/* ---------- Tablas ---------- */
/* Contenedor: tarjeta con esquinas redondeadas y sombra sutil */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: auto; /* scroll horizontal si no cabe */
    margin-top: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.table-wrap table { margin-top: 0; }
.table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg);
    padding: 0.7rem 0.75rem;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:nth-child(even):hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }
/* Celdas de acciones: sin display:flex (colapsa la altura de la celda y la
   linea de la fila queda pegada al boton); vertical-align centra en la fila */
td.actions {
    vertical-align: middle;
    white-space: nowrap;
}
td.actions > *:not(:last-child) { margin-right: 0.4rem; }
/* Boton solo-icono (refrescar orden): el icono queda centrado dentro del boton */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.3rem 0.4rem;
    line-height: 1;
}
.inline-form { display: inline; margin: 0; }

/* ---------- Badges y alertas ---------- */
.badge { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.alert { padding: 0.55rem 0.75rem; border-radius: 6px; font-size: 0.9rem; margin: 0.5rem 0; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 380px; padding: 1rem; }
.login-brand { text-align: center; margin: 0 0 1rem; }

/* ---------- Dashboard (sidebar + contenido) ---------- */
.dash { display: flex; min-height: 100vh; }
.sidebar {
    width: 220px;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-nav { display: flex; flex-direction: column; padding: 0.5rem; gap: 0.2rem; flex: 1; }
.sidebar-nav a {
    color: var(--text);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
}
.sidebar-nav a:hover { background: var(--border); }
.sidebar-nav a.active { background: var(--primary); color: var(--primary-text); }
/* Arbol de sincronizacion (details/summary nativo, sin JS); abierto por defecto */
.sidebar-tree-head {
    list-style: none;
    cursor: pointer;
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    user-select: none;
}
.sidebar-tree-head::-webkit-details-marker { display: none; }
.sidebar-tree-head::before {
    content: "▸";
    display: inline-block;
    transition: transform 0.15s ease;
    color: var(--muted);
    font-size: 0.75rem;
}
.sidebar-tree[open] > .sidebar-tree-head::before { transform: rotate(90deg); }
.sidebar-tree-head:hover { background: var(--border); }
.sidebar-tree-children {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.15rem 0.5rem 0.4rem;
    margin-left: 0.6rem;
    border-left: 1px solid var(--border);
}
.sidebar-tree-children a { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.sidebar-foot {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
body.sidebar-collapsed .sidebar-foot .logout-label { display: none; }
.dash-main { flex: 1; padding: 1.25rem; min-width: 0; }
.dash-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.dash-top h1 { margin: 0; font-size: 1.4rem; }
.dash-top-actions { display: flex; align-items: center; gap: 0.8rem; }

/* Sidebar colapsado (toggle en dashboard.js) */
body.sidebar-collapsed .sidebar { width: 56px; }
body.sidebar-collapsed .sidebar-head .brand,
body.sidebar-collapsed .sidebar-nav a { font-size: 0; }
body.sidebar-collapsed .sidebar-nav a::before { font-size: 1rem; }
body.sidebar-collapsed .sidebar-tree-head { font-size: 0; }
body.sidebar-collapsed .sidebar-tree-children { display: none; }
body.sidebar-collapsed .sidebar-foot { padding: 0.5rem; }

/* ---------- Filtros y contadores ---------- */
.filters { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.75rem 0 0.25rem; }
.filter-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
}
.filter-panel-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.filter-row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.filter-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
/* Panel Buscar: cuadricula de 3 columnas x 2 filas (Desde | Order ID | SKU / Hasta | Comprador | Producto) */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem 0.75rem;
    width: 100%;
}
.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--muted);
    min-width: 0;
}
.filter-field input { width: 100%; }

/* Chips de estado (multi-seleccion) */
.status-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--muted);
    transition: background 0.15s ease, color 0.15s ease;
}
.chip:hover span { border-color: var(--primary); color: var(--text); }
.chip input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
}
.chip input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.counters { display: flex; gap: 1.2rem; font-size: 0.85rem; margin: 0.35rem 0; }
.ml-code { font-family: ui-monospace, monospace; font-size: 0.85rem; }

/* ---------- Carga incremental (Mostrar 100 mas) ---------- */
.load-more { text-align: center; padding: 0.75rem 0; }

/* ---------- Toggle de tema con iconos (sol = claro, luna = oscuro) ---------- */
.icon { vertical-align: middle; display: inline-block; }
#theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: inline-block; }
:root[data-theme="dark"] #theme-toggle .icon-sun { display: none; }

/* ---------- Footer (version desplegada) ---------- */
.app-footer {
    margin-top: 1.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
}

/* ---------- Indicador HTMX (spinner de sync) ---------- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request { display: inline; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .topbar-inner { gap: 0.75rem; }
    .topnav { order: 3; width: 100%; justify-content: space-between; }
    table { font-size: 0.85rem; }
    .sidebar { width: 56px; }
    .sidebar .brand, .sidebar-nav a { font-size: 0; }
    .dash-main { padding: 0.75rem; }
    .filter-grid { grid-template-columns: 1fr; }
}

/* ---------- Vista Logs del sistema ---------- */
.log-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0.75rem 0 0.25rem;
}
.log-levels { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
td.log-logger {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
td.log-msg { font-family: ui-monospace, monospace; font-size: 0.85rem; }
.log-trace summary { cursor: pointer; color: var(--muted); font-size: 0.8rem; }
.log-trace[open] summary { color: var(--text); }
.log-trace pre {
    white-space: pre-wrap;
    max-height: 14rem;
    overflow: auto;
    margin: 0.4rem 0 0;
    padding: 0.5rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
}
