[hidden] { display: none !important; }

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d63d8;
  --primary-600: #1652b8;
  --primary-50: #eaf1fd;
  --primary-100: #d4e3fb;
  --ok: #15803d; --ok-bg: #e7f6ec;
  --warn: #b45309; --warn-bg: #fdf3e2;
  --danger: #c2410c; --danger-strong: #b91c1c; --danger-bg: #fdecea;
  --info: #1d63d8; --info-bg: #eaf1fd;
  --neutral-bg: #eef2f6;
  --side-bg: #0b1529; --side-text: #c4cede; --side-muted: #7d8aa3; --side-hover: #16233d; --side-active: #1d63d8;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 24px 64px rgba(15, 23, 42, .22);
  --radius: 12px; --radius-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #0f1729; --text: #e5eaf3; --text-2: #b5c0d3; --muted: #8592a8; --border: #22304a;
    --primary: #4c8df6; --primary-600: #3b7ae6; --primary-50: #15264a; --primary-100: #1c3260;
    --ok: #4ade80; --ok-bg: #0f2a1c; --warn: #fbbf24; --warn-bg: #2b2210; --danger: #fb923c; --danger-strong: #f87171; --danger-bg: #2d1612;
    --info: #60a5fa; --info-bg: #15264a; --neutral-bg: #1a2540;
    --side-bg: #070d1a; --side-hover: #111c33;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111a2e; --surface-2: #0f1729; --text: #e5eaf3; --text-2: #b5c0d3; --muted: #8592a8; --border: #22304a;
  --primary: #4c8df6; --primary-600: #3b7ae6; --primary-50: #15264a; --primary-100: #1c3260;
  --ok: #4ade80; --ok-bg: #0f2a1c; --warn: #fbbf24; --warn-bg: #2b2210; --danger: #fb923c; --danger-strong: #f87171; --danger-bg: #2d1612;
  --info: #60a5fa; --info-bg: #15264a; --neutral-bg: #1a2540;
  --side-bg: #070d1a; --side-hover: #111c33;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { background: var(--bg); }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 15px; }
a { color: var(--primary); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger-strong); min-height: 1.2em; font-size: 13px; }

/* ---------- Controles ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 8px 14px; border-radius: var(--radius-sm);
  cursor: pointer; font: 500 13.5px var(--font); color: var(--text); transition: background .15s, border-color .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--border) 60%, var(--muted)); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(29, 99, 216, .3); }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--danger-strong); }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger-bg); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; font-size: 14.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm); border: 0; background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: color-mix(in srgb, currentColor 10%, transparent); }

input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); width: 100%; background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); outline: none; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; margin-bottom: 12px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
label > input, label > select, label > textarea, label > .input-group { margin-top: 5px; }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: 13.5px; }
label.inline input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.input-group { display: flex; align-items: center; position: relative; }
.input-group input { padding-right: 44px; }
.input-group .icon-btn { position: absolute; right: 2px; color: var(--muted); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: radial-gradient(1200px 600px at 10% 0%, #2a6fe0 0%, #0f2f6e 45%, #08142e 100%); color: #e6eeff; padding: 64px 56px; display: flex; flex-direction: column; justify-content: center; }
.login-hero h1 { font-size: 34px; color: #fff; margin: 22px 0 10px; }
.login-hero h1 span { color: #8fb8ff; }
.login-hero p { max-width: 440px; color: #c3d4f5; font-size: 15.5px; }
.hero-points { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; }
.hero-points li { padding-left: 30px; position: relative; color: #dbe6ff; }
.hero-points li::before { content: ""; position: absolute; left: 0; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: rgba(143, 184, 255, .22) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238fb8ff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/12px no-repeat; }
.login-panel { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.login-card { width: 100%; max-width: 360px; }
.login-card h2 { font-size: 24px; margin-bottom: 4px; }
.login-card .muted { margin: 0 0 24px; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); display: grid; place-items: center; color: #fff; box-shadow: 0 4px 14px rgba(29, 99, 216, .4); }
.logo-mark.big { width: 56px; height: 56px; border-radius: 14px; }
.logo-mark.big svg { width: 28px; height: 28px; }

/* ---------- Estructura ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 248px; background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; z-index: 10; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-size: 14.5px; letter-spacing: .4px; }
.side-brand b { color: #8fb8ff; }
.side-company { padding: 4px 14px 12px; }
.side-company label { color: var(--side-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; margin: 0 0 4px 4px; }
.side-company select { background: var(--side-hover); border-color: #1e2c48; color: #e5eaf3; font-size: 13px; }
#nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
#nav .group { padding: 16px 10px 6px; font-size: 10.5px; text-transform: uppercase; color: var(--side-muted); letter-spacing: .8px; font-weight: 600; }
#nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 1px 0; color: var(--side-text); text-decoration: none; border-radius: var(--radius-sm); font-weight: 500; font-size: 13.5px; transition: background .12s, color .12s; }
#nav a svg { color: var(--side-muted); }
#nav a:hover { background: var(--side-hover); color: #fff; }
#nav a.active { background: var(--side-active); color: #fff; }
#nav a.active svg { color: #fff; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid #1a2741; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #64748b, #334155); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.who { flex: 1; min-width: 0; line-height: 1.25; }
.who b { display: block; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.who span { color: var(--side-muted); font-size: 12px; }
.side-user .icon-btn { color: var(--side-muted); }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px);
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; border-bottom: 1px solid var(--border); }
.crumbs { color: var(--muted); font-size: 13.5px; display: flex; gap: 8px; align-items: center; min-width: 0; }
.crumbs b { color: var(--text); font-weight: 600; }
.crumbs .sep { opacity: .5; }
.spacer { flex: 1; }
.menu-btn { display: none; }
main { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }

/* ---------- Páginas ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; flex: 1; display: flex; align-items: center; gap: 10px; min-width: 200px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar input[type="date"] { min-width: 0; }
.page-sub { color: var(--muted); margin: -10px 0 18px; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow-sm); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.card.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); font-size: 11.5px; color: var(--muted); font-weight: 600; white-space: nowrap; text-transform: uppercase; letter-spacing: .5px; position: sticky; top: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: color-mix(in srgb, var(--primary-50) 55%, transparent); }
tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--neutral-bg); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.published, .badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.draft, .badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.in_progress, .badge.info { background: var(--info-bg); color: var(--info); }
.badge.archived, .badge.cancelled { background: var(--neutral-bg); color: var(--muted); }
.badge.urgent, .badge.high { background: var(--danger-bg); color: var(--danger-strong); }

/* ---------- Panel ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); display: flex; gap: 14px; align-items: flex-start; }
.kpi .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); flex-shrink: 0; }
.kpi .ico.ok { background: var(--ok-bg); color: var(--ok); }
.kpi .ico.warn { background: var(--warn-bg); color: var(--warn); }
.kpi .ico.neutral { background: var(--neutral-bg); color: var(--text-2); }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 14px; }
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--primary); transition: opacity .15s; }
.chart .bar:hover { opacity: .75; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10.5px; font-family: var(--font); }
.hbars { display: grid; gap: 12px; }
.hbar .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; gap: 8px; }
.hbar .row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .row b { font-variant-numeric: tabular-nums; }
.hbar .track { height: 8px; border-radius: 99px; background: var(--neutral-bg); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 99px; background: var(--primary); }
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-clean li:last-child { border-bottom: 0; }
.list-clean .t { flex: 1; min-width: 0; }
.list-clean .t b { display: block; font-weight: 550; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-clean .t span { color: var(--muted); font-size: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.wo-status { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.wo-status div { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.wo-status b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.wo-status span { font-size: 12px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(8, 15, 30, .5); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; z-index: 40; animation: fade .15s ease-out; }
.modal-box { width: 100%; max-width: 580px; max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 16px; padding: 22px 24px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: pop .18s ease-out; }
.modal-box.wide { max-width: 960px; }
.modal-box h3 { font-size: 17px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 24px; right: 24px; background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 50; max-width: 420px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop .2s ease-out; }
.toast.err { background: var(--danger-strong); }

/* ---------- Detalle de envío ---------- */
.sub-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.sub-head .ico { width: 44px; height: 44px; border-radius: 12px; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; flex-shrink: 0; }
.sub-head h3 { margin: 0 0 2px; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; }
.meta div span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.meta div b { font-weight: 550; font-size: 13.5px; word-break: break-word; }
.kv { display: grid; grid-template-columns: 220px 1fr; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.kv dt, .kv dd { padding: 10px 14px; margin: 0; border-bottom: 1px solid var(--border); }
.kv dt { color: var(--text-2); background: var(--surface-2); font-weight: 500; font-size: 13px; }
.kv dd { word-break: break-word; }
.kv dt.section { grid-column: 1 / -1; background: var(--primary-50); color: var(--primary); font-weight: 650; text-transform: uppercase; font-size: 12px; letter-spacing: .5px; }
.kv > :nth-last-child(-n+2) { border-bottom: 0; }
.kv img { max-width: 220px; max-height: 170px; object-fit: cover; border: 1px solid var(--border); border-radius: 8px; margin: 2px 6px 2px 0; cursor: zoom-in; vertical-align: top; background: #fff; }
.kv img.sig { object-fit: contain; max-height: 110px; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 6px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 16px; }

/* ---------- Constructor ---------- */
.builder { display: grid; grid-template-columns: 190px 1fr 340px; gap: 16px; align-items: start; }
.palette { position: sticky; top: 76px; }
.palette button { display: flex; width: 100%; text-align: left; margin-bottom: 4px; border-color: transparent; background: transparent; }
.palette button:hover { background: var(--primary-50); color: var(--primary); }
.fields-list .fitem { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; background: var(--surface); cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s; }
.fields-list .fitem:hover { border-color: var(--primary-100); }
.fields-list .fitem.sel { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.fields-list .fitem.section { background: var(--surface-2); font-weight: 650; margin-top: 12px; }
.fitem .ftype { font-size: 11px; color: var(--primary); background: var(--primary-50); border-radius: 6px; padding: 2px 8px; min-width: 84px; text-align: center; font-weight: 600; }
.fitem .flabel { flex: 1; }
.fitem .cond { font-size: 11px; color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: 2px 8px; }
.editor { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; }
.editor h3 { display: flex; justify-content: space-between; align-items: center; }
.rule { display: grid; grid-template-columns: 1fr 100px 1fr 30px; gap: 4px; margin-bottom: 6px; }
.rule input, .rule select { padding: 6px; font-size: 12.5px; }
.errors-box { background: var(--danger-bg); color: var(--danger-strong); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.notice { background: var(--info-bg); color: var(--info); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }

@media (max-width: 1200px) {
  .builder { grid-template-columns: 1fr; }
  .palette, .editor { position: static; max-height: none; }
  .palette { display: flex; flex-wrap: wrap; gap: 4px; }
  .palette h3 { width: 100%; }
  .palette button { width: auto; margin: 0; border-color: var(--border); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { padding: 40px 24px; }
  .login-hero .hero-points { display: none; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  main { padding: 18px 16px 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { border-bottom: 0; padding-bottom: 2px; }
  .toolbar input, .toolbar select { width: 100%; }
}
