:root {
  --bg: #f4f6f9; --panel: #ffffff; --side: #14213d; --side-text: #c9d3e6; --side-active: #24365e;
  --text: #1c2433; --muted: #6b7587; --line: #e2e6ee; --accent: #2563eb; --accent-text: #fff;
  --ok: #15803d; --ok-bg: #dcfce7; --info: #1d4ed8; --info-bg: #dbeafe; --warn: #a16207; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2; --mute-bg: #eef0f4;
  --free: #e8f5ec; --used: #3b82f6; --gw: #7c3aed; --dhcp: #fde7b0;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --panel: #171e29; --side: #0b1018; --side-text: #a9b4c8; --side-active: #1d2a40;
    --text: #e3e8f0; --muted: #8b95a7; --line: #2a3342; --accent: #3b82f6;
    --ok: #4ade80; --ok-bg: #12351f; --info: #93c5fd; --info-bg: #172a4a; --warn: #fcd34d; --warn-bg: #3a2e0c;
    --bad: #fca5a5; --bad-bg: #431414; --mute-bg: #232c3a;
    --free: #16301f; --used: #2563eb; --gw: #7c3aed; --dhcp: #4a3a12;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .95em; }
.muted { color: var(--muted); }
.small, small { font-size: 12px; }

/* sidebar */
.sidebar { width: 240px; flex-shrink: 0; background: var(--side); color: var(--side-text); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 8px 14px; }
.brand:hover { text-decoration: none; }
.logo { background: var(--accent); color: #fff; border-radius: 7px; padding: 2px 7px; font-size: 13px; }
.search input { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #2c3d63; background: #0d1830; color: #fff; margin-bottom: 8px; }
.sidebar nav a { display: block; padding: 7px 10px; border-radius: 7px; color: var(--side-text); }
.sidebar nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.nav-group { text-transform: uppercase; font-size: 11px; letter-spacing: .08em; opacity: .6; margin: 16px 10px 4px; }
.menu-btn { display: none; }

main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.sub { margin: 4px 0 0; color: var(--muted); }
.crumbs { margin: 0 0 2px; font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

/* filters & tables */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.filters input[type=search] { width: 280px; }
.filters select { width: auto; max-width: 240px; }
.count { color: var(--muted); margin-left: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card .table-wrap { border: 0; border-radius: 0; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
table.sortable th { cursor: pointer; user-select: none; }
table.sortable th[data-dir=asc]::after { content: " ▲"; }
table.sortable th[data-dir=desc]::after { content: " ▼"; }
table.data tbody tr[data-href] { cursor: pointer; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
table.data tr:last-child td { border-bottom: 0; }
table.compact td { padding: 5px 6px; }
.row-link { font-weight: 600; }
tr.row-bad { background: var(--bad-bg); }
.empty { color: var(--muted); padding: 24px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.card .empty { border: 0; padding: 8px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-muted { background: var(--mute-bg); color: var(--muted); }
.late { color: var(--bad); font-weight: 600; }
.soon { color: var(--warn); font-weight: 600; }
.alert-text { color: var(--bad); font-weight: 600; }
.warn-text { color: var(--warn); }

/* forms */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); gap: 16px; align-items: start; }
.record-form fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.record-form legend { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0; margin-bottom: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.req { color: var(--bad); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.error { color: var(--bad); }
.hint { color: var(--muted); }
.fk { display: flex; gap: 4px; }
.fk-new { display: grid; place-items: center; width: 34px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 7px; font-weight: 700; }
.fk-new:hover { text-decoration: none; border-color: var(--accent); }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; }
.side .card { margin-bottom: 16px; }
.contact { padding: 8px 0; border-top: 1px solid var(--line); }
.contact a { margin-right: 10px; white-space: nowrap; }
.contact .muted { margin-left: 4px; }
.support p { margin: 4px 0; }
.history { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.history > li { padding: 6px 0; border-top: 1px solid var(--line); }
.history ul { margin: 4px 0 0 0; padding-left: 16px; }
.history s { color: var(--muted); }

/* stats & dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--text); box-shadow: var(--shadow); display: flex; flex-direction: column; }
a.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat b { font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.alert b { color: var(--bad); }
.stat.warn b { color: var(--warn); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.dash-grid .card { margin: 0; }
.usage { padding: 6px 0; }
.usage .mono { margin-left: 6px; }
.bar { height: 7px; background: var(--mute-bg); border-radius: 99px; overflow: hidden; margin: 4px 0; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; min-width: 2px; }
.bar.small { width: 90px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.welcome ol { margin: 0; padding-left: 20px; }
.welcome li { margin: 4px 0; }

/* IP map */
.legend { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.legend .cell { width: auto; padding: 2px 8px; height: auto; }
.ipgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; }
.cell { display: grid; place-items: center; height: 34px; border-radius: 6px; font: 600 12px ui-monospace, Consolas, monospace; border: 1px solid var(--line); background: var(--free); color: var(--text); cursor: pointer; padding: 0; }
.cell:hover { text-decoration: none; outline: 2px solid var(--accent); }
.cell.usada { background: var(--used); color: #fff; border-color: transparent; }
.cell.gateway { background: var(--gw); color: #fff; border-color: transparent; }
.cell.dhcp { background: var(--dhcp); }
.cell.conflicto { background: #dc2626; color: #fff; border-color: transparent; }
.cell.sel { outline: 3px solid var(--accent); }
.assign { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: sticky; top: 8px; z-index: 2; }

/* agenda */
.agenda { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.agenda .card { margin: 0; }
.company-info { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 6px; }
.company details { margin-top: 8px; font-size: 13px; }
.company summary { cursor: pointer; color: var(--muted); }

@media (max-width: 1100px) { .form-layout { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  body { display: block; }
  .sidebar { position: fixed; z-index: 20; left: -260px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-block; position: fixed; top: 10px; right: 10px; z-index: 30; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 18px; }
  main { padding: 16px; }
  .filters input[type=search] { width: 100%; }
  .dash-grid, .agenda { grid-template-columns: 1fr; }
}
[hidden] { display: none !important; }

/* usuario y autenticación */
.sidebar { display: flex; flex-direction: column; }
.sidebar nav { flex: 1; }
.user-box { border-top: 1px solid #2c3d63; margin-top: 14px; padding: 12px 8px 4px; }
.user-name { color: #fff; font-weight: 600; }
.user-meta { font-size: 12px; opacity: .75; margin-bottom: 8px; word-break: break-all; }
.user-box .btn { background: transparent; color: var(--side-text); border-color: #2c3d63; }
.made-by { font-size: 11px; opacity: .5; padding: 10px 8px 0; letter-spacing: .06em; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .brand { color: var(--text); padding: 0 0 18px; }
.auth-card .field { margin-bottom: 12px; }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 10px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.narrow { max-width: 560px; }

/* tickets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.note-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.note-actions { display: flex; gap: 8px; }
.note-actions select { flex: 1; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 12px; border-left: 2px solid var(--accent); margin-left: 4px; }
.timeline li + li { margin-top: 4px; }
.timeline li.sys { border-left-color: var(--line); }
.timeline li.sys .text { color: var(--muted); font-size: 13px; }
.timeline .meta { font-size: 12px; color: var(--muted); }
.timeline .text { white-space: pre-wrap; }

/* calendario */
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cal-toolbar .filters { margin: 0; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav h2 { margin: 0 6px; font-size: 18px; min-width: 150px; text-align: center; }
.cal-legend .ev { display: inline-block; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; margin-bottom: 16px; }
.cal-head { background: var(--panel); text-align: center; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--muted); padding: 6px; }
.cal-day { background: var(--panel); min-height: 112px; padding: 4px 5px 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day.out { background: var(--bg); }
.cal-day.out .cal-num span { opacity: .45; }
.cal-num { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; }
.cal-day.today .cal-num span { background: var(--accent); color: #fff; border-radius: 99px; padding: 1px 7px; }
.cal-add { opacity: 0; font-weight: 700; padding: 0 6px; border-radius: 6px; }
.cal-day:hover .cal-add { opacity: 1; }
.cal-add:hover { background: var(--mute-bg); text-decoration: none; }
.ev { display: block; font-size: 12px; line-height: 1.3; padding: 2px 6px; border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid transparent; color: var(--text); }
.ev:hover { text-decoration: none; filter: brightness(.95); }
.ev.prog { background: var(--info-bg); border-left-color: var(--info); }
.ev.reprog { background: var(--warn-bg); border-left-color: var(--warn); }
.ev.done { background: var(--ok-bg); border-left-color: var(--ok); }
.ev.cancel { background: var(--mute-bg); color: var(--muted); text-decoration: line-through; }
.ev.late { background: var(--bad-bg); border-left-color: var(--bad); }
.ev.ficha { background: transparent; border: 1px dashed var(--muted); border-left-width: 3px; }
.ev.ficha.late { border-color: var(--bad); }
.ev.venc { background: var(--mute-bg); border-left-color: #8b5cf6; }
.ev.ticket { background: var(--warn-bg); border-left-color: #f59e0b; }
.ev.tag { display: inline-block; white-space: nowrap; }
.ev-more { font-size: 11px; color: var(--muted); padding-left: 6px; }
.nowrap { white-space: nowrap; }
@media (max-width: 800px) {
  .cal { display: none; }
  .cal-nav h2 { min-width: 0; }
}
.cal .ev { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }

/* WhatsApp */
a.wa { color: #16a34a; white-space: nowrap; }
a.wa::before { content: ""; display: inline-block; width: 1em; height: 1em; margin-right: 4px; vertical-align: -2px;
  background: currentColor; -webkit-mask: var(--wa-icon) center / contain no-repeat; mask: var(--wa-icon) center / contain no-repeat; }
.wa-btn { color: #16a34a; border-color: color-mix(in srgb, #16a34a 45%, var(--line)); }
.wa-btn:hover { border-color: #16a34a; }
@media (prefers-color-scheme: dark) { a.wa, .wa-btn { color: #4ade80; } }
:root { --wa-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 0 0-8.6 15.1L2 22l5-1.3A10 10 0 1 0 12 2zm0 18.2a8.2 8.2 0 0 1-4.2-1.2l-.3-.2-3 .8.8-2.9-.2-.3A8.2 8.2 0 1 1 12 20.2zm4.5-6.1c-.2-.1-1.5-.7-1.7-.8s-.4-.1-.6.1-.7.8-.8 1-.3.2-.5.1a6.7 6.7 0 0 1-3.3-2.9c-.3-.4.2-.4.7-1.3.1-.2 0-.3 0-.4l-.8-1.8c-.2-.5-.4-.4-.6-.4h-.5a1 1 0 0 0-.7.3 3 3 0 0 0-.9 2.2 5.2 5.2 0 0 0 1.1 2.7 11.8 11.8 0 0 0 4.5 4c1.7.7 2.3.8 3.2.6a2.7 2.7 0 0 0 1.8-1.3 2.2 2.2 0 0 0 .2-1.3c-.1-.1-.3-.2-.5-.3z'/%3E%3C/svg%3E"); }

.mini-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.mini-stats b { color: var(--text); font-size: 16px; }

/* íconos de línea */
.ic { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; flex-shrink: 0; }
.sidebar nav a { display: flex; align-items: center; gap: 9px; }
.sidebar nav a .ic { opacity: .85; }
.sidebar nav a.active .ic { opacity: 1; color: #fff; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }
.page-head h1 .ic { color: var(--accent); width: 1em; height: 1em; stroke-width: 1.9; }
.card h3 .ic { color: var(--muted); margin-right: 2px; }
.stat span .ic { width: 1.05em; height: 1.05em; margin-right: 3px; }
.btn .ic { width: 1.05em; height: 1.05em; }
.menu-btn .ic { width: 22px; height: 22px; vertical-align: middle; }
.contact .ic, .company-info .ic { width: 1em; height: 1em; margin-right: 2px; color: var(--muted); }
.alert-text .ic { color: var(--bad); }

.logo-edit { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.logo-preview { width: 180px; height: 80px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; background: #fff; padding: 6px; }
.logo-preview { overflow: hidden; }
.logo-preview img { max-width: 166px; max-height: 66px; width: auto; height: auto; object-fit: contain; }
.logo-inputs { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 6px; }
.logo-inputs input[type=file] { padding: 6px; }

/* PWA: marca, instalación y configuración de la app */
[hidden] { display: none !important; }
.brand-icon { width: 28px; height: 28px; border-radius: 7px; object-fit: contain; flex: none; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.install-btn { margin: 12px 8px 0; background: transparent; color: var(--side-text); border-color: #2c3d63; }
.offline-card h1 { margin: 0 0 8px; font-size: 22px; }
.offline-card .btn { margin-top: 12px; }
.config-section { margin: 4px 0 2px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.config-section + .sub { margin: 0 0 12px; }
.config-sep { border: 0; border-top: 1px solid var(--line); margin: 22px 0 16px; }
.icon-preview { display: flex; gap: 12px; align-items: flex-end; }
.icon-preview figure { margin: 0; text-align: center; font-size: 11px; color: var(--muted); }
.icon-preview img { display: block; margin: 0 auto 4px; background: repeating-conic-gradient(#e9ecf1 0 25%, #fff 0 50%) 0 0 / 12px 12px; }
.icon-preview .i-any { width: 72px; height: 72px; border-radius: 16px; }
.icon-preview .i-mask { width: 72px; height: 72px; border-radius: 50%; }
.icon-preview .i-fav { width: 32px; height: 32px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type=color] { width: 48px; height: 36px; padding: 2px; flex: none; }
