/* Colour tokens: every text/background pair below meets WCAG AA (4.5:1) in both schemes. */
:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1f2330;
  --muted: #5b6472;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --link: #4338ca;
  --danger: #b91c1c;
  --success: #15803d;
  --warn: #b45309;
  --info: #1d4ed8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --panel: #171a23;
    --text: #e6e8ee;
    --muted: #9aa1b0;
    --border: #2a2f3c;
    --link: #8ab4f8;
    --danger: #f87171;
    --success: #4ade80;
    --warn: #fbbf24;
    --info: #60a5fa;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--link); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.logo { background: var(--primary); color: #fff; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: var(--text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
}
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot { margin-top: auto; color: var(--muted); font-size: 12px; padding: 8px; }

main { flex: 1; padding: 28px 32px; min-width: 0; }
h1:focus { outline: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.icon-btn { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
.toolbar input, .toolbar select { width: auto; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.narrow { max-width: 640px; }
.card-title { margin: 0 0 12px; font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; overflow-wrap: anywhere; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--bg); }
td b { overflow-wrap: anywhere; }
th.actions, td.actions {
  text-align: right;
  white-space: nowrap;
  position: sticky; /* Edit stays reachable when the table scrolls sideways */
  right: 0;
  background: var(--panel);
}
tbody tr:hover td.actions { background: var(--bg); }
.table-wrap { overflow-x: auto; padding: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); border: 1px solid var(--border); }
.badge.lead { color: var(--info); }
.badge.prospect { color: var(--warn); }
.badge.customer { color: var(--success); }
.badge.inactive { color: var(--muted); }
.tag { display: inline-block; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-size: 12px; margin-right: 4px; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(180px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 300px; }
.column-head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 6px; font-weight: 600; }
.column-head .sum { color: var(--muted); font-weight: 400; font-size: 12px; }
.column-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.column.drag-over { outline: 2px dashed var(--primary); }
.deal { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: grab; }
.deal:active { cursor: grabbing; }
.deal .title { font-weight: 600; overflow-wrap: anywhere; }
.deal .meta { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; justify-content: space-between; gap: 6px; }
.deal:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.deal-move { display: flex; justify-content: space-between; margin-top: 8px; }
.mv {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  width: 32px;
  height: 28px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.mv:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.mv:disabled { opacity: 0.3; cursor: default; }

/* Tasks */
.task { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: none; }
.task input[type=checkbox] { width: 18px; height: 18px; flex-shrink: 0; }
.task .body { flex: 1; min-width: 0; }
.task .title { overflow-wrap: anywhere; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.overdue { color: var(--danger); font-weight: 600; }

/* Activity */
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; overflow-wrap: anywhere; }
.activity li:last-child { border-bottom: none; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal.hidden { display: none; }
.modal-card { background: var(--panel); border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 20px 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-actions { display: flex; justify-content: space-between; margin-top: 18px; gap: 8px; }
.form-actions .right { display: flex; gap: 8px; margin-left: auto; }

/* Toast: stays in the accessibility tree (opacity, not display:none) so
   aria-live announcements are reliable. */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: min(420px, calc(100vw - 40px));
  background: var(--text);
  color: var(--panel);
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 60;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #b91c1c; color: #fff; }

/* Responsive */
@media (max-width: 900px) {
  .col-phone, .col-deals { display: none; }
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0 8px 8px 0; width: 100%; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .sidebar nav a { padding: 7px 10px; }
  .sidebar-foot { display: none; }
  main { padding: 18px 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .col-company { display: none; }
  .toolbar input[type=search] { flex: 1 1 160px; }
}

@media (max-width: 480px) {
  .col-email { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
