:root {
  --bg: #eaf3ff;
  --surface: #ffffff;
  --surface2: #eef6ff;
  --text: #162033;
  --muted: #607086;
  --accent: #0b73d9;
  --accent2: #13a66b;
  --danger: #c9354a;
  --warn: #b07700;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    linear-gradient(135deg, rgba(8, 95, 174, .96) 0%, rgba(15, 130, 219, .88) 38%, rgba(234, 243, 255, 1) 38.2%, rgba(234, 243, 255, 1) 100%);
  color: var(--text);
}

.topbar {
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid rgba(11, 115, 217, .16);
  box-shadow: 0 6px 22px rgba(18, 62, 112, .08);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.brand:hover { color: var(--accent); }

.user-chip {
  margin-left: auto;
  font-size: 0.85rem;
  color: #31516f;
  padding: 0.35rem 0.75rem;
  background: #e8f2ff;
  border-radius: 999px;
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(11, 115, 217, .13);
  padding: 1.35rem 1.5rem;
  box-shadow: 0 16px 36px rgba(18, 62, 112, .12);
}

.card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.grid-filters {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  margin-bottom: 1rem;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input, select, textarea {
  font: inherit;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #bfd5ec;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 4rem;
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid #bdd6ef;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  font-size: 0.9rem;
}

.tab:hover { color: var(--text); border-color: #7eb4e8; }

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
}

.btn-primary {
  background: linear-gradient(135deg, #075fb5, #1687e3);
  color: #fff;
  box-shadow: 0 10px 22px rgba(11, 115, 217, .22);
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-secondary {
  background: #eef6ff;
  color: var(--text);
  border: 1px solid #bdd6ef;
}

.btn-ghost {
  background: #f4f9ff;
  color: #31516f;
  border: 1px solid #cfe0f1;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.btn-ghost:hover { color: var(--text); }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-warn {
  background: #fff5d9;
  border: 1px solid #f2d282;
  color: #5d4300;
}

.alert-error {
  background: #ffe8ec;
  border: 1px solid #f0a7b2;
  color: #7d1020;
}

.alert-ok {
  background: #e6f8ef;
  border: 1px solid #a9dfc2;
  color: #125b3b;
}

.servicio-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.servicio-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem 1.25rem;
  font-size: 0.9rem;
}

.meta-k {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.meta-v { color: var(--text); }

.meta-v.multiline {
  white-space: pre-wrap;
  line-height: 1.45;
}

.form-nueva-os {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 0.5rem;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.cell-clip {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid #d5e4f4;
  background: #fff;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data thead {
  position: sticky;
  top: 0;
  background: #eaf4ff;
  z-index: 1;
}

table.data th, table.data td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #e3edf7;
}

table.data tbody tr:hover {
  background: #f4f9ff;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.pill-urgent { background: rgba(255, 107, 122, .2); color: #ffb3bc; }
.pill-warn { background: rgba(245, 197, 66, .18); color: #ffe08a; }
.pill-ok { background: rgba(90, 228, 168, .15); color: #9cf5d1; }
.pill-neutral { background: rgba(139, 156, 179, .2); color: var(--muted); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-panel {
  max-width: 520px;
  margin: 4.5rem auto;
}

.login-card {
  background: #fff;
  border: 1px solid rgba(11, 115, 217, .14);
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(19, 69, 126, .22);
  padding: 1.75rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.login-brand img {
  width: 78px;
  height: 78px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  padding: 0.35rem;
  border: 1px solid #d9e7f5;
}

.login-brand h1 {
  margin: 0 0 0.2rem;
  font-size: 1.45rem;
  line-height: 1.1;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.login-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.mode-option {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-height: 74px;
  border-radius: 8px;
  border: 1px solid #c7daef;
  background: #f6fbff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 0.75rem;
  font: inherit;
}

.mode-option span {
  font-weight: 700;
}

.mode-option small {
  color: var(--muted);
  line-height: 1.25;
}

.mode-option:hover,
.mode-option.active {
  border-color: #0b73d9;
  background: #e6f2ff;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-hint {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 1rem;
}

.admin-details {
  margin-top: 1.25rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.admin-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  list-style: none;
}

.admin-details summary::-webkit-details-marker { display: none; }

.admin-details[open] summary {
  margin-bottom: 0.65rem;
}

.admin-details p {
  margin: 0;
  padding: 0.75rem 1rem;
  background: #f7fbff;
  border-radius: 8px;
  border: 1px solid #d8e7f6;
}

.admin-details code {
  font-size: 0.9em;
  color: var(--accent);
}

.dash-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.dash-kpi {
  background: var(--surface);
  border: 1px solid #d5e4f4;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.dash-kpi-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.dash-kpi-val {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.dash-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.dash-charts .card {
  min-height: 280px;
}

.dash-charts canvas {
  max-height: 260px;
}

.text-muted {
  color: var(--muted);
}

@media (max-width: 900px) {
  .dash-charts { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .user-chip { display: none; }
  .login-panel { margin: 1.5rem auto; }
  .login-card { padding: 1rem; }
  .login-brand { align-items: flex-start; }
  .login-brand img { width: 58px; height: 58px; }
  .login-mode-grid { grid-template-columns: 1fr; }
}

/* ==================== Sprint 10 — Autocomplete cliente / proveedor ==================== */
.ac-wrap { position: relative; }
.ac-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.10);
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
}
.ac-row {
  padding: .5rem .65rem;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
}
.ac-row:last-child { border-bottom: none; }
.ac-row:hover, .ac-row-active { background: #eff6ff; }
.ac-row-main { font-weight: 600; color: #111827; }
.ac-row-sub { font-size: .78rem; color: #6b7280; margin-top: .1rem; }
.ac-empty { padding: .65rem; color: #9ca3af; font-size: .9rem; text-align: center; }

/* ==================== Sprint 10 — Responsive mobile ==================== */
.topbar-inner { flex-wrap: wrap; row-gap: .35rem; }

.table-wrap, .card > table, .card > .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; min-width: 600px; }

@media (max-width: 900px) {
  .topbar-inner { padding: .65rem .75rem; gap: .35rem; }
  .topbar-inner .btn-ghost { padding: .35rem .55rem; font-size: .82rem; }
  .topbar-inner .brand { font-size: 1rem; }
  .shell { padding: .75rem; }
  .card { padding: .75rem; }
  .servicio-header { flex-direction: column; align-items: stretch; gap: .5rem; }
  .servicio-actions { flex-wrap: wrap; }
  .detail-grid { grid-template-columns: 1fr; }
  .grid-2col { grid-template-columns: 1fr !important; }
  table.data { font-size: .85rem; }
  .form-nueva-os .dia-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar-inner { padding: .5rem .5rem; }
  .topbar-inner .user-chip { display: none; }
  .topbar-inner .brand { font-size: .95rem; }
  .topbar-inner .btn-ghost { padding: .3rem .45rem; font-size: .78rem; }
  .shell { padding: .5rem; }
  .card { padding: .6rem; border-radius: 8px; }
  h1 { font-size: 1.2rem; }
  h2 { font-size: 1.05rem; }
  .form-nueva-os .dia-grid { grid-template-columns: 1fr; }
  .chat-card-libre { height: auto; min-height: 60vh; }
  .chat-msg { max-width: 90%; }
  .btn { padding: .5rem .75rem; font-size: .9rem; }
  /* Forms con flex que arman renglones — que rompan a 1 col */
  form[method=post] > div[style*='display:flex'][style*='gap'] { flex-wrap: wrap; }
}

/* ==================== Sprint 13 — Formato WhatsApp en mensajes ==================== */
.msg-hint {
  font-size: .72rem;
  color: #9ca3af;
  display: block;
  margin-top: -.25rem;
  line-height: 1.4;
}
.msg-hint strong, .msg-hint em, .msg-hint del, .msg-hint code {
  color: #6b7280;
  font-weight: inherit;
}
.msg-hint strong { font-weight: 700; color: #374151; }
.msg-hint code {
  background: #f3f4f6;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: .9em;
}

/* Estilos del contenido formateado en burbujas de chat / notas */
.msg-text strong { font-weight: 700; }
.msg-text em     { font-style: italic; }
.msg-text del    { text-decoration: line-through; opacity: .75; }
.msg-text code {
  background: rgba(0,0,0,.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
}
.msg-text a {
  color: #1d4ed8;
  text-decoration: underline;
  word-break: break-all;
}
.nota-texto strong { font-weight: 700; }
.nota-texto em     { font-style: italic; }
.nota-texto del    { text-decoration: line-through; opacity: .75; }
.nota-texto code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
}
