:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --success: #16a34a;
    --radius: 10px;
    --shadow: 0 10px 30px rgba(2, 6, 23, .12);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* El atributo [hidden] debe ganar sobre cualquier `display` de autor
   (.modal, .app-view, etc. usan display:flex y si no, no se ocultarían). */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Botones ---------- */
.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

/* ---------- Login ---------- */
.login-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 30% 20%, #1e293b, #0f172a);
    padding: 20px;
}
.login-card {
    background: var(--surface);
    width: 100%;
    max-width: 380px;
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
}
.login-title { margin: 0; font-size: 22px; }
.login-subtitle { margin: 4px 0 24px; color: var(--muted); }
.login-error {
    margin: 14px 0 0;
    color: var(--danger);
    background: var(--danger-soft);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
}
.api-config { margin: 4px 0 18px; }
.api-config summary { color: var(--muted); cursor: pointer; font-size: 13px; }

/* ---------- Campos ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.field textarea { min-height: 80px; resize: vertical; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }

/* ---------- Layout app ---------- */
.app-view { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px;
    background: var(--bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    padding: 20px 22px;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: .5px;
}
.sidebar-brand span { color: #60a5fa; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: #cbd5e1;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-soft); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--bg-soft); }
.current-user { font-size: 13px; margin-bottom: 10px; color: #94a3b8; }
.current-user strong { color: #fff; display: block; }

.content { flex: 1; padding: 26px 32px; max-width: 100%; overflow-x: auto; }
.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
}
.content-header h2 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); margin: 4px 0 0; font-size: 13px; }
.content-actions { display: flex; gap: 10px; align-items: center; }
.search-input {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    min-width: 220px;
}

/* ---------- Tabla ---------- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;   /* scroll horizontal cuando la tabla es más ancha */
    overflow-y: hidden;
    position: relative;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    text-align: left;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-table th {
    background: var(--surface-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.actions { white-space: nowrap; text-align: right; }
.data-table td.actions .btn { margin-left: 6px; }
.cell-id { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 12px;
}
.empty-state, .loading-state { padding: 40px; text-align: center; color: var(--muted); }

/* Imágenes */
.img-thumb {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    vertical-align: middle;
}
.img-preview {
    display: block;
    max-width: 120px;
    max-height: 120px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    padding: 6px;
    margin-bottom: 8px;
}
.img-controls { display: flex; flex-direction: column; gap: 8px; }
.img-file { font-size: 13px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .55); }
.modal-card {
    position: relative;
    background: var(--surface);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    border-radius: 14px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; color: var(--muted); }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    gap: 12px;
}
.modal-footer-actions { display: flex; gap: 10px; margin-left: auto; }
.form-error { color: var(--danger); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text);
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 100;
    font-size: 14px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- Ordenamiento (drag & drop) ---------- */
.nav-sep { height: 1px; background: var(--bg-soft); margin: 10px 4px; }

.order-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.order-tab {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}
.order-tab:hover { background: var(--surface-2); }
.order-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

.order-hint { margin: 0 0 14px; }
.order-list { display: flex; flex-direction: column; gap: 8px; max-width: 720px; }

/* Productos agrupados por categoría (el orden es por categoría). */
.order-group {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    overflow: hidden;
}
.order-group-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg);
    color: #fff;
}
.order-group-name { font-weight: 600; font-size: 14px; }
.order-group-count { color: #94a3b8; margin: 0; font-size: 12px; }
.order-sublist {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    min-height: 44px;   /* zona soltable visible aun sin productos */
}
.order-sublist:empty::after {
    content: 'Sin productos';
    color: var(--muted);
    font-size: 13px;
    padding: 4px 4px 0;
}
.order-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    cursor: grab;
    user-select: none;
}
.order-item:hover { border-color: #cbd5e1; }
.order-item.dragging { opacity: .5; cursor: grabbing; box-shadow: var(--shadow); }
.order-handle { color: var(--muted); font-size: 18px; line-height: 1; cursor: grab; }
.order-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.order-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.order-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.order-id { font-variant-numeric: tabular-nums; font-size: 13px; }
.order-actions { margin-top: 18px; }

@media (max-width: 720px) {
    .sidebar { width: 64px; }
    .sidebar-brand, .current-user, .nav-item span { display: none; }
    .content { padding: 18px; }
}
