:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-muted: #f0efe9;
  --border: #e2e0d8;
  --text-primary: #1f1e1c;
  --text-secondary: #6b6a63;
  --text-muted: #9a988f;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --success: #3b6d11;
  --success-bg: #eaf3de;
  --radius: 8px;
}

body.dark {
  --bg: #1c1c1a;
  --surface: #262624;
  --surface-muted: #2f2f2c;
  --border: #3d3d39;
  --text-primary: #f0efe9;
  --text-secondary: #b0aea5;
  --text-muted: #7d7b73;
  --accent: #6cabe8;
  --accent-bg: #1c3a52;
  --danger: #e28b8b;
  --danger-bg: #4a2323;
  --success: #9bcf6b;
  --success-bg: #253a17;
}

body {
  transition: background-color 0.15s ease, color 0.15s ease;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
}

.hidden { display: none !important; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text-primary);
}

textarea { resize: vertical; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text-primary);
}
button:hover { background: var(--surface-muted); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #0c447c; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

/* Login */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 320px;
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .muted { color: var(--text-secondary); margin: 0 0 16px; font-size: 13px; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card button { width: 100%; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; font-size: 16px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab-btn {
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--text-secondary);
}
.tab-btn.active {
  background: var(--surface-muted);
  color: var(--text-primary);
  font-weight: 500;
}

.view-root { padding: 24px; max-width: 1200px; margin: 0 auto; }

/* Metric cards */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--surface-muted);
  border-radius: var(--radius);
  padding: 16px;
}
.metric-card.danger { background: var(--danger-bg); }
.metric-card.success { background: var(--success-bg); }
.metric-label { font-size: 13px; color: var(--text-secondary); margin: 0 0 4px; }
.metric-card.danger .metric-label { color: var(--danger); }
.metric-card.success .metric-label { color: var(--success); }
.metric-value { font-size: 26px; font-weight: 600; margin: 0; }
.metric-card.danger .metric-value { color: var(--danger); }
.metric-card.success .metric-value { color: var(--success); }

/* Filters */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters input[type="text"] { flex: 1; min-width: 200px; }
.filters select { min-width: 140px; }

/* Table */
.contacts-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13px;
}
td { padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13px; }
tr.contact-row { cursor: pointer; }
tr.contact-row:hover { background: var(--surface-muted); }
.overdue-date { color: var(--danger); font-weight: 500; }

.status-badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--text-secondary);
  white-space: nowrap;
}
.status-badge.st-progress { background: var(--accent-bg); color: var(--accent); }
.status-badge.st-overdue { background: var(--danger-bg); color: var(--danger); }
.status-badge.st-positive { background: var(--success-bg); color: var(--success); }

/* Kanban */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}
.kanban-col {
  background: var(--surface-muted);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 80px;
}
.kanban-col-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: grab;
}
.kanban-card:last-child { margin-bottom: 0; }
.kanban-card-name { font-size: 13px; font-weight: 500; margin: 0; }
.kanban-card-meta { font-size: 12px; color: var(--text-secondary); margin: 3px 0 0; }
.kanban-col.drag-over { outline: 2px dashed var(--accent); }
.kanban-card.dragging { opacity: 0.4; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 16px;
  z-index: 100;
}
.modal-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 560px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-header .sub { color: var(--text-secondary); font-size: 13px; margin: 4px 0 0; }
.close-x { border: none; background: none; font-size: 18px; padding: 0 4px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.field-full { margin-bottom: 8px; }
.field-full input, .field-full textarea, .field-full select { width: 100%; }
label.field-label { font-size: 12px; color: var(--text-secondary); display: block; margin-bottom: 4px; }

.info-table td { border-top: 1px solid var(--border); padding: 6px 0; font-size: 13px; }
.info-table td:first-child { color: var(--text-secondary); width: 40%; }
.info-table td:last-child { text-align: right; }
.info-table a { color: var(--accent); }

.section-title { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin: 16px 0 8px; }

.activity-item { display: flex; gap: 10px; margin-bottom: 10px; }
.activity-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); margin-top: 6px; flex-shrink: 0; }
.activity-text { font-size: 13px; margin: 0; }
.activity-meta { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

.side-decoration {
  position: fixed;
  top: 76px;
  right: 24px;
  width: 200px;
  height: auto;
  opacity: 0.9;
  pointer-events: none;
  z-index: 1;
}
@media (max-width: 1650px) {
  .side-decoration { display: none; }
}

#theme-toggle {
  padding: 8px 10px;
  font-size: 16px;
  line-height: 1;
}

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