:root {
  --bg: #f5f6f8;
  --text: #323338;
  --muted: #676879;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --outline: #d0d4e4;
  --primary: #0073ea;
  --primary-2: #0073ea;
  --glass: #ffffff;
  --line: #e6e9ef;
  --ok: #00c875;
  --danger: #e2445c;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.03em; color: var(--text); }
h2 { margin: 0 0 12px; font-size: 13px; font-weight: 700; }
h3 { margin: 16px 0 8px; font-size: 15px; color: var(--text); }

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
}

.hint, .picked, .who { color: var(--muted); }
.hint { margin: 8px 0 0; font-size: 13px; line-height: 1.45; }
.who { margin: 6px 0 0; }
.error { color: var(--danger); margin: 0; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: #f5f6f8 center / cover no-repeat;
}
.avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 8px;
  display: block;
}
.avatar-letters {
  display: grid;
  place-items: center;
  background: #0073ea;
  color: #fff;
  font-size: 28px;
  font-weight: 700;
}
#lock-form { text-align: center; }
#lock-view.has-photo #lock-form {
  background: rgba(255, 255, 255, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.62);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
#lock-view.has-photo #lock-form h1,
#lock-view.has-photo #lock-form .hint,
#lock-view.has-photo #lock-form label,
#lock-view.has-photo #lock-form .support-line,
#lock-view.has-photo #lock-form .support-mail {
  color: #1c2430;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.login-view[hidden],
.app-view[hidden] { display: none !important; }

.brand-mark { width: 56px; height: 56px; object-fit: contain; display: block; margin: 0 auto 8px; }
.brand-line { display: flex; align-items: center; gap: 12px; }
.brand-line .brand-mark { width: 42px; height: 42px; margin: 0; }
.brand-name {
  font-family: Itim, cursive;
  color: #2155CD;
  font-size: 42px;
  font-weight: 400;
  line-height: 1;
  margin: 0;
  text-align: center;
}
.brand-name span { color: #2563eb; }
.brand-name-small { font-size: 28px; text-align: left; }
#lock-form .brand-name-small { text-align: center; }
.brand-line .brand-name-small { text-align: left; }
.login-kicker {
  margin: 8px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
}
.login-title {
  font-family: Inter, "Segoe UI", sans-serif;
  color: #1e293b;
  font-size: 18px;
  font-weight: 650;
  margin: 22px 0 0;
  text-align: left;
}
.login-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.support-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
}
.support-line a { color: #9a5b12; font-weight: 650; text-decoration: none; }
.support-line a:hover { text-decoration: underline; }
.support-mail {
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  user-select: text;
}
.support-line .support-copy {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
}
.app-view > .support-line { flex: none; margin: -6px 0 8px; }
.login-split {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(340px, 460px);
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(33, 85, 205, 0.12);
}
.login-brand {
  background: #2155CD;
  display: grid;
  place-items: center;
  padding: 28px;
}
.login-brand img { width: 100%; height: 100%; max-height: 520px; object-fit: contain; display: block; }
#login-form.login-card {
  width: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 40px 36px;
  align-content: center;
}
#login-form .brand-mark { margin-bottom: 12px; }
#login-form button[type="submit"] {
  width: 100%;
  height: 44px;
  margin-top: 6px;
  background: #2155CD;
  border-radius: 10px;
}
#login-form button[type="submit"]:hover { background: #1b46ab; }
#login-view { background: #e8eef8; }

.login-card, dialog {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(50, 51, 56, 0.12);
  gap: 0.8rem;
  color: var(--text);
}

.login-card { display: grid; }

dialog:not([open]) { display: none; }
dialog[open] {
  display: block;
  max-height: calc(100vh - 32px);
  overflow: auto;
}
#create-dialog { width: min(560px, calc(100% - 2rem)); }
#detail-dialog, #history-dialog, #alerts-dialog, #team-dialog { width: min(860px, calc(100% - 2rem)); }
.extra-box {
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 12px;
  background: #f6f7fb;
}
.extra-box h3 { margin-top: 0; }
dialog::backdrop { background: rgba(50, 51, 56, 0.35); }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--outline);
  background: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(0, 115, 234, 0.25);
  border-color: var(--primary);
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: #0060c2; }

button.ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--outline);
}

button.ghost:hover { background: #f5f6f8; }

button.danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #f4c3cb;
}

button.danger:hover { background: #fff5f6; }

.app-view { min-height: 100vh; padding: 20px 20px 16px; }

.app-view:not([hidden]) {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body:has(#app-view:not([hidden])) { overflow: hidden; }

.top, .toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  flex: none;
  margin-bottom: 18px;
}

.toolbar-actions {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.toolbar-actions label { min-width: 190px; }

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
}

.column {
  background: #f0f1f5;
  border-radius: 10px;
  min-height: 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px 8px 8px;
  overflow: hidden;
}

.column-cards {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.column h2 {
  display: inline-block;
  flex: none;
  margin: 0 0 12px;
  padding: 5px 10px;
  border-radius: 4px;
  color: #fff;
  font-size: 13px;
  line-height: 1.3;
}

.column[data-stage="nuevo"] h2 { background: #c4c4c4; color: #323338; }
.column[data-stage="contactado"] h2 { background: #fdab3d; }
.column[data-stage="cotizado"] h2 { background: #579bfc; }
.column[data-stage="ganado"] h2 { background: #00c875; }
.column[data-stage="perdido"] h2 { background: #e2445c; }

.card, .result, .plain li, .sale {
  background: #fff;
  border: 1px solid #e6e9ef;
  border-radius: 8px;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(50, 51, 56, 0.06);
}

.card { padding: 12px; margin-bottom: 8px; cursor: grab; }
.card strong, .card span { display: block; }
.card strong { color: #323338; font-weight: 700; font-size: 14px; }
.card span, .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

.results { display: grid; gap: 8px; max-height: 180px; overflow: auto; }
.result { text-align: left; padding: 10px 12px; cursor: pointer; }
.result:hover { border-color: var(--primary); }

.row-actions, .search-row, .split {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.split { display: grid; grid-template-columns: 1fr 1fr 1fr; width: 100%; }
.search-row input { flex: 1; }
.fields { display: grid; gap: 8px; margin-bottom: 8px; }
.detail-head, .header-actions { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.detail-head h2 { margin: 0; font-size: 22px; line-height: 1.25; color: var(--text); }
.sheet-sale > label { margin-bottom: 10px; }
.check-line { flex-direction: row; align-items: center; gap: 8px; margin: 0; color: var(--text); font-size: 14px; }
.check-line input { width: auto; }
#quote-message { min-height: 220px; }
.header-actions { justify-content: flex-end; }
.icon-button { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 42px; }
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
}
.price-input { width: 120px; }
.item-edit {
  display: grid;
  grid-template-columns: 100px 130px minmax(140px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  margin-top: 8px;
}
.item-edit label { min-width: 0; }
.item-edit button { margin-bottom: 0; }
.plain { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.plain li, .sale { padding: 12px; }
.line { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.change { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: pre-wrap; }

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 4px;
}
.fact {
  background: #f6f7fb;
  border-radius: 8px;
  padding: 10px 12px;
}
.fact span { display: block; color: var(--muted); font-size: 12px; }
.fact strong { display: block; margin-top: 2px; color: var(--text); font-size: 15px; }
.fact.missing strong { color: var(--muted); font-weight: 600; }
#metrics-dialog { width: min(980px, calc(100vw - 32px)); }
.metrics-table-wrap { overflow: auto; margin-top: 8px; }
#metrics-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#metrics-table th, #metrics-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
#metrics-table th:first-child, #metrics-table td:first-child { text-align: left; }
#metrics-table th { color: var(--muted); font-size: 12px; font-weight: 650; }
#metrics-table .seller-mail { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.sheet {
  margin-top: 12px;
  padding: 12px 14px 14px;
  border-radius: 10px;
  background: #f6f7fb;
}
.sheet > h3, .sheet .detail-head h3 { margin-top: 0; }
.sheet-client { background: var(--sheet-client-bg, #e7f3ff); }
.sheet-client h3 { color: var(--sheet-client-ink, #0073ea); }
.sheet-sale { background: var(--sheet-sale-bg, #e5f8ee); }
.sheet-sale h3 { color: var(--sheet-sale-ink, #00854d); }
.sheet-renew { background: var(--sheet-renew-bg, #fff1d6); }
.sheet-renew h3 { color: var(--sheet-renew-ink, #b86e00); }
.sheet-extra { background: var(--sheet-extra-bg, #f3e8ff); }
.sheet-extra h3 { color: var(--sheet-extra-ink, #7e3fb0); }
.sheet-products { background: var(--sheet-products-bg, #e5f7f6); }
.sheet-products h3 { color: var(--sheet-products-ink, #0d7a78); }
.sheet-follow { background: var(--sheet-follow-bg, #ffe8ef); }
.sheet-follow h3 { color: var(--sheet-follow-ink, #c22b4a); }
.color-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.color-picks { display: flex; gap: 14px; align-items: center; }
.color-picks label { align-items: center; }
.color-row input[type="color"] { width: 52px; height: 36px; padding: 2px; }
.stage-chip {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 4px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.stage-chip[data-stage="nuevo"] { background: #c4c4c4; color: #323338; }
.stage-chip[data-stage="contactado"] { background: #fdab3d; }
.stage-chip[data-stage="cotizado"] { background: #579bfc; }
.stage-chip[data-stage="ganado"] { background: #00c875; }
.stage-chip[data-stage="perdido"] { background: #e2445c; }

@media (max-width: 900px) {
  .split, .facts, .login-split, .item-edit { grid-template-columns: 1fr; }
  .login-brand { min-height: 180px; padding: 16px; }
  .login-brand img { max-height: 180px; }
  #login-form.login-card { padding: 28px 22px; }
  .brand-name { font-size: 34px; }
  .top, .toolbar { flex-direction: column; align-items: flex-start; }
  h1 { font-size: 24px; }
}
