:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #65717d;
    --line: #d9e0e7;
    --primary: #1769aa;
    --primary-dark: #0f4f82;
    --sidebar: #202833;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
}

button,
input {
    font: inherit;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(rgba(12, 18, 28, 0.38), rgba(12, 18, 28, 0.38)), url("/img/fondo.jpg") center center / cover no-repeat;
}

.login-panel {
    width: min(380px, calc(100vw - 32px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 18px 40px rgba(20, 30, 40, 0.26);
}

.login-panel h1 {
    margin: 0 0 24px;
    font-size: 26px;
}

.login-panel label {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
    color: var(--muted);
}

.login-panel input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
}

.login-panel button,
.panel-header button {
    border: 0;
    border-radius: 6px;
    padding: 11px 16px;
    color: #fff;
    background: var(--primary);
    cursor: pointer;
}

.login-panel button:hover,
.panel-header button:hover {
    background: var(--primary-dark);
}

.form-error {
    min-height: 20px;
    color: #b42318;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
}

.sidebar {
    background: var(--sidebar);
    color: #fff;
    padding: 18px 12px;
}

.brand {
    padding: 10px 12px 22px;
    font-size: 20px;
    font-weight: 700;
}

.nav-link {
    display: block;
    width: 100%;
    margin-bottom: 6px;
    padding: 10px 12px;
    border: 0;
    border-radius: 6px;
    color: #dfe7ef;
    background: transparent;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.nav-link:hover,
.nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.main {
    min-width: 0;
}

.topbar {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 24px;
}

#session-user {
    color: var(--muted);
}

.content {
    padding: 24px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.metric-card,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric-card {
    padding: 18px;
}

.metric-card span {
    display: block;
    color: var(--muted);
    margin-bottom: 10px;
}

.metric-card strong {
    font-size: 30px;
}

.panel {
    padding: 18px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-header h2 {
    margin: 0;
    font-size: 20px;
}

.json-box {
    overflow: auto;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}

.document-page {
    background: #fff;
}

.document {
    max-width: 820px;
    margin: 0 auto;
    padding: 40px 24px;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .content,
    .topbar {
        padding: 16px;
    }
}

/* ===================== Panel (mismas clases que snoopcrush) ===================== */
[hidden] {
    display: none !important;
}

select,
textarea {
    font: inherit;
}

.nav-section {
    margin: 18px 12px 8px;
    color: #93a4b7;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.panel-summary {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.explorer-panel {
    min-width: 0;
}

.explorer-error {
    min-height: 20px;
    margin-bottom: 8px;
    color: #b42318;
}

.explorer-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
}

.tab-button {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
}

.tab-button.active {
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 700;
}

.primary-button,
.secondary-button {
    border: 0;
    border-radius: 6px;
    padding: 10px 14px;
    cursor: pointer;
}

.primary-button {
    color: #fff;
    background: var(--primary);
}

.secondary-button {
    color: var(--text);
    background: #e8edf2;
}

.danger-button {
    color: #b42318;
}

.primary-button:disabled,
.secondary-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.login-volver {
    display: inline-block;
    margin-top: 6px;
    color: var(--muted);
    text-decoration: none;
}

/* Ventanas (<dialog>) */
.edit-window {
    width: min(1000px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 18px 40px rgba(20, 30, 40, 0.26);
}

.edit-window.angosta {
    width: min(760px, calc(100vw - 32px));
}

.edit-window::backdrop {
    background: rgba(12, 18, 28, 0.48);
}

.edit-window h3 {
    margin: 0 0 14px;
}

.window-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

/* Formularios */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px 18px;
}

.form-grid label,
.form-field {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
}

.form-grid .ancho {
    grid-column: 1 / -1;
}

.form-grid input:not([type="range"]):not([type="color"]):not([type="file"]),
.form-grid select,
.form-grid textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 11px;
    color: var(--text);
    background: #fff;
}

.form-grid input[type="range"] {
    width: 100%;
}

.form-grid input[type="color"] {
    width: 60px;
    height: 38px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.range-valor {
    float: right;
    color: var(--text);
    font-weight: 700;
}

.section-title {
    margin: 22px 0 12px;
    color: var(--muted);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nota {
    color: var(--muted);
    font-size: 13px;
}

.acciones-fila {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.logo-editor img {
    max-height: 60px;
    max-width: 200px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px;
    background: #fff;
}

/* Vista previa de la tienda */
.vista-previa {
    margin-top: 18px;
    border: 2px dashed var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.vista-previa-etiqueta {
    padding: 8px 14px;
    background: #eef2f6;
    color: var(--muted);
    font-size: 13px;
}

.producto-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 22px;
}

/* Estados */
.estado {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
}

.estado-producto-1, .estado-pedido-2 { background: #e3f4e5; color: #1f6b2a; }
.estado-producto-2, .estado-pedido-1 { background: #fff3d6; color: #8a5a00; }
.estado-producto-0 { background: #eceff2; color: #5b6670; }
.estado-pedido-3 { background: #e1ecfa; color: #1b4f8f; }
.estado-pedido-4 { background: #fde4e1; color: #a2271b; }

.grid-miniatura {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    background: #eef2f6;
    display: block;
}

/* Fotos del producto */
.fotos-lista {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.foto-item {
    width: 96px;
    text-align: center;
    font-size: 12px;
}

.foto-item img {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border: 2px solid var(--line);
    border-radius: 6px;
    display: block;
    margin-bottom: 4px;
}

.foto-item.principal img {
    border-color: var(--primary);
}

.foto-item button {
    border: 0;
    background: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
}

.foto-item button.danger-button {
    color: #b42318;
}

/* Pedido y remito */
.pedido-datos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px 18px;
    margin-bottom: 16px;
}

.pedido-datos span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.pedido-datos strong {
    word-break: break-word;
}

.tabla {
    width: 100%;
    border-collapse: collapse;
}

.tabla th,
.tabla td {
    padding: 8px 6px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.tabla .num {
    text-align: right;
    white-space: nowrap;
}

.tabla tfoot td {
    border-bottom: 0;
    font-size: 17px;
    font-weight: 700;
}

@media (max-width: 860px) {
    .producto-editor {
        grid-template-columns: 1fr;
    }
}

.logo-editor label {
    display: inline-block;
    color: var(--text);
}

.form-error.ok,
.explorer-error.ok {
    color: #1f6b2a;
}
