/* EMBACO CRM - Pipedrive-style interface */
:root {
  --green: #1fa363;
  --green-dark: #17854f;
  --topbar: #26292c;
  --topbar-hover: #3b3f43;
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #d9dcde;
  --border-light: #e7e9eb;
  --text: #26292c;
  --muted: #75787b;
  --red: #e5484d;
  --yellow: #f0a800;
  --blue: #317ae2;
  --radius: 4px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
a { color: var(--blue); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
#topbar {
  height: 48px;
  background: var(--topbar);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  flex-shrink: 0;
  z-index: 30;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  margin-right: 16px;
  white-space: nowrap;
}
.logo-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.nav-link {
  color: #c9cbcd;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13.5px;
  white-space: nowrap;
}
.nav-link:hover { background: var(--topbar-hover); color: #fff; }
.nav-link.active { background: var(--topbar-hover); color: #fff; }
.topbar-spacer { flex: 1; }
.search-wrap { position: relative; margin-right: 10px; }
#search-input {
  background: var(--topbar-hover);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: #fff;
  padding: 7px 10px 7px 30px;
  width: 220px;
  font-size: 13px;
  outline: none;
}
#search-input::placeholder { color: #9a9da0; }
#search-input:focus { background: #fff; color: var(--text); border-color: var(--green); }
.search-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: #9a9da0; pointer-events: none; font-size: 14px;
}
#search-results {
  position: absolute; top: 40px; left: 0;
  width: 340px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  display: none;
  max-height: 420px;
  overflow-y: auto;
  z-index: 60;
}
#search-results.open { display: block; }
.search-group { padding: 6px 0; border-bottom: 1px solid var(--border-light); }
.search-group:last-child { border-bottom: none; }
.search-group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 4px 12px;
}
.search-item { display: block; padding: 7px 12px; color: var(--text); }
.search-item:hover { background: var(--bg); }
.search-item .sub { color: var(--muted); font-size: 12px; }
.btn-add-deal {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13.5px;
  margin-right: 12px;
  white-space: nowrap;
}
.btn-add-deal:hover { background: var(--green-dark); }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none;
  color: #c9cbcd; font-size: 13px;
  padding: 4px 6px; border-radius: var(--radius);
}
.user-chip:hover { background: var(--topbar-hover); color: #fff; }
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
#user-menu {
  position: absolute; right: 10px; top: 44px;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  min-width: 210px; z-index: 60;
  display: none;
}
#user-menu.open { display: block; }
#user-menu .menu-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 8px 12px 2px;
}
#user-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  background: none; border: none;
  padding: 8px 12px; font-size: 13.5px;
}
#user-menu button:hover { background: var(--bg); }
#user-menu .check { margin-left: auto; color: var(--green); font-weight: 700; }

/* ---------- sub bar ---------- */
.subbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.subbar h1 { font-size: 17px; font-weight: 600; margin-right: 4px; }
.subbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg button {
  background: #fff; border: none;
  padding: 6px 12px; font-size: 13px;
  color: var(--muted);
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--bg); color: var(--text); font-weight: 600; }
select, input[type=text], input[type=email], input[type=number],
input[type=date], input[type=password], input[type=url], textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 9px;
  font: inherit;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
  outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--green); }
.pill {
  display: inline-block;
  font-size: 11.5px; font-weight: 600;
  border-radius: 10px;
  padding: 2px 9px;
}
.pill.green { background: #e2f5ec; color: #17854f; }
.pill.gray { background: #eceeef; color: var(--muted); }
.pill.red { background: #fdebec; color: #c53030; }
.pill.yellow { background: #fdf3d7; color: #92600a; }

/* ---------- board ---------- */
#view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.board {
  flex: 1;
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding: 0;
}
.col {
  flex: 1;
  min-width: 205px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.col:last-child { border-right: none; }
.col-head {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 9px 12px;
  flex-shrink: 0;
}
.col-head .col-name { font-weight: 600; font-size: 13.5px; }
.col-head .col-sum { color: var(--muted); font-size: 12px; margin-top: 2px; }
.col-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.col-body.drag-over { background: #e9f0f7; }
.deal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: grab;
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.deal-card:hover { border-color: #b9bec2; }
.deal-card.dragging { opacity: .45; }
.deal-title { font-weight: 600; font-size: 13.5px; line-height: 1.35; }
.deal-org { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.deal-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: 7px;
}
.deal-value { font-size: 12.5px; color: var(--text); }
.deal-foot .avatar { margin-left: auto; }
.act-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.act-dot.red { background: var(--red); }
.act-dot.green { background: var(--green); }
.act-dot.gray { background: #b9bec2; }
.act-dot.none { background: var(--yellow); }
.empty-col { color: var(--muted); font-size: 12.5px; text-align: center; padding: 14px 4px; }
.drop-placeholder {
  border: 2px dashed #b9bec2;
  border-radius: var(--radius);
  height: 64px;
  background: #eef1f3;
}

/* ---------- closed deals list ---------- */
.list-wrap { flex: 1; overflow-y: auto; padding: 16px; }
.grid-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--border);
  table-layout: fixed;
}
.grid-table th, .grid-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-table th {
  background: #fafbfb;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.grid-table tbody tr:hover { background: #f7f9fa; }
.grid-table tbody tr { cursor: pointer; }
.grid-table td.num, .grid-table th.num { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- detail pages ---------- */
.detail-wrap { flex: 1; overflow-y: auto; }
.detail-head {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px 0;
}
.detail-head-top { display: flex; align-items: flex-start; gap: 12px; }
.detail-head h1 { font-size: 19px; font-weight: 600; }
.detail-head .meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.detail-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.green:hover { background: var(--green-dark); }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.red:hover { background: #c93a3f; }
.btn.subtle { border-color: transparent; color: var(--muted); }
.btn.subtle:hover { background: var(--bg); color: var(--text); }
.stage-bar { display: flex; margin: 14px 0 0; padding-bottom: 14px; gap: 3px; }
.stage-seg {
  flex: 1;
  height: 26px;
  background: #e3e6e8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  position: relative;
  border: none;
}
.stage-seg:first-child { border-radius: 13px 0 0 13px; }
.stage-seg:last-child { border-radius: 0 13px 13px 0; }
.stage-seg.done { background: var(--green); color: #fff; }
.stage-seg:hover { filter: brightness(.95); }
.status-banner {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13.5px;
}
.status-banner.won { background: #e2f5ec; color: #17854f; }
.status-banner.lost { background: #fdebec; color: #c53030; }
.detail-grid {
  display: flex;
  gap: 16px;
  padding: 16px 20px 28px;
  align-items: flex-start;
}
.side-col { width: 330px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel-head {
  display: flex; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600; font-size: 13.5px;
}
.panel-head .btn { margin-left: auto; padding: 4px 10px; font-size: 12.5px; }
.panel-body { padding: 12px 14px; }
.kv { display: grid; grid-template-columns: 120px 1fr; row-gap: 9px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { overflow: hidden; text-overflow: ellipsis; }

/* ---------- timeline / feed ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--border-light); }
.tabs button {
  background: none; border: none;
  padding: 10px 14px;
  font-size: 13.5px; font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--green); }
.composer { padding: 12px 14px; border-bottom: 1px solid var(--border-light); }
.composer textarea { width: 100%; min-height: 64px; resize: vertical; }
.composer .row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.feed { list-style: none; }
.feed-item {
  display: flex; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
}
.feed-item:last-child { border-bottom: none; }
.feed-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.feed-body { flex: 1; min-width: 0; }
.feed-title { font-weight: 600; font-size: 13.5px; }
.feed-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.feed-text { margin-top: 5px; font-size: 13.5px; white-space: pre-wrap; }
.feed-meta { color: var(--muted); font-size: 12px; margin-top: 5px; }
.feed-item.done-act .feed-title { text-decoration: line-through; color: var(--muted); }
.feed-check { margin-top: 6px; }
.feed-del {
  background: none; border: none; color: var(--muted);
  font-size: 15px; padding: 2px 6px; visibility: hidden;
}
.feed-item:hover .feed-del { visibility: visible; }
.feed-del:hover { color: var(--red); }
.email-dir { font-weight: 700; font-size: 11px; }
.email-dir.sent { color: var(--blue); }
.email-dir.received { color: var(--green-dark); }
.banner {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.banner.warn { background: #fdf3d7; color: #6d4c06; }
.banner.err { background: #fdebec; color: #c53030; font-weight: 600; }
.empty-note { padding: 22px 14px; color: var(--muted); text-align: center; font-size: 13px; }

/* ---------- modal ---------- */
#modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
#modal-root.open { display: block; }
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(38,41,44,.55);
}
.modal {
  position: relative;
  width: 480px;
  max-width: calc(100vw - 32px);
  margin: 7vh auto 0;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 16px 48px rgba(0,0,0,.3);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center;
}
.modal-close {
  margin-left: auto;
  background: none; border: none;
  font-size: 20px; color: var(--muted);
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  display: flex; justify-content: flex-end; gap: 8px;
}
.form-row { margin-bottom: 12px; }
.form-row label {
  display: block;
  font-size: 12.5px; font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.form-split { display: flex; gap: 10px; }
.form-split .form-row { flex: 1; }

/* ---------- settings ---------- */
.settings-wrap { flex: 1; overflow-y: auto; padding: 20px; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(430px, 1fr));
  gap: 16px;
  max-width: 1200px;
}
.settings-grid .panel-body p { margin-bottom: 10px; line-height: 1.5; }
.inline-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-light);
}
.inline-row:last-child { border-bottom: none; }
.inline-row input[type=text] { flex: 1; }
.icon-btn {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px; font-size: 12.5px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* ---------- narrow screens: stack detail columns ---------- */
@media (max-width: 980px) {
  .detail-grid { flex-direction: column; }
  .side-col { width: 100%; }
}

/* ---------- toast ---------- */
#toast-root {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
}
.toast {
  background: var(--topbar);
  color: #fff;
  border-radius: 6px;
  padding: 11px 18px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: 480px;
}
.toast.error { background: var(--red); font-weight: 600; }
