/* RepCore — one stylesheet, no build step, no framework.
   Edit the tokens below to rebrand the whole application. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e6e9ee;
  --border: #dde1e7;
  --border-strong: #c6ccd6;
  --text: #12161c;
  --text-muted: #5b6675;
  --text-faint: #8a93a1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e5edff;
  --accent-text: #ffffff;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #6d28d9;
  --info-soft: #ede9fe;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232c;
    --surface-3: #262d38;
    --border: #2a3038;
    --border-strong: #3a424e;
    --text: #e6edf3;
    --text-muted: #9aa5b1;
    --text-faint: #6e7781;
    --accent: #4d8bff;
    --accent-hover: #6ba0ff;
    --accent-soft: #17263f;
    --good: #4ade80;
    --good-soft: #10281a;
    --warn: #fbbf24;
    --warn-soft: #2a2113;
    --bad: #f87171;
    --bad-soft: #2c1618;
    --info: #a78bfa;
    --info-soft: #1f1b33;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232c;
  --surface-3: #262d38;
  --border: #2a3038;
  --border-strong: #3a424e;
  --text: #e6edf3;
  --text-muted: #9aa5b1;
  --text-faint: #6e7781;
  --accent: #4d8bff;
  --accent-hover: #6ba0ff;
  --accent-soft: #17263f;
  --good: #4ade80;
  --good-soft: #10281a;
  --warn: #fbbf24;
  --warn-soft: #2a2113;
  --bad: #f87171;
  --bad-soft: #2c1618;
  --info: #a78bfa;
  --info-soft: #1f1b33;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app-loading { padding: 48px; color: var(--text-muted); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 14px; border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.nav { padding: 10px 8px; flex: 1; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); padding: 12px 10px 5px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 16px; text-align: center; opacity: .9; }

.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); }
.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px;
  border-radius: var(--radius-sm); cursor: pointer;
}
.user-chip:hover { background: var(--surface-2); }
.avatar {
  width: 27px; height: 27px; border-radius: 50%; flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 650; font-size: 11px;
}
.user-name { font-size: 12.5px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { flex: none; }
.topbar-spacer { flex: 1; }

.content { padding: 20px 22px 60px; flex: 1; }

/* ---------- Cards / grids ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}

.kpi { padding: 14px 16px; }
.kpi-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 24px; font-weight: 680; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-2); position: sticky; top: 0;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { padding: 9px 12px; font-weight: 650; border-top: 2px solid var(--border-strong); }
.empty { padding: 34px 16px; text-align: center; color: var(--text-faint); }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 550; font-size: 13px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

input, select, textarea {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent); outline-offset: -1px;
}
textarea { min-height: 78px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span.label-text {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px;
}
.hint { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 3px; line-height: 1.45; }
label.field .hint { margin-top: 3px; }
label.inline { align-items: flex-start; }
label.inline input[type="checkbox"] { margin-top: 3px; }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 12px; }
label.inline input[type="checkbox"] { width: auto; }
.required-mark { color: var(--bad); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.search-input { max-width: 280px; }
.filter-select { width: auto; min-width: 130px; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 8px 13px; border: none; background: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 550; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 620; background: var(--surface-3); color: var(--text-muted);
  white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack { display: flex; flex-direction: column; gap: 3px; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }

/* ---------- Pipeline board ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.board-col {
  flex: 0 0 268px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.board-col.drop-target { border-color: var(--accent); background: var(--accent-soft); }
.board-col-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.board-col-title { display: flex; align-items: center; gap: 7px; font-weight: 620; font-size: 13px; }
.stage-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--text-faint); }
.board-col-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.board-col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; max-height: 62vh; overflow-y: auto; }
.opp-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px; cursor: grab;
}
.opp-card:hover { border-color: var(--border-strong); }
.opp-card.dragging { opacity: .45; }
.opp-card-title { font-weight: 600; font-size: 12.5px; line-height: 1.35; }
.opp-card-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.opp-card-value { font-weight: 650; font-size: 13px; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 1.4fr) 3fr minmax(84px, auto); gap: 10px; align-items: center; margin-bottom: 7px; font-size: 12.5px; }
.bar-track { background: var(--surface-3); border-radius: 4px; height: 9px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 4px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Modal / drawer ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 10, 16, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 640px; margin: auto 0;
}
.modal.wide { max-width: 1000px; }
.modal.xwide { max-width: 1240px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; max-height: 74vh; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 13px 18px; border-top: 1px solid var(--border); }

.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 11px 15px; font-size: 13px; max-width: 400px; animation: slide-in .16s ease-out;
}
.toast.error { border-left-color: var(--bad); }
.toast.success { border-left-color: var(--good); }
@keyframes slide-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head .brand-mark { width: 44px; height: 44px; font-size: 21px; margin: 0 auto 12px; border-radius: 12px; }
.login-hint {
  margin-top: 14px; padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 12.5px; color: var(--text-muted);
}

/* ---------- Detail panes ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 13px; }
.detail-item .dt { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.detail-item .dd { margin-top: 2px; font-size: 13.5px; word-break: break-word; }

.line-editor table { width: 100%; border-collapse: collapse; font-size: 13px; }
.line-editor th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--text-muted); padding: 4px 6px; font-weight: 600; }
.line-editor td { padding: 3px 6px; }
.line-editor input { padding: 5px 7px; }

.map-row { display: grid; grid-template-columns: 190px 1fr; gap: 10px; align-items: center; margin-bottom: 7px; }
.map-row .field-name { font-size: 12.5px; font-weight: 600; }
.map-row .field-name small { display: block; font-weight: 400; color: var(--text-faint); font-size: 11px; }

.progress { height: 7px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 4px; }

code.inline { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
