:root {
  --ink: #172033;
  --muted: #667085;
  --line: #d7dee8;
  --soft: #f4f6f8;
  --panel: #fff;
  --primary: #164160;
  --primary-2: #0f2f46;
  --accent: #d69d28;
  --accent-soft: #fff5dc;
  --dark: #111827;
  --ok: #027a48;
  --warn: #b54708;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(16, 24, 40, .07);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #f7f8fa;
  color: var(--ink);
}
a { text-decoration: none; color: inherit; }
main { min-height: 78vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: .9rem clamp(1rem, 5vw, 4rem);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar div { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 900; letter-spacing: .01em; color: var(--primary-2); }

.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  padding: .72rem 1rem;
  font-weight: 800;
  cursor: pointer;
  min-height: 42px;
}
.button:hover, button:hover { filter: brightness(.96); }
.button.dark { background: var(--dark); }
.button.outline {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.container { width: min(1220px, 92vw); margin: auto; }
.hero {
  position: relative;
  border-bottom: 1px solid var(--line);
  padding: 4.7rem 0 4.1rem;
  background:
    linear-gradient(135deg, rgba(22,65,96,.94), rgba(15,47,70,.88)),
    linear-gradient(90deg, #164160, #0f2f46);
  color: #fff;
}
.hero .lead { color: #dbe7ef; }
.hero .panel { color: var(--ink); }
.hero .eyebrow { color: #ffd36f; }

.grid { display: grid; gap: 1.15rem; }
.two { grid-template-columns: 1.15fr .85fr; }
.three { grid-template-columns: repeat(3, 1fr); }
.four { grid-template-columns: repeat(4, 1fr); }

.card, .panel, .auth, .stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.card { transition: transform .18s ease, box-shadow .18s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 18px 42px rgba(16,24,40,.1); }
.section { padding: 3.2rem 0; }
.soft { background: var(--soft); border-block: 1px solid var(--line); }

h1 { font-size: clamp(2.1rem, 4.8vw, 4rem); margin: .35rem 0; line-height: 1.02; }
h2 { font-size: clamp(1.35rem, 2.6vw, 2rem); margin: .2rem 0 1rem; }
h3 { margin-top: 0; }
.lead { font-size: 1.12rem; color: var(--muted); line-height: 1.65; }
.muted { color: var(--muted); }
.eyebrow {
  color: var(--accent);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.price { font-size: 1.35rem; font-weight: 900; margin: .8rem 0; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .72rem;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; }
label { display: block; font-weight: 800; margin: .8rem 0 .35rem; }
.auth { width: min(470px, 92vw); margin: 3rem auto; }
.row-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

.dash-title {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin: 1.8rem 0;
}
.tabs { display: flex; gap: .5rem; flex-wrap: wrap; }
.tabs a {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: #fff;
  border-radius: 7px;
  padding: .55rem .8rem;
  font-weight: 800;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td {
  text-align: left;
  padding: .78rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: #fafcff; }

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: .28rem .65rem;
  font-size: .74rem;
  font-weight: 900;
  text-transform: uppercase;
}
.active, .Activo, .Terminada, .Aprobada, .Cerrada, .Contratado { color: var(--ok); background: #ecfdf3; }
.suspended, .expired, .Vencida, .Abierta, .Rechazada { color: var(--danger); background: #fef3f2; }
.pending_payment, .Pendiente, .Solicitada, .En.seguimiento, .En.revision { color: var(--warn); background: #fffaeb; }

.flash {
  width: min(1220px,92vw);
  margin: 1rem auto 0;
  background: var(--accent-soft);
  border: 1px solid #fed7aa;
  color: #8a4a06;
  padding: .9rem;
  border-radius: 8px;
}
.empty {
  width: min(900px,92vw);
  margin: 3rem auto;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}
footer {
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 1.3rem clamp(1rem,5vw,4rem);
  font-size: .9rem;
}

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: #0f2f46;
  color: #e5e7eb;
  padding: 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar h2 { font-size: 1.08rem; color: #fff; }
.sidebar a {
  display: block;
  padding: .72rem .8rem;
  border-radius: 7px;
  margin: .18rem 0;
  color: #dbe7ef;
}
.sidebar a:hover, .sidebar a.active-link { background: rgba(255,255,255,.11); color: #fff; }
.app-main { padding: 1.5rem clamp(1rem,4vw,2.2rem); }
.metric { border-left: 4px solid var(--accent); }
.mini-form { display: grid; grid-template-columns: repeat(3,1fr); gap: .75rem; align-items: end; }
.span-all { grid-column: 1 / -1; }

.risk-ok { border-left: 4px solid var(--ok); }
.risk-warn { border-left: 4px solid var(--warn); }
.risk-danger { border-left: 4px solid var(--danger); }

.assistant-layout { grid-template-columns: 280px 1fr; align-items: start; }
.assistant-history a {
  display: block;
  padding: .7rem .75rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  margin-bottom: .45rem;
  color: var(--primary);
  font-weight: 800;
}
.assistant-history a.active-link { background: var(--primary); color: #fff; }
.chat-panel { padding: 0; overflow: hidden; }
.chat-panel > .row-actions { padding: 1rem 1rem 0; }
.chat-box {
  display: flex;
  flex-direction: column;
  gap: .8rem;
  min-height: 360px;
  max-height: 620px;
  overflow-y: auto;
  padding: 1rem;
  background: #f8fafc;
  border-block: 1px solid var(--line);
  margin-block: 1rem;
}
.chat-message {
  width: min(820px, 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .9rem;
  background: #fff;
  box-shadow: 0 10px 24px rgba(16,24,40,.05);
}
.chat-message.user {
  align-self: flex-end;
  background: #eaf3f8;
  border-color: #c7ddea;
}
.chat-message.assistant { align-self: flex-start; }
.chat-message > span {
  display: block;
  font-size: .75rem;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: .35rem;
  text-transform: uppercase;
}
.chat-message p { margin: .35rem 0; line-height: 1.55; }
.chat-message table { min-width: 0; margin: .6rem 0; background: #fff; }
.chat-form { padding: 0 1rem 1rem; }
.sources {
  margin-top: .75rem;
  padding-top: .7rem;
  border-top: 1px solid var(--line);
  font-size: .9rem;
}

@media (max-width: 960px) {
  .two, .three, .four, .mini-form, .assistant-layout { grid-template-columns: 1fr; }
  .dash-title, .topbar { align-items: stretch; flex-direction: column; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: relative; }
  .app-main { padding: 1rem; }
  table { min-width: 640px; }
}
