:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e2e6ee;
  --text: #1c2333;
  --muted: #6b7488;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
}
[data-theme="dark"] {
  --bg: #12151c;
  --panel: #1a1f2a;
  --border: #2a3140;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #5b8def;
  --accent-soft: #22304a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
#app { display: flex; min-height: 100vh; }

/* sidebar */
.sidebar {
  width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.logo { font-size: 17px; font-weight: 700; padding: 18px 16px; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; flex: 1; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
#nav a:hover { background: var(--bg); color: var(--text); }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-footer { padding: 12px; display: flex; gap: 8px; }
.ghost-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  cursor: pointer; color: var(--text); font-size: 13px;
}
.ghost-btn:hover { background: var(--bg); }

/* main */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--panel); position: relative; }
.search-wrap { max-width: 480px; position: relative; }
#global-search {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px; outline: none;
}
#global-search:focus { border-color: var(--accent); }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 380px; overflow-y: auto; z-index: 50;
}
.search-results .group-label { padding: 8px 12px 2px; font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.search-results .result { display: block; padding: 7px 12px; cursor: pointer; color: var(--text); text-decoration: none; }
.search-results .result:hover { background: var(--bg); }
.search-results .result small { color: var(--muted); margin-left: 6px; }
.hidden { display: none !important; }

#view { padding: 24px; flex: 1; }

/* view header */
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.view-head h1 { font-size: 21px; }
.view-head .spacer { flex: 1; }
.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 8px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--red); }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* cards / tables */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card h3 { padding: 14px 16px 0; font-size: 14px; color: var(--muted); font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg); }
.table-wrap { overflow-x: auto; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { padding: 16px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .num { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .num.green { color: var(--green); }
.kpi .num.red { color: var(--red); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dash-grid .card { padding-bottom: 10px; }
.dash-grid .full { grid-column: 1 / -1; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.chart { padding: 10px 16px; overflow-x: auto; }

/* chips / badges */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--muted); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; cursor: pointer; font-weight: 500;
}
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.gray { background: var(--bg); color: var(--muted); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: rgba(22,163,74,.12); color: var(--green); }
.badge.red { background: rgba(220,38,38,.12); color: var(--red); }
.badge.amber { background: rgba(217,119,6,.12); color: var(--amber); }
.tag-pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: var(--accent-soft); color: var(--accent); margin-right: 4px; }

/* kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 12px; }
.kanban-col { min-width: 240px; width: 240px; flex-shrink: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.kanban-col .col-head { padding: 10px 12px; font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); }
.kanban-col .col-head .sum { color: var(--muted); font-weight: 500; font-size: 12px; }
.kanban-cards { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.kanban-col.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.deal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  cursor: grab; box-shadow: var(--shadow);
}
.deal-card .dc-title { font-weight: 600; margin-bottom: 4px; }
.deal-card .dc-meta { color: var(--muted); font-size: 12px; }
.deal-card .dc-value { font-weight: 600; margin-top: 4px; font-size: 13px; }
.deal-card.dragging { opacity: .5; }

/* forms & modal */
#modal-root .overlay {
  position: fixed; inset: 0; background: rgba(10, 14, 22, .5); display: flex;
  align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; overflow-y: auto;
}
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-head .x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field input, label.field select, label.field textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  background: var(--bg); color: var(--text); outline: none; font-family: inherit;
}
label.field input:focus, label.field select:focus, label.field textarea:focus { border-color: var(--accent); }
label.field textarea { min-height: 70px; resize: vertical; }
.hint { font-size: 11px; color: var(--muted); font-weight: 400; }

/* detail / timeline */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin-bottom: 16px; }
.detail-grid .dt { font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.detail-grid .dd { margin-bottom: 6px; }
.timeline { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; max-height: 300px; overflow-y: auto; }
.tl-item { display: flex; gap: 10px; }
.tl-icon { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 13px; }
.tl-body { flex: 1; }
.tl-body .tl-content { white-space: pre-wrap; }
.tl-body .tl-time { font-size: 11px; color: var(--muted); }
.note-form { display: flex; gap: 8px; margin-top: 12px; }
.note-form select { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 6px; }
.note-form input { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }

/* tasks */
.task-row .tick { width: 18px; height: 18px; cursor: pointer; }
.task-done { text-decoration: line-through; color: var(--muted); }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  box-shadow: var(--shadow); animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-cell { min-height: 84px; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: var(--bg); overflow: hidden; }
.cal-cell.empty-cell { border: none; background: none; }
.cal-cell.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cal-day { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.cal-ev { font-size: 11px; padding: 2px 5px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); margin-bottom: 2px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.deal-ev { background: rgba(22,163,74,.12); color: var(--green); }
.cal-ev.done { text-decoration: line-through; opacity: .6; }

/* deal items */
.items-table { font-size: 13px; }
.items-table th, .items-table td { padding: 6px 8px; }

/* login */
.login-overlay {
  position: fixed; inset: 0; background: var(--bg); display: flex;
  align-items: center; justify-content: center; z-index: 300;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; width: 100%; max-width: 340px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.login-box input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px; width: 100%;
}
.login-box input:focus { border-color: var(--accent); outline: none; }
.login-error { color: var(--red); font-size: 13px; }
.qr-box { background: #fff; border-radius: 10px; padding: 10px; width: fit-content; margin: 8px 0; }
.qr-box svg { display: block; width: 200px; height: 200px; }

/* settings */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-grid .card { padding: 16px; }
.settings-grid h3 { padding: 0 0 10px; }
.settings-grid code { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: 12px; display: inline-block; margin-top: 6px; word-break: break-all; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 140px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.row-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.row-list .row-item { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; background: var(--bg); border-radius: 8px; gap: 8px; }
.row-list .row-item span { overflow: hidden; text-overflow: ellipsis; }

/* pipedrive batch */
.deal-card.rotting { border-left: 3px solid var(--red); }
.dc-next { font-size: 11px; margin-top: 5px; color: var(--muted); }
.dc-next.overdue { color: var(--red); font-weight: 600; }
.dc-next.warn { color: var(--amber); font-weight: 600; }
.goal-bar { height: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.goal-fill { height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }

/* notifications */
.notif-badge {
  position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff;
  border-radius: 999px; font-size: 10px; font-weight: 700; padding: 1px 5px; min-width: 16px; text-align: center;
}

/* nav sections */
.nav-sec { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 12px 12px 3px; }
#nav { overflow-y: auto; }

/* command palette */
.pal-input { width: 100%; padding: 14px 16px; border: none; border-bottom: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 16px; outline: none; border-radius: 12px 12px 0 0; }
.pal-list { max-height: 320px; overflow-y: auto; padding: 6px; }
.pal-item { padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.pal-item:hover, .pal-item.sel { background: var(--accent-soft); color: var(--accent); }

/* logo */
.logo-img { width: 26px; height: 26px; vertical-align: -6px; }
.login-box .logo-img { width: 34px; height: 34px; }

/* security gate */
.gate-in { width: 100%; padding: 10px 12px; margin: 5px 0; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 14px; box-sizing: border-box; }
.gate-in:focus { border-color: var(--accent); outline: none; }
.login-box .qr-box svg { width: 170px; height: 170px; }

/* feature control center */
.feat-group { padding: 0; margin-bottom: 10px; }
.feat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
.feat-body { padding: 4px 16px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.feat-item { display: flex; gap: 9px; align-items: flex-start; padding: 5px 4px; font-size: 13px; border-radius: 6px; }
.feat-item:hover { background: var(--bg); }
.feat-item input { margin-top: 2px; }
