:root {
    --navy: #003057;
    --navy-2: #0b3f6b;
    --orange: #FF6B35;
    --orange-2: #e85a26;
    --bg: #f3f5f8;
    --card: #ffffff;
    --line: #dfe4ea;
    --text: #1b2430;
    --muted: #677385;
    --danger: #c62828;
    --ok: #2e7d32;
    --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; }

/* ---------- botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid transparent; border-radius: 8px;
    padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
    text-decoration: none; background: #e9edf2; color: var(--text);
    transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #dde3ea; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--orange-2); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: #fff; }
.btn-danger { background: transparent; color: var(--danger); border-color: #f1c6c6; }
.btn-danger:hover { background: #fdecec; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 7px 9px; }
.btn-block { width: 100%; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, var(--navy), #004a7f); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; color: var(--navy); }
.login-card label { display: block; margin: 16px 0 0; font-weight: 600; font-size: 14px; }
.login-card input { margin-top: 6px; }
.login-card .btn { margin-top: 22px; }
.login-mark { width: 52px; height: 52px; }

/* ---------- estructura ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px; font-weight: 700; font-size: 18px; }
.brand img { width: 32px; height: 32px; }
.tabs { flex: 1; overflow-y: auto; padding: 6px 10px; }
.tab {
    display: flex; align-items: center; gap: 12px; width: 100%;
    background: none; border: 0; color: rgba(255,255,255,.82); text-align: left;
    padding: 10px 12px; border-radius: 8px; font: inherit; cursor: pointer;
}
.tab i { width: 18px; text-align: center; opacity: .85; }
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.active { background: var(--orange); color: #fff; }
.tab-sep { margin: 12px 12px 6px; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: rgba(255,255,255,.45); }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .muted { color: rgba(255,255,255,.6); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn { color: #fff; border-color: rgba(255,255,255,.25); }
.sidebar-foot .btn:hover { background: rgba(255,255,255,.1); }

.main { min-width: 0; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 14px;
    padding: 14px 28px; background: rgba(243,245,248,.95); backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 20px; color: var(--navy); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.panel { padding: 24px 28px 80px; max-width: 1100px; }
.only-mobile { display: none; }

/* ---------- formularios ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card > h3 { margin: 0 0 4px; font-size: 16px; color: var(--navy); }
.card > .help { margin-bottom: 14px; }
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.help { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], textarea, select {
    width: 100%; padding: 10px 12px; border: 1px solid #cfd6de; border-radius: 8px;
    font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,107,53,.15); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: 14px; }
.switch input { width: 18px; height: 18px; accent-color: var(--orange); }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type=color] { width: 48px; height: 40px; padding: 2px; border: 1px solid #cfd6de; border-radius: 8px; background: #fff; }
.color-row input[type=text] { max-width: 140px; }

/* archivo (imagen, video, pdf) */
.media-field { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.media-preview {
    width: 160px; height: 110px; border-radius: 8px; border: 1px dashed #c3ccd6;
    background: #f7f9fb repeating-conic-gradient(#eef1f4 0 25%, #fff 0 50%) 0 0 / 16px 16px;
    display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 13px; text-align: center;
}
.media-preview img, .media-preview video { width: 100%; height: 100%; object-fit: contain; }
.media-actions { display: flex; flex-direction: column; gap: 8px; }
.media-actions .row { display: flex; gap: 8px; flex-wrap: wrap; }
.media-url { font-size: 12px; color: var(--muted); word-break: break-all; max-width: 360px; }

/* icono */
.icon-row { display: flex; gap: 10px; align-items: center; }
.icon-preview { width: 42px; height: 42px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; flex: none; }
.icon-row select { flex: 1; }

/* listas */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd; }
.list-item-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; }
.list-item-head .thumb { width: 54px; height: 40px; border-radius: 6px; object-fit: cover; background: #e9edf2; flex: none; }
.list-item-head .thumb.contain { object-fit: contain; background: #fff; border: 1px solid var(--line); }
.list-item-head .title { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item-head .tag { font-size: 12px; background: #e7edf4; color: var(--navy); padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.list-item-head .tools { display: flex; gap: 4px; }
.list-item-body { padding: 14px; border-top: 1px solid var(--line); background: #fff; border-radius: 0 0 10px 10px; }
.list-foot { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.list-empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.list-item.dragging { opacity: .5; }

/* biblioteca */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-tile { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.media-tile .media-preview { width: 100%; height: 110px; border: 0; border-radius: 0; }
.media-tile .meta { padding: 8px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.media-tile button.pick { border: 0; padding: 0; background: none; cursor: pointer; text-align: left; }
.badge-used { background: #e6f4ea; color: var(--ok); padding: 1px 6px; border-radius: 10px; }

.history-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history-row:last-child { border-bottom: 0; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status.ok { color: var(--ok); }
.status.off { color: var(--muted); }
.status.err { color: var(--danger); }
.steps { margin: 8px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* modal y aviso */
.modal { position: fixed; inset: 0; background: rgba(10,20,35,.55); z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 14px; width: 100%; max-width: 900px; max-height: 85vh; overflow-y: auto; padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; color: var(--navy); }
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200;
    background: #1b2430; color: #fff; padding: 12px 20px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
    max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); }
.progress { height: 6px; background: #e9edf2; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--orange); width: 0; transition: width .2s; }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -260px; width: 250px; z-index: 50; transition: left .2s; }
    .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.35); }
    .only-mobile { display: inline-flex; }
    .topbar { padding: 10px 14px; flex-wrap: wrap; }
    .topbar h2 { font-size: 17px; }
    .topbar-actions { width: 100%; }
    .topbar-actions #saveState { flex: 1; }
    .panel { padding: 16px 14px 80px; }
    .grid-2 { grid-template-columns: 1fr; }
}
