:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dfe1e6;
  --text: #172b4d;
  --text-muted: #5e6c84;
  --primary: #0052cc;
  --primary-hover: #0747a6;
  --danger: #de350b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(9, 30, 66, 0.15), 0 0 1px rgba(9, 30, 66, 0.2);
}

* { box-sizing: border-box; }

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

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  display: block;
  height: 44px;
  width: auto;
  margin: 0 auto 16px;
}

.auth-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.auth-card p.sub {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 14px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #ebecf0; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #bf2600; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
  min-height: 16px;
}

.switch-link {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.switch-link a { color: var(--primary); text-decoration: none; cursor: pointer; }

/* ---------- Board layout ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-logo {
  height: 26px;
  width: auto;
  display: block;
}

.topbar .right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-email {
  font-size: 13px;
  color: var(--text-muted);
}

.icon-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn:hover { background: var(--primary-hover); }

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

.board {
  display: flex;
  gap: 14px;
  padding: 16px;
  overflow-x: auto;
  align-items: flex-start;
  min-height: calc(100vh - 60px);
}

.column {
  background: #ebecf0;
  border-radius: var(--radius);
  width: 280px;
  min-width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 92px);
}

.column-header {
  padding: 12px 12px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.column-count {
  background: #dfe1e6;
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 12px;
}

.column-body {
  padding: 0 8px 8px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.column-body.drag-over {
  background: #dcdff2;
  border-radius: 6px;
}

.card {
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: grab;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.4; }
.card.overdue-card { border-left-color: var(--danger); }

.card .khach-hang {
  font-weight: 700;
}

.add-card-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  text-align: left;
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
}
.add-card-btn:hover { background: #dfe1e6; color: var(--text); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 30, 66, 0.54);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
}

/* Modal dùng flexbox: phần nội dung cuộn riêng, thanh nút luôn nằm cố định
   ở đáy hộp thoại theo luồng bình thường (không dùng position:fixed) để
   tránh lỗi hiển thị/hở khoảng trống trên trình duyệt di động. */
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-scroll {
  padding: 24px;
  overflow-y: auto;
}

.modal-scroll h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.modal-row {
  display: flex;
  gap: 12px;
}
.modal-row .field { flex: 1; }

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-actions .btn, .modal-actions .btn-secondary, .modal-actions .btn-danger {
  width: auto;
  flex: 1;
}

/* ---------- Khung trao đổi dạng chat ---------- */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;
  padding: 10px;
  background: #f4f5f7;
  border-radius: 8px;
  margin-bottom: 4px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}
.chat-msg.own { align-self: flex-end; align-items: flex-end; }
.chat-msg.other { align-self: flex-start; align-items: flex-start; }

.chat-msg .chat-sender {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 4px 2px;
}

.chat-bubble {
  border-radius: 14px;
  padding: 8px 12px;
  font-size: 13px;
  word-break: break-word;
}
.chat-msg.own .chat-bubble { background: var(--primary); color: white; border-bottom-right-radius: 4px; }
.chat-msg.other .chat-bubble { background: #ebecf0; color: var(--text); border-bottom-left-radius: 4px; }

.chat-bubble img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}
.chat-bubble img + .chat-caption { margin-top: 6px; }

.chat-msg .chat-time {
  font-size: 10px;
  color: var(--text-muted);
  margin: 2px 4px 0;
}

.chat-msg .remove-msg-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  margin: 2px 4px 0;
  padding: 0;
}

.chat-msg.uploading .chat-bubble { color: var(--text-muted); font-style: italic; }

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input-row input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
}
.chat-input-row .btn { width: auto; padding: 10px 18px; border-radius: 20px; }
.chat-attach-btn {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
}

.hint-msg {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

/* ---------- Gợi ý khách hàng cũ ---------- */
.autocomplete-wrap { position: relative; }

.suggestions-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
}

.suggestions-list li {
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.suggestions-list li:hover,
.suggestions-list li.active {
  background: #ebecf0;
}
.suggestions-list li .s-name { font-weight: 600; }
.suggestions-list li .s-phone { color: var(--text-muted); margin-left: 6px; }

/* ---------- Quản lý người dùng ---------- */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-row .u-email { font-size: 13px; word-break: break-all; }
.user-row .u-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
  white-space: nowrap;
}
.u-badge.cho_duyet { background: #fff0b3; color: #7a5d00; }
.u-badge.nhan_vien { background: #e6f0ff; color: var(--primary); }
.u-badge.admin { background: #d3f5e0; color: #006644; }
.user-row select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.hidden { display: none !important; }

.loading-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .topbar h1 { font-size: 15px; }
  .topbar .right { gap: 8px; flex-wrap: wrap; }
  .user-email { display: none; }

  .board { padding: 10px; gap: 10px; }
  .column { width: 78vw; min-width: 220px; max-width: 300px; }

  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
  .modal-scroll { padding: 16px; }
  .modal-row { flex-direction: column; gap: 0; }

  .modal-actions {
    padding: 12px 16px;
    box-shadow: 0 -2px 6px rgba(9, 30, 66, 0.15);
  }

  /* Chữ trong ô nhập tối thiểu 16px để iPhone không tự phóng to trang khi bấm vào */
  .field input, .field select, .field textarea, .chat-input-row input[type="text"] {
    font-size: 16px;
  }

  .chat-input-row { padding: 10px 16px; }
  .chat-msg { max-width: 88%; }

  .btn, .icon-btn { min-height: 44px; }
}

@media (max-width: 380px) {
  .column { width: 84vw; }
}
