/* =====================================================================
   Defender MSP Console
   ===================================================================== */

:root {
  --bg:            #f4f6f9;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --border:        #e3e8ef;
  --text:          #16202e;
  --text-dim:      #5c6b80;
  --text-faint:    #8695a8;

  --sidebar-bg:    #101a28;
  --sidebar-text:  #b4c1d3;
  --sidebar-hover: #1a2739;
  --accent:        #2f6fed;
  --accent-soft:   #e8f0fe;

  --sev-high:      #d93b47;
  --sev-medium:    #e08217;
  --sev-low:       #c9a227;
  --sev-info:      #4a8cc7;
  --sev-unknown:   #8695a8;
  --ok:            #1f9d55;
  --warn:          #b7791f;

  --radius:        10px;
  --shadow:        0 1px 2px rgba(16,26,40,.06), 0 4px 14px rgba(16,26,40,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0d141f;
    --surface:   #141d2b;
    --surface-2: #18222f;
    --border:    #253244;
    --text:      #e6ecf5;
    --text-dim:  #9db0c8;
    --text-faint:#7288a3;
    --accent-soft: #17233a;
    --shadow:    0 1px 2px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.2px; }
h2 { font-size: 14px; margin: 0 0 14px; font-weight: 650; text-transform: uppercase;
     letter-spacing: .6px; color: var(--text-dim); }
h2.mt { margin-top: 28px; }
p  { margin: 0 0 10px; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2);
       padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }

/* ------------------------------ Layout ----------------------------- */

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: 232px;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; }
.brand-mark { font-size: 22px; }
.brand-text { color: #fff; font-weight: 650; font-size: 14px; line-height: 1.25; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; font-size: 13.5px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { width: 17px; height: 17px; fill: currentColor; opacity: .85; flex: none; }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,.1); padding: 14px 11px 2px; }
.who strong { display: block; color: #fff; font-size: 13px; }
.who .role { color: var(--text-faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
.link-quiet { display: inline-block; margin-top: 8px; color: var(--sidebar-text); font-size: 12.5px; }

.main { margin-left: 232px; padding: 26px 30px 60px; max-width: 1560px; }

.foot { margin-top: 40px; color: var(--text-faint); font-size: 12px; }

/* ---------------------------- Cabecera ----------------------------- */

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 20px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head .muted { margin: 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs { font-size: 13px; margin-bottom: 6px; }
.detail-badges { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }

.muted { color: var(--text-dim); font-size: 13px; }
.small { font-size: 12.5px; }
.mono  { font-family: var(--mono); }
.break { word-break: break-all; }
.num   { text-align: right; }
.err   { color: var(--sev-high); }
.right { margin-left: auto; }
.inline { display: inline; }

/* ----------------------------- Tarjetas ---------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card.no-pad { padding: 0; overflow: hidden; }
.card.no-pad .card-head { padding: 16px 20px 0; margin: 0; }
.card.no-pad .empty { padding: 34px 20px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-detail { display: grid; grid-template-columns: minmax(0,1fr) 330px; gap: 18px; align-items: start; }

@media (max-width: 1100px) {
  .grid-2, .grid-detail { grid-template-columns: 1fr; }
}

/* ------------------------------- KPIs ------------------------------ */

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
  color: var(--text);
}
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 30px; font-weight: 640; line-height: 1.1; letter-spacing: -1px; }
.kpi-sub   { font-size: 12px; color: var(--text-faint); }
.kpi-high  { border-left-color: var(--sev-high); }
.kpi-open  { border-left-color: var(--sev-medium); }
.kpi-ok    { border-left-color: var(--ok); }

/* ------------------------------ Tablas ----------------------------- */

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); font-weight: 600;
  padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table-alerts tbody tr { cursor: pointer; }
.table .row-off { opacity: .55; }

.row-title { font-weight: 550; color: var(--text); }
.row-title:hover { color: var(--accent); }
.row-sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.w-sev { width: 96px; } .w-tenant { width: 170px; } .w-prod { width: 150px; }
.w-status { width: 110px; } .w-date { width: 110px; } .w40 { width: 22%; }
.actions { white-space: nowrap; }
.actions form, .actions a { margin-left: 4px; }
.empty { color: var(--text-dim); text-align: center; padding: 34px 0; }

/* ------------------------- Etiquetas y pills ----------------------- */

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; color: #fff; white-space: nowrap;
}
.pill.sev-high { background: var(--sev-high); }
.pill.sev-medium { background: var(--sev-medium); }
.pill.sev-low { background: var(--sev-low); }
.pill.sev-informational { background: var(--sev-info); }
.pill.sev-unknown, .pill.sev- { background: var(--sev-unknown); }

.status {
  display: inline-block; padding: 2px 9px; border-radius: 6px;
  font-size: 11.5px; font-weight: 550; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-dim); white-space: nowrap;
}
.status-new        { border-color: #c9d8f5; background: var(--accent-soft); color: var(--accent); }
.status-active     { border-color: #c9d8f5; background: var(--accent-soft); color: var(--accent); }
.status-inProgress { border-color: #f3ddb8; background: #fdf5e7; color: #8a5b12; }
.status-resolved   { border-color: #c2e4cd; background: #edf8f1; color: #1b7a45; }
.status-sync-ok    { border-color: #c2e4cd; background: #edf8f1; color: #1b7a45; }
.status-sync-error { border-color: #f2c9cd; background: #fdeef0; color: #a92230; }
.status-sync-never, .status-sync-running { color: var(--text-faint); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11.5px;
       background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); }
.tag-sm { font-size: 11px; padding: 1px 6px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.sev-high { background: var(--sev-high); }
.dot.sev-medium { background: var(--sev-medium); }
.dot.sev-low { background: var(--sev-low); }
.dot.sev-informational { background: var(--sev-info); }
.dot.sev-unknown, .dot.sev- { background: var(--sev-unknown); }

.tdot { display: inline-block; width: 8px; height: 8px; border-radius: 2px;
        margin-right: 6px; vertical-align: middle; }

.count { display: inline-block; background: var(--surface-2); border: 1px solid var(--border);
         border-radius: 10px; padding: 0 7px; font-size: 11.5px; color: var(--text-dim); }

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

.btn {
  display: inline-block; padding: 7px 13px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 550;
  cursor: pointer; font-family: inherit; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; border-color: var(--text-faint); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2560d8; border-color: #2560d8; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--sev-high); border-color: #f0cbcf; }
.btn-danger:hover { background: #fdeef0; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 6px; padding: 10px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px;
       overflow: hidden; background: var(--surface); }
.seg a { padding: 6px 13px; font-size: 12.5px; color: var(--text-dim);
         border-right: 1px solid var(--border); }
.seg a:last-child { border-right: 0; }
.seg a:hover { background: var(--surface-2); text-decoration: none; }
.seg a.on { background: var(--accent); color: #fff; }

/* ------------------------------ Filtros ---------------------------- */

.filters { padding: 16px 18px; }
.f-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.f-row + .f-row { margin-top: 12px; }
.f-row .grow { flex: 1 1 240px; }

label { display: block; font-size: 12px; color: var(--text-dim); font-weight: 550; }
input[type=text], input[type=search], input[type=password], select, textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 7px 10px; font-size: 13.5px; font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=color] { margin-top: 4px; width: 52px; height: 34px; padding: 2px;
                    border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
small { display: block; margin-top: 4px; color: var(--text-faint); font-size: 11.5px; font-weight: 400; }
textarea { resize: vertical; }

.chips { align-items: center; }
.chip-group-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
                    color: var(--text-faint); font-weight: 600; margin-right: -4px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; color: var(--text-dim); font-weight: 500;
}
.chip input { display: none; }
.chip:hover { border-color: var(--text-faint); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.sev-high.on    { background: var(--sev-high); border-color: var(--sev-high); }
.chip.sev-medium.on  { background: var(--sev-medium); border-color: var(--sev-medium); }
.chip.sev-low.on     { background: var(--sev-low); border-color: var(--sev-low); }
.chip.sev-informational.on { background: var(--sev-info); border-color: var(--sev-info); }

.switches { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 14px 0; }
.switches legend { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
                   color: var(--text-faint); padding: 0 6px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13.5px;
          color: var(--text); font-weight: 450; padding: 3px 0; }
.switch input { width: auto; margin: 0; }

.form-narrow { max-width: 640px; }
.form-narrow label { margin-bottom: 14px; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ------------------------------ Graficos --------------------------- */

.chart-bars { display: flex; align-items: flex-end; gap: 2px; height: 150px;
              padding: 6px 0; border-bottom: 1px solid var(--border); }
.bar-col { height: 100%; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0;
       display: flex; align-items: flex-end; opacity: .85; }
.bar:hover { opacity: 1; }
.bar-high { width: 100%; background: var(--sev-high); border-radius: 0 0 3px 3px; }
.chart-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-dim); }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.sw-total { background: var(--accent); }
.sw-high { background: var(--sev-high); }

.meter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.meter-label { flex: 0 0 175px; display: flex; align-items: center; gap: 7px;
               font-size: 13px; color: var(--text); }
.meter-label:hover { color: var(--accent); text-decoration: none; }
.meter { flex: 1; height: 8px; background: var(--surface-2); border-radius: 5px;
         overflow: hidden; border: 1px solid var(--border); }
.meter-fill { height: 100%; border-radius: 5px; background: var(--accent); }
.meter-fill.sev-high { background: var(--sev-high); }
.meter-fill.sev-medium { background: var(--sev-medium); }
.meter-fill.sev-low { background: var(--sev-low); }
.meter-fill.sev-informational { background: var(--sev-info); }
.meter-fill.sev-unknown, .meter-fill.sev- { background: var(--sev-unknown); }
.meter-fill.neutral { background: var(--accent); opacity: .65; }
.meter-value { flex: 0 0 46px; text-align: right; font-size: 13px;
               font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* ------------------------------- Listas ---------------------------- */

.taglist { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 7px; }
.taglist a { display: inline-block; padding: 4px 10px; border-radius: 20px;
             background: var(--surface-2); border: 1px solid var(--border);
             color: var(--text-dim); font-size: 12.5px; }
.taglist a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.feed { list-style: none; padding: 0; margin: 0; }
.feed li { display: grid; grid-template-columns: 12px 1fr; gap: 9px;
           padding: 9px 0; border-bottom: 1px solid var(--border); align-items: start; }
.feed li:last-child { border-bottom: 0; }
.feed .dot { margin-top: 5px; }
.feed-title { display: block; font-size: 13.5px; color: var(--text); font-weight: 500; }
.feed-title:hover { color: var(--accent); }
.feed-meta { display: block; font-size: 12px; color: var(--text-faint); margin-top: 1px; }

.steps { margin: 0; padding-left: 20px; color: var(--text); }
.steps li { margin-bottom: 7px; }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 7px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--text-faint); font-size: 12px; }
.kv dd { margin: 0; color: var(--text); }

.prose { color: var(--text); font-size: 13.5px; line-height: 1.6; }

/* ----------------------------- Evidencias -------------------------- */

.evidence { display: flex; flex-direction: column; gap: 6px; }
.ev-item { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.ev-item > summary { padding: 9px 12px; cursor: pointer; display: flex; gap: 9px;
                     align-items: center; flex-wrap: wrap; font-size: 13px; }
.ev-item > summary::-webkit-details-marker { display: none; }
.ev-type { font-family: var(--mono); font-size: 11.5px; color: var(--accent);
           background: var(--accent-soft); padding: 1px 7px; border-radius: 5px; }
.ev-sum { color: var(--text); flex: 1; min-width: 200px; }
.raw-toggle { cursor: pointer; font-size: 13px; color: var(--text-dim); font-weight: 550; }

.json, .code {
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  background: var(--sidebar-bg); color: #cfe0f5;
  padding: 12px 14px; border-radius: 8px; overflow-x: auto;
  margin: 10px 0 0; white-space: pre;
}
.code { margin: 10px 0; }

/* ---------------------------- Paginacion --------------------------- */

.pager { display: flex; gap: 4px; justify-content: center; margin: 18px 0; flex-wrap: wrap; }
.pager a { padding: 6px 11px; border: 1px solid var(--border); border-radius: 7px;
           background: var(--surface); color: var(--text-dim); font-size: 13px; }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager a.disabled { opacity: .4; pointer-events: none; }
.pager .gap { padding: 6px 4px; color: var(--text-faint); }

/* ------------------------------ Avisos ----------------------------- */

.flash { padding: 11px 15px; border-radius: 8px; margin-bottom: 16px;
         font-size: 13.5px; border: 1px solid; }
.flash-ok    { background: #edf8f1; border-color: #c2e4cd; color: #16663a; }
.flash-error { background: #fdeef0; border-color: #f2c9cd; color: #96202c; }
.flash-warn  { background: #fdf7e7; border-color: #f0e0b6; color: #7a5a10; }
.flash a { color: inherit; text-decoration: underline; }

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

body.bare { background: var(--sidebar-bg); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--surface); border-radius: 14px; padding: 34px 32px;
  width: 100%; max-width: 372px; box-shadow: 0 18px 50px rgba(0,0,0,.35);
}
.login-brand { font-size: 34px; text-align: center; }
.login-card h1 { text-align: center; font-size: 19px; margin-top: 8px; }
.login-card > .muted { text-align: center; margin-bottom: 22px; }
.login-card label { margin-bottom: 14px; }

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

@media (max-width: 820px) {
  .sidebar { position: static; width: auto; flex-direction: row; align-items: center;
             padding: 10px 14px; gap: 12px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand-text { display: none; }
  .sidebar nav { flex-direction: row; flex: 1; }
  .nav-item { white-space: nowrap; }
  .sidebar-foot { border: 0; padding: 0; }
  .who { display: none; }
  .main { margin-left: 0; padding: 18px 14px 40px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .meter-label { flex-basis: 110px; }
}
