:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #ece8df;
  --surface-3: #e2ddd0;
  --border: #d9d4c7;
  --text: #201f1c;
  --text-muted: #6b675e;
  --accent: #2f7a5f;
  --accent-warn: #b5720a;
  --danger: #a14848;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --font-sans: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #141319;
    --surface: #1c1b24;
    --surface-2: #24232e;
    --surface-3: #2c2b38;
    --border: #35333f;
    --text: #eeece6;
    --text-muted: #9c99a8;
    --accent: #59bd9a;
    --accent-warn: #e8a13c;
    --danger: #d97c7c;
  }
}

:root[data-theme='dark'] {
  --bg: #141319;
  --surface: #1c1b24;
  --surface-2: #24232e;
  --surface-3: #2c2b38;
  --border: #35333f;
  --text: #eeece6;
  --text-muted: #9c99a8;
  --accent: #59bd9a;
  --accent-warn: #e8a13c;
  --danger: #d97c7c;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
}

a { color: inherit; }

button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }

.drawer-root { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 9, 6, 0.45); }

.drawer-panel {
  position: relative;
  z-index: 1;
  width: min(280px, 80vw);
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.drawer-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 0.6rem;
}

.drawer-link {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
  padding: 0.65rem 0.6rem;
  border-radius: 8px;
}
.drawer-link:hover { background: var(--surface-2); }

.user-label { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }

/* Buttons and inputs */

.btn {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}

.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #06120d; }
.btn-primary:hover { transform: translateY(-1px); }

.btn-ghost { background: transparent; }

.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--surface); }

.btn-small { padding: 0.35rem 0.65rem; font-size: 0.7rem; }

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; }
.field span { font-family: var(--font-mono); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

input[type='text'], input[type='password'], input[type='number'], input[type='date'], textarea, select {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; font-family: var(--font-sans); }

/* Login */

.view-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; }

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem 1.75rem;
}

.login-card h1 { font-family: var(--font-mono); font-size: 1.4rem; margin: 0 0 1.25rem; }

.form-error { color: var(--danger); font-size: 0.8125rem; margin: -0.4rem 0 0.9rem; }

/* Shared page shell */

main#app { max-width: 1280px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

h1 { font-family: var(--font-mono); font-size: clamp(1.5rem, 2.4vw, 1.9rem); font-weight: 600; letter-spacing: -0.01em; margin: 0; text-wrap: balance; }
h2 { font-family: var(--font-mono); font-size: 0.95rem; font-weight: 600; margin: 0; }

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}

.view-header-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.back-link { display: inline-block; font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); text-decoration: none; margin-bottom: 0.5rem; }
.back-link:hover { color: var(--text); }

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
}
.empty-state-small { padding: 0.9rem; font-size: 0.8rem; }

.scroll-hint { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); margin: 0 0 0.75rem; }

/* Board (Kanban) */

.board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }

.board-column {
  flex: 0 0 auto;
  width: 260px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
}

.board-column-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.board-column-count {
  font-family: var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.7rem;
}

.board-column-cards { display: flex; flex-direction: column; gap: 0.6rem; }

.deal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 0.85rem 0.85rem 0.75rem;
}

.deal-card-link { display: block; text-decoration: none; color: inherit; padding-top: 1.4rem; }

.deal-card-empresa { font-family: var(--font-mono); font-weight: 600; font-size: 0.9rem; margin: 0 0 0.25rem; }
.deal-card-meta { font-size: 0.75rem; color: var(--text-muted); margin: 0 0 0.15rem; }

.deal-card-audit {
  display: inline-block;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}

.deal-card-toolbar {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  gap: 0.25rem;
}

/* Deal detail */

.deal-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.deal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.2rem;
}

.deal-panel-wide { grid-column: 1 / -1; }

.deal-panel h2 { margin-bottom: 0.9rem; }

.deal-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.deal-panel-header h2 { margin-bottom: 0; }

.contact-facts { margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.contact-facts > div { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.85rem; }
.contact-facts dt { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
.contact-facts dd { margin: 0; text-align: right; }

.deal-notes { font-size: 0.85rem; color: var(--text-muted); margin: 0.6rem 0 0; }

/* Timeline */

.timeline { display: flex; flex-direction: column; gap: 0.75rem; }

.timeline-item {
  border-left: 2px solid var(--border);
  padding-left: 0.9rem;
}

.timeline-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-right: 0.5rem;
}

.timeline-date { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); }
.timeline-desc { margin: 0.3rem 0 0; font-size: 0.85rem; line-height: 1.5; }

/* Tasks */

.task-list { display: flex; flex-direction: column; gap: 0.5rem; }

.task-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

.task-row-done .task-title { text-decoration: line-through; color: var(--text-muted); }

.task-title { flex: 1; font-size: 0.85rem; }
.task-due { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); }

/* Dashboard */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}

.stat-tile-value { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 600; margin: 0; }
.stat-tile-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0.3rem 0 0; }

.stat-big { font-family: var(--font-mono); font-size: 2rem; font-weight: 600; margin: 0.4rem 0; color: var(--accent); }

.origen-list { display: flex; flex-direction: column; gap: 0.4rem; }

.origen-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

.origen-row-link { text-decoration: none; color: inherit; }
.origen-row-link:hover { background: var(--surface-3); }

/* Modal */

.modal-root { position: fixed; inset: 0; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 9, 6, 0.45); }

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(440px, calc(100vw - 2.5rem));
  margin: 8vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.6rem 1.6rem 1.4rem;
  max-height: 82vh;
  overflow-y: auto;
}

.modal-panel h2 { font-size: 1.1rem; margin: 0 0 1.1rem; }
.modal-fields { display: flex; flex-direction: column; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.4rem; }

.modal-confirm p { margin: 0 0 1.2rem; font-size: 0.9rem; line-height: 1.5; }
