:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1d1b19;
  --ink-2: #4a4540;
  --muted: #7a736b;
  --line: #e6e0d8;
  --line-2: #d6cec3;
  --accent: #d9472b;
  --accent-ink: #ffffff;
  --accent-soft: #fbe7e1;
  --ok: #2f7d4f;
  --ok-soft: #e3f1e8;
  --warn: #a86200;
  --warn-soft: #fbefd9;
  --err: #b3261e;
  --err-soft: #f9e1df;
  --idle: #8a8178;
  --idle-soft: #eeeae4;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(29, 27, 25, .05), 0 8px 24px -12px rgba(29, 27, 25, .12);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151312;
    --surface: #1e1b19;
    --surface-2: #24211e;
    --ink: #f1ece6;
    --ink-2: #cfc7be;
    --muted: #9a9188;
    --line: #2f2b27;
    --line-2: #3d3833;
    --accent: #f0664a;
    --accent-ink: #1a0d09;
    --accent-soft: #3a211b;
    --ok: #5cc287;
    --ok-soft: #1c2e23;
    --warn: #f0b252;
    --warn-soft: #33271a;
    --err: #f2867d;
    --err-soft: #3a1f1d;
    --idle: #9a9188;
    --idle-soft: #2a2623;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { background: var(--ink-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.danger { color: var(--err); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  font: inherit; font-size: 15px; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.icon-btn:disabled { opacity: .4; cursor: progress; }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 32px 28px;
}
.login-card h1 { margin: 18px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card .btn { width: 100%; justify-content: center; margin-top: 14px; height: 42px; }
.login-card .warn-box { margin-top: 0; }

/* ---------- Estructura ---------- */

.shell { max-width: 1200px; margin: 0 auto; padding: 0 16px 64px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 22px 0 20px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 20px; letter-spacing: -.02em;
}
.brand strong { display: block; font-size: 17px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 13px; color: var(--muted); }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-panel button, .menu-panel a {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink);
  font: inherit; font-size: 14px; cursor: pointer; text-decoration: none;
}
.menu-panel button:hover, .menu-panel a:hover { background: var(--surface-2); }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

.warn-box {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 0 0 16px; padding: 12px 14px;
  background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: var(--radius-sm); font-size: 14px;
}
.warn-box strong { color: var(--warn); }

/* ---------- Estadísticas ---------- */

.stats {
  display: grid; gap: 12px; margin-bottom: 22px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.stat .value { font-size: 30px; font-weight: 750; letter-spacing: -.03em; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat.warn .value { color: var(--warn); }
.stat.err .value { color: var(--err); }
.stat.ok .value { color: var(--ok); }
.stat .value.small { font-size: 19px; padding-top: 8px; }

/* ---------- Barra de filtros ---------- */

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.segmented .count { opacity: .65; font-weight: 500; margin-left: 3px; }
.search {
  height: 38px; width: 260px; max-width: 100%;
  padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit;
}

/* ---------- Lista de webs ---------- */

.sites { display: grid; gap: 10px; }

.site {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.site-row {
  display: grid; align-items: center; gap: 16px;
  grid-template-columns: 34px minmax(180px, 1.5fr) minmax(170px, 1.2fr) minmax(150px, 1fr) minmax(120px, .8fr) auto;
  padding: 14px 14px 14px 10px;
}
.site.is-open .site-row { border-bottom: 1px solid var(--line); }

.expand { transition: transform .15s; }
.site.is-open .expand { transform: rotate(90deg); }

.site-name { min-width: 0; }
.site-name h3 { margin: 0; font-size: 15.5px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-name a { font-size: 13px; color: var(--muted); text-decoration: none; }
.site-name a:hover { color: var(--accent); text-decoration: underline; }

.cell-label { display: none; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 650; padding: 3px 10px; border-radius: 999px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.updates { background: var(--warn-soft); color: var(--warn); }
.pill.error { background: var(--err-soft); color: var(--err); }
.pill.never, .pill.unconfigured, .pill.disabled { background: var(--idle-soft); color: var(--idle); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; }
.chip.core { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }

.err-line { margin-top: 6px; font-size: 12.5px; color: var(--err); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.streak { display: flex; gap: 3px; margin-top: 7px; }
.streak i { width: 9px; height: 14px; border-radius: 3px; background: var(--idle-soft); }
.streak i.ok { background: var(--ok); }
.streak i.ko { background: var(--err); }

.meta { font-size: 13px; color: var(--ink-2); }
.meta .muted { color: var(--muted); }

.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* Detalle desplegable */
.site-detail { padding: 16px 18px 20px 54px; background: var(--surface-2); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; }
.detail-grid h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.detail-grid h4 a { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--accent); font-size: 13px; }

table.items { width: 100%; border-collapse: collapse; font-size: 14px; }
table.items th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 8px 6px 0; border-bottom: 1px solid var(--line); }
table.items td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.items tr:last-child td { border-bottom: 0; }
table.items .ver { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; color: var(--ink-2); }
table.items .ver b { color: var(--ink); font-weight: 600; }
.tag { font-size: 11.5px; color: var(--muted); }
.tag.auto { color: var(--ok); }

.log { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.log li { display: grid; grid-template-columns: 14px 112px 1fr; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.log li:last-child { border-bottom: 0; }
.log .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); transform: translateY(-1px); }
.log .dot.ko { background: var(--err); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .why { color: var(--ink-2); }
.log .why.ko { color: var(--err); }

.empty-detail { color: var(--muted); font-size: 14px; margin: 0; }
.notes { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

/* Estado vacío y guía */
.empty {
  background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius);
  padding: 36px 24px; text-align: center; color: var(--muted);
}

.guide {
  margin-top: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px;
}
.guide h3 { margin: 0 0 12px; font-size: 15px; }
.guide ol { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 14px; }
.guide li { margin-bottom: 6px; }

.runs { margin-top: 26px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.runs section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.runs h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.runs ul { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.runs li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.runs li:last-child { border-bottom: 0; }
.runs li span:last-child { color: var(--muted); text-align: right; }

/* ---------- Diálogo ---------- */

.dialog {
  width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45);
}
.dialog::backdrop { background: rgba(20, 16, 13, .45); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.dialog-head h2 { margin: 0; font-size: 19px; }
.dialog-body { padding: 6px 20px 8px; overflow: auto; }
.dialog-foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.spacer { flex: 1; }

fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px 14px; margin: 12px 0; }
legend { font-weight: 700; font-size: 14px; padding: 0 6px; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-top: 10px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type="text"], input:not([type]), input[type="password"], input[type="url"] {
  display: block; width: 100%; height: 40px; margin-top: 5px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface); color: var(--ink); font: inherit; font-size: 14.5px;
}
input:focus-visible, .search:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.help { margin: 4px 0 2px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.help a { color: var(--accent); font-weight: 600; }

.switch { display: inline-flex; align-items: center; gap: 10px; margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 36px; height: 21px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(15px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

fieldset.is-off .grid-2, fieldset.is-off > label, fieldset.is-off .help { opacity: .5; }

.form-error { margin: 8px 0 4px; padding: 10px 12px; border-radius: 9px; background: var(--err-soft); color: var(--err); font-size: 14px; }

/* ---------- Toasts ---------- */

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast {
  background: var(--ink); color: var(--bg); padding: 11px 15px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,.4); max-width: 420px; animation: rise .2s ease-out;
}
.toast.err { background: var(--err); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Responsive ---------- */

@media (max-width: 1020px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .site-row { grid-template-columns: 34px minmax(0, 1fr) auto; grid-template-areas: "x name act" "x upd upd" "x log log" "x meta meta"; row-gap: 12px; }
  .site-row > .expand { grid-area: x; align-self: start; }
  .site-row > .site-name { grid-area: name; }
  .site-row > .cell-upd { grid-area: upd; }
  .site-row > .cell-log { grid-area: log; }
  .site-row > .meta { grid-area: meta; }
  .site-row > .row-actions { grid-area: act; align-self: start; }
  .cell-label { display: block; }
  .detail-grid { grid-template-columns: 1fr; }
  .site-detail { padding-left: 18px; }
  .runs { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 26px; }
  .top-actions { width: 100%; }
  .top-actions > .btn.primary { flex: 1; justify-content: center; }
  .grid-2 { grid-template-columns: 1fr; }
  .search { width: 100%; }
  .log li { grid-template-columns: 14px 1fr; }
  .log .why { grid-column: 2; }
  .dialog-foot { flex-wrap: wrap; }
}
.err-text { color: var(--err); }
