:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8f0;
  --text: #1a2233;
  --text-soft: #66718a;
  --primary: #4f6df5;
  --primary-soft: #eaeefe;
  --green: #1faa72;
  --green-soft: #e4f6ee;
  --amber: #e0930c;
  --amber-soft: #fdf2dd;
  --red: #e0533d;
  --red-soft: #fce8e4;
  --purple: #8b5cf6;
  --purple-soft: #f0ebfe;
  --shadow: 0 1px 3px rgba(20,30,60,.06), 0 8px 24px rgba(20,30,60,.06);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0e1220;
  --surface: #171c2e;
  --surface-2: #1d2336;
  --border: #2a3148;
  --text: #e7ecf6;
  --text-soft: #8b96b0;
  --primary: #6d86ff;
  --primary-soft: #232a47;
  --green-soft: #14301f;
  --amber-soft: #2f2510;
  --red-soft: #321a14;
  --purple-soft: #221a3d;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

#app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; }
.brand-mark { color: var(--primary); font-size: 20px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -.3px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border: none; background: none;
  color: var(--text-soft); font-size: 14px; font-weight: 500;
  border-radius: 10px; cursor: pointer; text-align: left; width: 100%;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-ic { width: 18px; text-align: center; font-size: 15px; }
.sidebar-foot { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 14px; border-top: 1px solid var(--border); }
/* Export + Import share the top row; the two icon buttons sit compact below. */
#exportBtn, #importBtn { flex: 1 1 calc(50% - 3px); }
#themeBtn, #signOutBtn { flex: 0 0 auto; min-width: 40px; padding-left: 0; padding-right: 0; text-align: center; }

/* Main */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.search-wrap { position: relative; flex: 1; max-width: 460px; }
.search-ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-soft); font-size: 15px; }
#search {
  width: 100%; padding: 10px 12px 10px 36px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 14px;
}
#search:focus { outline: none; border-color: var(--primary); background: var(--surface); }

.view { padding: 28px; overflow-y: auto; flex: 1; }

/* Buttons */
.primary-btn {
  background: var(--primary); color: #fff; border: none; padding: 10px 18px;
  border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: filter .12s, transform .05s;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active { transform: translateY(1px); }
.ghost-btn {
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 9px; font-weight: 500; font-size: 13px; cursor: pointer; flex: 1;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-soft); }
.danger-btn {
  background: var(--red-soft); color: var(--red); border: none; padding: 10px 16px;
  border-radius: 10px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.danger-btn:hover { filter: brightness(.97); }
.icon-btn { background: none; border: none; color: var(--text-soft); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Page header */
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.page-head p { color: var(--text-soft); margin-top: 3px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-card .label { color: var(--text-soft); font-size: 13px; font-weight: 500; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 8px; letter-spacing: -.5px; }
.stat-card .sub { font-size: 12px; color: var(--text-soft); margin-top: 4px; }
.stat-ic { float: right; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; }

/* Cards / panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }

/* Table */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; padding: 11px 20px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-soft); font-weight: 600; background: var(--surface-2); }
tbody td { padding: 13px 20px; border-top: 1px solid var(--border); }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--text-soft); font-size: 13px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; margin-right: 10px; vertical-align: middle; }
.name-cell { display: flex; align-items: center; }

/* Badges */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.new { background: var(--primary-soft); color: var(--primary); }
.badge.contacted { background: var(--amber-soft); color: var(--amber); }
.badge.qualified { background: var(--purple-soft); color: var(--purple); }
.badge.won { background: var(--green-soft); color: var(--green); }
.badge.lost { background: var(--red-soft); color: var(--red); }

/* Pipeline */
.pipeline { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(248px, 1fr); gap: 16px; align-items: start; overflow-x: auto; padding-bottom: 10px; }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 120px; }
.col-head { padding: 13px 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.col-head .count { background: var(--surface); color: var(--text-soft); border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.col-sum { font-size: 12px; color: var(--text-soft); font-weight: 500; }
.col-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 60px; }
.col-body.drag-over { background: var(--primary-soft); border-radius: 0 0 var(--radius) var(--radius); }
.deal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  padding: 13px 14px; cursor: grab; box-shadow: 0 1px 2px rgba(20,30,60,.04);
}
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: .4; }
.deal-card .title { font-weight: 600; margin-bottom: 5px; }
.deal-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; }
.deal-card .val { font-weight: 700; color: var(--green); }
.deal-card .company { color: var(--text-soft); font-size: 13px; }
.deal-card .date { font-size: 12px; color: var(--text-soft); }

/* Empty */
.empty { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,20,35,.5); display: grid; place-items: center; z-index: 100; backdrop-filter: blur(2px); }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 16px; width: 480px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-form { padding: 20px 22px; overflow-y: auto; display: grid; gap: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.field textarea { resize: vertical; min-height: 70px; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }
.modal-foot .spacer { flex: 1; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 11px 20px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); z-index: 200; animation: rise .2s ease; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

.row-actions { display: flex; gap: 6px; }
.tag-link { color: var(--primary); font-weight: 600; }

/* Modal extra (activity timeline) */
.modal-extra { border-top: 1px solid var(--border); }
.modal-extra:empty { border-top: none; }
.timeline-wrap { padding: 18px 22px; max-height: 280px; overflow-y: auto; }
.timeline-wrap h3 { font-size: 13px; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; }
.act-add { display: grid; grid-template-columns: 116px 1fr auto; gap: 8px; margin-bottom: 16px; }
.act-add select, .act-add input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--text); font-size: 13px; font-family: inherit; }
.act-add input:focus, .act-add select:focus { outline: none; border-color: var(--primary); }
.act-add button { background: var(--primary); color: #fff; border: none; border-radius: 9px; padding: 0 14px; font-weight: 600; cursor: pointer; font-size: 13px; }
.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-item { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; padding: 9px 0; align-items: start; }
.tl-item + .tl-item { border-top: 1px solid var(--border); }
.tl-ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; }
.tl-ic.note { background: var(--primary-soft); color: var(--primary); }
.tl-ic.call { background: var(--green-soft); color: var(--green); }
.tl-ic.email { background: var(--amber-soft); color: var(--amber); }
.tl-ic.meeting { background: var(--purple-soft); color: var(--purple); }
.tl-body { font-size: 13.5px; line-height: 1.45; }
.tl-meta { font-size: 11.5px; color: var(--text-soft); margin-top: 2px; }
.tl-del { background: none; border: none; color: var(--text-soft); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; opacity: 0; }
.tl-item:hover .tl-del { opacity: 1; }
.tl-del:hover { background: var(--red-soft); color: var(--red); }
.tl-empty { color: var(--text-soft); font-size: 13px; padding: 6px 0; }

/* Tasks */
.task-list { display: flex; flex-direction: column; }
.task-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 14px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); cursor: pointer; }
.task-row:first-child { border-top: none; }
.task-row:hover { background: var(--surface-2); }
.task-check { width: 20px; height: 20px; border: 2px solid var(--border); border-radius: 6px; display: grid; place-items: center; cursor: pointer; color: transparent; font-size: 12px; flex-shrink: 0; transition: all .12s; }
.task-check:hover { border-color: var(--primary); }
.task-check.done { background: var(--green); border-color: var(--green); color: #fff; }
.task-title { font-weight: 600; }
.task-row.done .task-title { text-decoration: line-through; color: var(--text-soft); font-weight: 500; }
.task-sub { font-size: 13px; color: var(--text-soft); margin-top: 2px; }
.task-due { font-size: 13px; font-weight: 600; color: var(--text-soft); white-space: nowrap; }
.task-due.overdue { color: var(--red); }
.task-due.today { color: var(--amber); }
.task-section-label { padding: 14px 20px 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-soft); }

@media (max-width: 860px) {
  #app { grid-template-columns: 64px 1fr; }
  .brand-name, .nav-item span:not(.nav-ic), .sidebar-foot { display: none; }
  .nav-item { justify-content: center; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===================== Auth + sync (added for shared cloud version) ===================== */
#app { display: none; }  /* hidden until login resolves; JS reveals it */

.boot-loader { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg, #f7f8fa); color: var(--text-soft); font-size: 14px; z-index: 1000; }

.login-screen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg, #f7f8fa); z-index: 1100; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.08); }
.login-brand { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.login-brand .brand-mark { color: var(--primary); }
.login-sub { color: var(--text-soft); font-size: 14px; margin: -4px 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2, #fff); color: var(--text); font-size: 14px; }
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-btn { margin-top: 6px; width: 100%; justify-content: center; }
.login-error { color: var(--red); font-size: 13px; text-align: center; }

.sync-status { font-size: 12px; font-weight: 600; color: var(--text-soft); margin-right: 12px; min-width: 56px; text-align: right; transition: color .2s; }
.sync-status.saving { color: var(--amber); }
.sync-status.saved { color: var(--green); }
.sync-status.error { color: var(--red); }

/* Fix: these overlays set display:grid, which overrides the `hidden` attribute.
   Force hidden to win so login/boot actually disappear once signed in. */
.login-screen[hidden], .boot-loader[hidden] { display: none !important; }
