:root {
  --bg: #F0F2F5;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --text: #1B2430;
  --text-muted: #6B7686;
  --border: #E2E5EA;
  --primary: #2E5EAA;
  --primary-dark: #234A87;
  --danger: #C9463C;
  --danger-bg: #FBEAE8;
  --success-bg: #E9F5EC;
  --success-text: #2C7A44;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 1px 1px rgba(20,30,50,.04);
  --shadow-md: 0 8px 24px rgba(20,30,50,.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--primary);
  color: #fff;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-left h1 { font-size: 18px; color: #fff; }
.logo-dot {
  width: 12px; height: 12px; border-radius: 4px;
  background: #F4C542;
  display: inline-block;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.me { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; padding: 0 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  transition: background .12s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover { background: #EDEFF3; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #F6D8D5; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

.icon-btn {
  background: transparent; border: none; color: var(--text-muted);
  width: 26px; height: 26px; border-radius: 6px; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-sm { width: 22px; height: 22px; font-size: 12px; }

/* ---------- Board layout ---------- */
.board-wrap { padding: 20px; overflow-x: auto; height: calc(100vh - 56px); }
.boards { display: flex; gap: 16px; align-items: flex-start; min-height: 100%; }

.board {
  background: var(--surface-2);
  border-radius: var(--radius);
  width: 300px;
  min-width: 300px;
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.board-add { background: transparent; box-shadow: none; }
.add-board-btn {
  width: 300px;
  padding: 14px;
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
}
.add-board-btn:hover { background: var(--surface); border-color: var(--primary); color: var(--primary); }

.board-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 8px 12px;
  border-top: 4px solid;
  border-radius: var(--radius) var(--radius) 0 0;
  gap: 4px;
}
.board-rename-form { flex: 1; }
.board-title-input {
  width: 100%;
  border: none; background: transparent;
  font-weight: 700; font-size: 14.5px; color: var(--text);
  padding: 4px 6px; border-radius: 6px;
}
.board-title-input:hover, .board-title-input:focus { background: rgba(0,0,0,.05); outline: none; }

.card-list {
  padding: 4px 10px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-card-btn {
  margin: 6px 10px 12px;
  padding: 8px 10px;
  text-align: left;
  border: none; background: transparent;
  color: var(--text-muted); font-weight: 600; border-radius: var(--radius-sm);
}
.add-card-btn:hover { background: rgba(0,0,0,.05); color: var(--text); }

/* ---------- Card preview ---------- */
.card-preview {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid transparent;
}
.card-preview:hover { border-color: var(--primary); }
.card-preview-title { font-weight: 600; margin-bottom: 4px; }
.card-preview-client { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.badge {
  display: inline-block; background: #EAF1FB; color: var(--primary);
  font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
  margin-bottom: 6px;
}
.progress-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.progress-bar { flex: 1; height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; }
.progress-bar-lg { height: 8px; margin: 6px 0 12px; }
.progress-fill { height: 100%; background: var(--success-text); border-radius: 4px; }
.progress-text { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.card-preview-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.comment-count { font-size: 12px; color: var(--text-muted); }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 12px;
  flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10.5px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,20,30,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  width: 100%; max-width: 640px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 18px 4px;
  gap: 8px;
}
.modal-header form { flex: 1; }
.card-title-input {
  width: 100%; border: none; font-size: 19px; font-weight: 700;
  padding: 6px 8px; border-radius: 6px; background: transparent; color: var(--text);
}
.card-title-input:hover, .card-title-input:focus { background: var(--surface-2); outline: none; }
.modal-body { padding: 6px 18px 20px; }

.modal-row { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 16px; }
.modal-row-3 { align-items: flex-end; }
.modal-field { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 4px; }
.modal-field label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.modal-field input, .modal-field select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.modal-field input:focus, .modal-field select:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: #fff; }

.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-muted); margin: 20px 0 8px;
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
}

.custom-fields-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.custom-field-row {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 7px 10px; font-size: 13px;
}
.cf-name { font-weight: 700; }
.cf-value { flex: 1; color: var(--text); }

.checklist { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.checklist-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
}
.checklist-item:hover { background: var(--surface-2); }
.checklist-item label { display: flex; align-items: center; gap: 8px; flex: 1; cursor: pointer; }
.checklist-item.is-checked span { text-decoration: line-through; color: var(--text-muted); }
.item-link { font-size: 13px; }

.inline-form { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.inline-form input {
  flex: 1; min-width: 120px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.inline-form input:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: #fff; }

.timeline { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.timeline-item { display: flex; gap: 10px; align-items: flex-start; }
.timeline-item-activity { padding-left: 4px; }
.timeline-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--border);
  margin-top: 7px; margin-left: 8px; flex-shrink: 0;
}
.timeline-content { flex: 1; font-size: 13.5px; }
.timeline-time { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.modal-footer { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- Auth pages ---------- */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--primary); }
.login-box {
  background: var(--surface); padding: 32px; border-radius: var(--radius);
  width: 100%; max-width: 340px; box-shadow: var(--shadow-md);
}
.login-box h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: var(--text-muted); margin: 0 0 18px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-top: 8px; }
.login-form input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.login-form button { margin-top: 16px; }

/* ---------- Generic pages (users.php) ---------- */
.page-narrow { max-width: 640px; margin: 0 auto; padding: 28px 20px; }
.page-narrow h2 { margin-bottom: 16px; }
.panel {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.panel h3 { font-size: 15px; margin-bottom: 12px; }
.stack-form { display: flex; flex-direction: column; gap: 6px; }
.stack-form label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-top: 6px; }
.stack-form input[type=text], .stack-form input[type=password] {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.stack-form input[type=color] { width: 60px; height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.stack-form button { margin-top: 14px; align-self: flex-start; }

.simple-table { width: 100%; border-collapse: collapse; }
.simple-table th, .simple-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.simple-table th { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13.5px; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success-text); }

.text-muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .board-wrap { padding: 12px; }
  .board, .add-board-btn { width: 82vw; min-width: 82vw; }
  .modal-overlay { padding: 0; }
  .modal { max-width: 100%; min-height: 100vh; border-radius: 0; }
  .topbar { padding: 10px 12px; }
  .topbar-left h1 { font-size: 15px; }
  .me span:last-child { display: none; }
}
