/* ===== CRM — estilos base (identidad isanlab) ===== */
@font-face {
  font-family: 'Nunito';
  src: url('../fonts/Nunito.ttf') format('truetype-variations');
  font-weight: 200 1000;
  font-display: swap;
}
* { box-sizing: border-box; }
:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --panel-2: #f8fafc;       /* superficie secundaria: cabeceras de tabla, hover */
  --input-bg: #ffffff;
  --ink: #21302a;
  --muted: #68796f;
  --line: #dde6e0;
  --primary: #f2990a;       /* naranja isanlab (principal) */
  --primary-dark: #d98500;
  --primary-ink: #2b1c00;   /* texto oscuro sobre naranja */
  --link: #b06000;          /* naranja oscurecido legible para enlaces */
  --accent: #3e7561;        /* verde isanlab (acento) */
  --danger: #c93a3a;
  --ok: #1f8a4c;
  --warn: #b07708;
  --sidebar: #182420;       /* verde muy oscuro de marca */
  --focus: rgba(242, 153, 10, .4);
  --radius: 10px;
}
/* ===== Modo oscuro (se aplica con data-theme="dark" en <html>) ===== */
:root[data-theme="dark"] {
  --bg: #0f1512;
  --panel: #1a221e;
  --panel-2: #212b26;
  --input-bg: #141a17;
  --ink: #e7ede9;
  --muted: #93a49a;
  --line: #2c3832;
  --link: #f2990a;          /* en oscuro el naranja vivo ya contrasta */
  --sidebar: #121815;
}
:root[data-theme="dark"] .badge-lead    { background: #4a3a12; color: #f0cf7e; }
:root[data-theme="dark"] .badge-cliente,
:root[data-theme="dark"] .badge-activo   { background: #163a28; color: #7fd8a4; }
:root[data-theme="dark"] .badge-antiguo,
:root[data-theme="dark"] .badge-cancelado{ background: #2b3640; color: #a8bacb; }
:root[data-theme="dark"] .badge-caducado { background: #4a1f1f; color: #f0a3a3; }
:root[data-theme="dark"] .badge-pronto   { background: #4a3a12; color: #f0cf7e; }
:root[data-theme="dark"] .badge-ingreso  { background: #17324f; color: #8fc0f0; }
:root[data-theme="dark"] .alert-error { background: #3a1c1c; border-color: #6a3535; color: #f0b4b4; }
:root[data-theme="dark"] .alert-ok    { background: #163025; border-color: #2f5c44; color: #a7e0c0; }
:root[data-theme="dark"] .alert-warn  { background: #3a3018; border-color: #6a5a2a; color: #e6cf97; }
:root[data-theme="dark"] mark { background: #6a5410; color: #ffe9a8; }
:root[data-theme="dark"] .btn:hover { background: #262f2a; }
:root[data-theme="dark"] tr:hover td { background: #212b26; }
:root[data-theme="dark"] .kanban-card { background: #212b26; }
:root[data-theme="dark"] .board-col { background: #161d19; }
html, body { margin: 0; padding: 0; }
body {
  font: 500 15px/1.5 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
h1, h2, h3, .num, .brand-name { font-weight: 700; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--sidebar); color: #cbd6e2;
  display: flex; flex-direction: column;
  padding: 18px 0;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 2px 18px 16px; color: #fff;
}
.brand img { width: 26px; height: 29px; }
.brand-name { font-size: 21px; font-weight: 700; letter-spacing: .2px; }
.brand:hover { text-decoration: none; color: #fff; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; }
.auth-brand img { width: 30px; height: 33px; }
.auth-brand .brand-name { font-size: 24px; color: var(--ink); }
.sidebar nav { flex: 1; display: flex; flex-direction: column; }
.sidebar nav a {
  color: #cbd6e2; padding: 10px 20px; display: block;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: var(--primary-ink); font-weight: 700; }
.sidebar nav .nav-group {
  color: #7d8fa3; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; padding: 14px 20px 4px;
}

/* Barras de disponibilidad (uptime): verde día limpio, rojo día con caídas,
   gris sin datos. Altura = % del día. Colores validados para daltonismo. */
:root { --up-ok: #2ea866; --up-ko: #8f2323; }
:root[data-theme="dark"] { --up-ko: #b84848; }
.uptime-strip { display: flex; align-items: flex-end; gap: 2px; height: 28px; }
.uptime-strip .ub {
  flex: 1 1 4px; max-width: 8px; min-height: 2px;
  background: var(--up-ok); border-radius: 2px 2px 0 0;
}
.uptime-strip .ub.ko { background: var(--up-ko); }
.uptime-strip .ub.nd { background: var(--line); height: 30%; }
.sidebar-footer { padding: 14px 20px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.sidebar-footer a { color: #cbd6e2; display: block; margin-bottom: 6px; }
.btn-link {
  background: none; border: none; color: #8fa4ba; cursor: pointer;
  padding: 0; font-size: 13px;
}
.btn-link:hover { color: #fff; }
.content { flex: 1; padding: 26px 32px; max-width: 1200px; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 8px 10px; flex-wrap: wrap; }
  .brand { padding: 0 12px 0 4px; }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a { padding: 8px 10px; }
  .sidebar nav .nav-group { display: none; } /* en móvil el menú es horizontal: sin títulos */
  .sidebar-footer { border: none; padding: 0 8px; margin-left: auto; display: flex; gap: 10px; align-items: center; }
  .sidebar-footer a { margin: 0; }
  .content { padding: 16px; }
}

/* ---- Cabeceras de página ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 22px 0 10px; }

/* ---- Tarjetas / paneles ---- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
}
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
a.stat-link { display: block; color: inherit; }
a.stat-link:hover { text-decoration: none; border-color: var(--primary); box-shadow: 0 2px 8px var(--focus); }
.delta-good { color: var(--ok); font-weight: 600; font-size: 12px; }
.delta-bad { color: var(--danger); font-weight: 600; font-size: 12px; }
.delta-neutral { color: var(--muted); font-size: 12px; }

/* ---- Tablas ---- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--panel-2); }
td.actions { white-space: nowrap; text-align: right; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-lead { background: #fff3d6; color: #8a6100; }
.badge-cliente { background: #d9f2e3; color: #146c3c; }
.badge-antiguo { background: #e8ecf1; color: #5b6b7d; }
.badge-activo { background: #d9f2e3; color: #146c3c; }
.badge-caducado { background: #fbe0e0; color: #a02c2c; }
.badge-cancelado { background: #e8ecf1; color: #5b6b7d; }
.badge-pronto { background: #fff3d6; color: #8a6100; }

/* ---- Formularios ---- */
form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=url], input[type=date], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px; font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; background: var(--input-bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.form-actions { margin-top: 8px; display: flex; gap: 10px; align-items: center; }

/* ---- Botones ---- */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--input-bg); color: var(--ink); font: inherit; cursor: pointer;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--input-bg); border-color: #e5b8b8; color: var(--danger); }
.btn-danger:hover { background: #fbeaea; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ---- Alertas ---- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-size: 14px; }
.alert-error { background: #fbeaea; border-color: #e5b8b8; color: #8f2424; }
.alert-ok { background: #e4f5eb; border-color: #b3ddc4; color: #14532d; }
.alert-warn { background: #fdf3dc; border-color: #ecd9a5; color: #7a5b05; }

/* ---- Filtros ---- */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filters label { margin: 0; min-width: 160px; flex: 0 1 auto; }
.filters .grow { flex: 1 1 220px; }

/* ---- Login ---- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar); margin: 0; font: 500 15px/1.5 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.auth-card { background: var(--panel); border-radius: 12px; padding: 32px; width: 100%; max-width: 380px; margin: 20px; }
.auth-card h1 { margin: 0 0 18px; font-size: 20px; }
.auth-card h2 { font-size: 15px; margin: 18px 0 10px; color: var(--muted); }

/* ---- Detalle ficha ---- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; }
.detail-grid dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.detail-grid dd { margin: 2px 0 8px; }
.note { border-left: 3px solid var(--line); padding: 6px 12px; margin-bottom: 10px; }
.note .meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; align-items: center; }
.note p { margin: 4px 0 0; white-space: pre-wrap; }
.muted { color: var(--muted); }
.pagination { margin-top: 14px; display: flex; gap: 6px; }
.pagination a, .pagination span { padding: 5px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--input-bg); }
.theme-toggle { background: none; border: none; color: #8fa4ba; cursor: pointer; font-size: 13px; padding: 0; }
.theme-toggle:hover { color: #fff; }
.pagination span.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.inline-form { display: inline; }

/* ---- Gastos e ingresos ---- */
.badge-ingreso { background: #dbe9fb; color: #1c5cab; }
.badge-gasto { background: #fbe0e0; color: #a02c2c; }
.importe-ingreso { color: #1c5cab; font-weight: 600; }
.importe-gasto { color: #a02c2c; font-weight: 600; }

/* ---- Gráficos SVG ---- */
.chart-svg { width: 100%; height: auto; display: block; font-family: inherit; }
.chart-legend { display: flex; gap: 16px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.legend-chip { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: #fff; font-size: 13px;
  padding: 6px 10px; border-radius: 7px; max-width: 340px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* ---- Buscador global ---- */
.sidebar-search { padding: 0 14px 14px; }
.sidebar-search input {
  width: 100%; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.08);
  color: #fff; border-radius: 7px; padding: 7px 10px; font: inherit; font-size: 13px;
}
.sidebar-search input::placeholder { color: #8fa4ba; }
.sidebar-search input:focus { outline: 2px solid var(--focus); background: rgba(255,255,255,.14); }
mark { background: #ffe9a8; border-radius: 3px; padding: 0 2px; }

/* ---- Etiquetas ---- */
.tags-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.tag a { color: inherit; }
.tag a:hover { text-decoration: none; }
.tag-sm { padding: 1px 7px; font-size: 11px; }
.tag-x { background: none; border: none; cursor: pointer; color: inherit; opacity: .6; font-size: 13px; padding: 0; line-height: 1; }
.tag-x:hover { opacity: 1; }
.tag-add-form input {
  border: 1px dashed var(--line); background: transparent; border-radius: 20px;
  padding: 2px 10px; font-size: 12px; width: 110px;
}
.tag-add-form input:focus { background: var(--input-bg); outline: 1px solid var(--primary); }
.tag-c0 { background: #dbe9fb; color: #1c5cab; }
.tag-c1 { background: #d9f2e3; color: #146c3c; }
.tag-c2 { background: #fff3d6; color: #8a6100; }
.tag-c3 { background: #f3e3f5; color: #7b3a85; }
.tag-c4 { background: #fbe0e0; color: #a02c2c; }
.tag-c5 { background: #dcf1f3; color: #14606b; }
.tag-c6 { background: #ffe6d6; color: #97481a; }
.tag-c7 { background: #e8ecf1; color: #45566a; }

/* ---- Tablero kanban (proyectos) ---- */
.board {
  display: flex; gap: 14px; align-items: flex-start;
  overflow-x: auto; padding-bottom: 12px; margin-bottom: 8px;
}
.board-col {
  width: 272px; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px;
}
.board-col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; padding: 0 2px; }
.board-cards { min-height: 24px; display: flex; flex-direction: column; gap: 8px; }
.board-col.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; }
.kanban-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.kanban-card.dragging { opacity: .45; }
.kanban-card a { color: var(--ink); font-weight: 600; }
.card-desc { font-size: 12px; margin-top: 3px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 11px; }
.card-tags .assignee { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 1px 8px; color: var(--muted); }
.card-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; min-height: 18px; }
.card-arrows { margin-left: auto; display: flex; gap: 4px; }
.btn-mini {
  background: none; border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 7px; font-size: 11px; cursor: pointer; color: var(--muted);
}
.btn-mini:hover { background: #f0f3f7; color: var(--ink); }
.board-add input {
  width: 100%; margin-top: 8px; border: 1px dashed var(--line); background: transparent;
  border-radius: 7px; padding: 7px 10px; font: inherit; font-size: 13px;
}
.board-add input:focus { background: var(--input-bg); outline: 2px solid var(--focus); }
.board-col-foot { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.col-rename {
  border: none; background: transparent; font: inherit; font-size: 12px; color: var(--muted);
  padding: 2px 4px; border-radius: 4px; width: 100%;
}
.col-rename:focus { background: var(--input-bg); outline: 1px solid var(--line); }
.board-col-new { background: transparent; border: 1px dashed var(--line); }
.board-col-new input { width: 100%; border: none; background: transparent; font: inherit; padding: 6px; }
.progress { background: #e8ecf1; border-radius: 6px; height: 8px; width: 130px; overflow: hidden; margin-bottom: 3px; }
.progress-fill { background: var(--ok); height: 100%; border-radius: 6px; }

/* ---- Portal del cliente ---- */
.portal-body { background: var(--bg); }
.portal-topbar { background: var(--sidebar); }
.portal-topbar-inner {
  max-width: 960px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.portal-brand { color: #fff; font-weight: 700; font-size: 17px; }
.portal-nav { display: flex; gap: 18px; align-items: center; }
.portal-nav a { color: #cbd6e2; font-size: 14px; }
.portal-nav a:hover { color: #fff; text-decoration: none; }
.portal-main { max-width: 960px; margin: 0 auto; padding: 26px 20px 60px; }
.portal-main h1 { font-size: 22px; margin: 0 0 4px; }
