:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #dfe5e2;
  --text: #0a0a0a;
  --text-2: #3f4642;
  --muted: #7a827e;
  --accent: #047857;          /* esmeralda para links, foco y acentos */
  --accent-soft: rgba(4, 120, 87, .10);
  --primary-bg: #035c40;      /* botón principal */
  --primary-fg: #ffffff;
  --pos: #047857;
  --pos-soft: rgba(4, 120, 87, .11);
  --neg: #c62828;
  --neg-soft: rgba(198, 40, 40, .10);
  --warn: #b77a00;
  --grid: rgba(0, 0, 0, .06);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --brand: #023a24;           /* verde del logo */
  --brand-2: #012a1a;
  --on-brand: #ffffff;
  --on-brand-2: rgba(255,255,255,.72);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0b0f0d;
  --surface-2: #131a17;
  --border: #1f2925;
  --text: #f4f7f5;
  --text-2: #c3cbc7;
  --muted: #7f8984;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, .14);
  --primary-bg: #10b981;
  --primary-fg: #02150d;
  --pos: #34d399;
  --pos-soft: rgba(52, 211, 153, .13);
  --neg: #f87171;
  --neg-soft: rgba(248, 113, 113, .13);
  --warn: #e5a82a;
  --grid: rgba(255, 255, 255, .06);
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
  --brand: #022e1d;
  --brand-2: #011a10;
  --on-brand: #ffffff;
  --on-brand-2: rgba(255,255,255,.68);
  --radius: 12px;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0b0f0d;
  --surface-2: #131a17;
  --border: #1f2925;
  --text: #f4f7f5;
  --text-2: #c3cbc7;
  --muted: #7f8984;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, .14);
  --primary-bg: #10b981;
  --primary-fg: #02150d;
  --pos: #34d399;
  --pos-soft: rgba(52, 211, 153, .13);
  --neg: #f87171;
  --neg-soft: rgba(248, 113, 113, .13);
  --warn: #e5a82a;
  --grid: rgba(255, 255, 255, .06);
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
  --brand: #022e1d;
  --brand-2: #011a10;
  --on-brand: #ffffff;
  --on-brand-2: rgba(255,255,255,.68);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-2); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12.5px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--brand), var(--brand-2)); color: var(--on-brand); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 24px; color: inherit; }
.brand .mark { width: 30px; height: 40px; color: #fff; flex: none; }
.brand .word { display: flex; flex-direction: column; line-height: 1.1; }
.brand .word b { font-weight: 800; font-size: 14px; letter-spacing: .05em; white-space: nowrap; }
.brand .word small { font-size: 10px; letter-spacing: .16em; white-space: nowrap; text-transform: uppercase; opacity: .7; font-weight: 600; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--on-brand-2); font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.nav a:hover { background: rgba(255,255,255,.07); color: var(--on-brand); }
.nav a.active { background: rgba(255,255,255,.13); color: var(--on-brand); box-shadow: inset 3px 0 0 #34d399; }
.badge {
  margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700;
  background: #fff; color: var(--brand); border-radius: 99px; padding: 1px 7px;
}
.sidebar-foot { margin-top: auto; padding: 0 4px; }
.main { min-width: 0; padding: 0 28px 48px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 0 14px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 18px; }
.view { display: flex; flex-direction: column; gap: 18px; }

/* controls */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  font-weight: 500; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); font-weight: 600; }
button.primary:hover { opacity: .88; }
button.ghost { background: transparent; }
button.danger { color: var(--neg); }
button.small { padding: 4px 9px; font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 110px; width: 100%; line-height: 1.5; }
select { padding-right: 26px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; color: var(--text-2); }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 22px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.hero .value { font-size: 26px; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.chart-box.short { height: 200px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2);
}
.pill.long { background: var(--pos-soft); color: var(--pos); }
.pill.short { background: var(--neg-soft); color: var(--neg); }
.pill.open { background: var(--text); color: var(--surface); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 9px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.chip.on { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty .actions { margin-top: 16px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* breakdown bars */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 86px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar-track { position: relative; height: 18px; }
.bar-track .axis { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--border); left: 50%; }
.bar-fill { position: absolute; top: 2px; height: 14px; border-radius: 4px; }
.bar-fill.pos { background: var(--pos); }
.bar-fill.neg { background: var(--neg); }
.bar-row .val { text-align: right; font-weight: 600; }
.bar-row .meta { grid-column: 2 / 4; margin-top: -6px; font-size: 11.5px; color: var(--muted); }

/* heatmap */
.heat { display: grid; grid-template-columns: 38px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 11px; }
.heat .h { color: var(--muted); text-align: center; }
.heat .d { color: var(--text-2); display: flex; align-items: center; }
.heat .c { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); min-height: 14px; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 10px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) 110px; gap: 6px; }
.cal .wd { font-size: 12px; color: var(--muted); padding: 0 4px 4px; }
.cal .day {
  min-height: 88px; border: 1px solid var(--border); border-radius: 10px; padding: 8px;
  background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.cal .day:hover { border-color: var(--muted); }
.cal .day.other { opacity: .35; }
.cal .day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal .day.pos { background: var(--pos-soft); }
.cal .day.neg { background: var(--neg-soft); }
.cal .day .n { font-size: 12px; color: var(--text-2); display: flex; justify-content: space-between; }
.cal .day .p { font-weight: 650; font-size: 15px; margin-top: auto; }
.cal .day .c { font-size: 11.5px; color: var(--muted); }
.cal .week { border-radius: 10px; padding: 8px; background: var(--surface-2); display: flex; flex-direction: column; justify-content: center; }
.cal .week .p { font-weight: 650; }

/* drawer */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(620px, 100vw); background: var(--surface);
  border-left: 1px solid var(--border); z-index: 21; transform: translateX(100%); transition: transform .2s ease;
  overflow-y: auto; box-shadow: var(--shadow);
}
.drawer.open { transform: none; }
.drawer-head {
  position: sticky; top: 0; background: var(--surface); z-index: 1; padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.drawer-body { padding: 18px 22px 110px; display: flex; flex-direction: column; gap: 20px; }
.drawer-foot {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 12px 22px; display: flex; gap: 10px; justify-content: space-between; align-items: center;
}
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.fact { background: var(--surface); padding: 10px 12px; }
.fact .k { font-size: 11.5px; color: var(--muted); }
.fact .v { font-weight: 600; margin-top: 2px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--text-2); font-weight: 500; }
.field.full { grid-column: 1 / -1; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.stars { display: inline-flex; gap: 2px; }
.stars button { border: 0; background: none; padding: 0 2px; font-size: 20px; color: var(--border); }
.stars button.on { color: var(--warn); }
.toggle3 { display: inline-flex; gap: 6px; }
.shots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.shot { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); aspect-ratio: 16 / 10; background: var(--surface-2); }
.shot img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.shot button { position: absolute; top: 4px; right: 4px; padding: 2px 7px; font-size: 12px; background: rgba(0,0,0,.6); color: #fff; border: 0; }
.dropzone {
  border: 1.5px dashed var(--border); border-radius: 10px; padding: 16px; text-align: center; color: var(--muted);
  font-size: 13px; cursor: pointer;
}
.dropzone.over { border-color: var(--accent); color: var(--accent); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 40; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 8px; }

/* modal */
.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; z-index: 31; box-shadow: var(--shadow);
}
#modal-backdrop { z-index: 30; }
.modal-head { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 10px; }
.calc { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); font-weight: 500; max-width: 90vw;
}
.toast.err { background: var(--neg); color: #fff; }
.callout { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: 10px; background: var(--surface-2); }
.help { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.help ol { padding-left: 18px; margin: 8px 0; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; bottom: 0; top: auto; height: auto; width: 100%; flex-direction: row; padding: 6px; z-index: 10; border-right: 0; border-top: 1px solid rgba(255,255,255,.1); }
  .nav a.active { box-shadow: inset 0 -3px 0 #34d399; }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px; }
  .nav a .badge { display: none; }
  .main { padding: 0 16px 90px; }
  .g2, .g3, .g-2-1 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; }
  #sync-info { display: none; }
  .cal { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal .week { display: none; }
  .cal .day { min-height: 60px; padding: 5px; }
  .cal .day .p { font-size: 12px; }
  .cal .day .c { display: none; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid.g3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* usuario */
.user-box { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; background: rgba(255,255,255,.08); }
.user-box .muted { color: var(--on-brand-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #fff; color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; text-transform: uppercase; }
.user-meta { min-width: 0; }
.user-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.temp-pw { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 16px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); user-select: all; letter-spacing: .04em; }
@media (max-width: 960px) { #nav-admin span { font-size: 11px; } }

/* marca y tema */
.sidebar .ghost { color: var(--on-brand); border-color: rgba(255,255,255,.22); }
.sidebar .ghost:hover { border-color: rgba(255,255,255,.5); }
.theme-btn { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 10px; }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: block; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-btn .sun { display: block; }
  :root:not([data-theme]) .theme-btn .moon { display: none; }
}
.topbar-brand { display: none; align-items: center; gap: 8px; }
.topbar-brand img { width: 30px; height: 30px; border-radius: 8px; }
@media (max-width: 960px) { .topbar-brand { display: flex; } #view-title { font-size: 18px; } }
::selection { background: var(--accent-soft); }
.filters select { max-width: 230px; text-overflow: ellipsis; }

/* celular: tabla compacta, filtros plegables, calendario */
.filters-toggle { display: none; }
.show-sm { display: none; }
.cal .day .p .short { display: none; }
@media (max-width: 960px) {
  .hide-sm { display: none; }
  .filters-toggle { display: inline-flex; }
  .filters select { display: none; }
  .filters.open select { display: block; flex: 1 1 calc(50% - 8px); max-width: none; }
  .cal .wd:nth-child(8) { display: none; }
  .cal { gap: 4px; }
  .cal .day { min-height: 58px; padding: 5px 4px; border-radius: 8px; }
  .cal .day .n { font-size: 11px; }
  .cal .day .p { font-size: 11.5px; letter-spacing: -.02em; }
  .cal .day .p .full { display: none; }
  .cal .day .p .short { display: inline; }
  .card-head { flex-wrap: wrap; }
  .cal-head { flex-wrap: wrap; }
  .drawer-body { padding: 16px 16px 110px; }
  .drawer-head { padding: 16px; }
  .drawer .form-grid.g3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .field input, .field select { width: 100%; }
  .card { padding: 14px; }
  td, th { padding: 9px 6px; }
  .show-sm { display: block; }
}
@media (max-width: 420px) { .hide-xs { display: none; } .seg button { padding: 5px 8px; } }

/* TradingView */
.tv-row { display: flex; gap: 8px; }
.tv-row input { flex: 1; min-width: 0; }
.shot-tag { position: absolute; left: 6px; bottom: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; padding: 2px 7px; border-radius: 99px; background: rgba(0,0,0,.65); color: #fff; }
.tv-preview:empty { display: none; }
.tv-preview { margin-top: 10px; }
.tv-shot { aspect-ratio: auto; }
.tv-shot img { height: auto; object-fit: contain; display: block; background: #131722; }

/* contactos */
.wa { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.btn.primary-link { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); font-weight: 600; }
.pill.warn { background: rgba(183,122,0,.14); color: var(--warn); }
.timeline { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.note { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.note-head { display: flex; gap: 8px; align-items: center; }
.note-head button { margin-left: auto; padding: 0 6px; }
.note-text { margin-top: 4px; white-space: pre-wrap; font-size: 14px; }
select.crm-status { padding: 5px 24px 5px 8px; font-size: 13px; }
@media (max-width: 960px) { .kpis[style] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; } }
@media (max-width: 960px) {
  .nav { gap: 0; }
  .nav a { flex: 1 1 0; min-width: 0; padding: 6px 2px; font-size: 10px; }
  .nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kpis[style] > .kpi:nth-child(5):last-child { grid-column: 1 / -1; }
  #crm-q { width: 100% !important; }
  .card-head > div { width: 100%; }
  .card-head > div select { flex: 1 1 calc(50% - 8px); }
}
@media (max-width: 380px) { .nav a svg { width: 17px; height: 17px; } .nav a { font-size: 9px; } }
