/* ============================================================
   Kim Minh — Quản lý & Giao việc
   Chủ đề "sổ sách": nền giấy ấm, mực slate, nhấn vàng Kim Minh.
   ============================================================ */

:root {
  --paper:      #F4F1EA;
  --paper-2:    #EDE8DC;
  --surface:    #FFFFFF;
  --ink:        #16232E;
  --ink-2:      #3C4E5C;
  --ink-3:      #6A7B87;
  --line:       #E2DCCC;
  --line-soft:  #ECE6D8;
  --gold:       #B8862B;
  --gold-soft:  #F3E9CF;

  /* Trạng thái */
  --s-todo:     #6A7B87;   /* Chưa bắt đầu */
  --s-doing:    #2F6FB0;   /* Đang làm */
  --s-review:   #B8862B;   /* Chờ duyệt */
  --s-done:     #2E7D57;   /* Hoàn thành */
  --danger:     #BC3B2E;   /* Quá hạn / cảnh báo */
  --danger-bg:  #FBEAE6;

  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 2px rgba(22,35,46,.05), 0 8px 24px rgba(22,35,46,.06);
  --shadow-sm:  0 1px 2px rgba(22,35,46,.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "SFMono-Regular", "SF Mono", "Cascadia Code", "Consolas", "Roboto Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--ink);
  color: #D8E0E6;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  border-right: 1px solid #0E1720;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 20px; }
.brand-mark {
  width: 42px; height: 42px;
  border-radius: 10px;
  border: 1px solid var(--gold);
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: .5px;
  color: var(--gold);
  background: rgba(184,134,43,.08);
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 17px; font-weight: 700; color: #FFFFFF; letter-spacing: .2px; }
.brand-sub  { font-size: 11px; color: #8EA0AC; text-transform: uppercase; letter-spacing: 1.2px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border: none; background: transparent;
  color: #B7C3CC; text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px; font-weight: 500;
  width: 100%;
  transition: background .12s ease, color .12s ease;
}
.nav-item .nav-ico { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav-item .nav-count {
  margin-left: auto;
  font-family: var(--mono); font-size: 11px;
  background: rgba(255,255,255,.08); color: #C6D0D8;
  padding: 1px 7px; border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #EAF0F4; }
.nav-item.active { background: rgba(184,134,43,.16); color: #FFFFFF; }
.nav-item.active .nav-ico { color: var(--gold); opacity: 1; }
.nav-item.active .nav-count { background: rgba(184,134,43,.28); color: #F3E4C4; }

.sidebar-foot { margin-top: auto; padding: 14px 8px 0; display: flex; flex-direction: column; gap: 3px; border-top: 1px solid rgba(255,255,255,.07); }
.foot-line { font-size: 11px; color: #7C8D99; }
.foot-ver  { font-size: 11px; color: #56656F; font-family: var(--mono); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; background: var(--paper); }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 22px 30px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--paper), var(--paper));
  position: relative;
}
.topbar::after {
  content: ""; position: absolute; left: 0; bottom: -1px; width: 84px; height: 2px;
  background: var(--gold);
}
.topbar-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.topbar-sub { margin: 3px 0 0; font-size: 13px; color: var(--ink-3); }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.view { flex: 1; overflow-y: auto; padding: 24px 30px 40px; outline: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s, box-shadow .12s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: #D2C9B2; background: #FCFBF7; }
.btn:active { transform: translateY(1px); }
.btn .ico { width: 16px; height: 16px; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #1E3040; border-color: #1E3040; }
.btn-gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn-gold:hover { background: #A9791F; border-color: #A9791F; }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-ghost:hover { background: var(--paper-2); border-color: var(--line); }
.btn-danger { color: var(--danger); border-color: #E7C6C1; background: #fff; }
.btn-danger:hover { background: var(--danger-bg); border-color: #E0A79F; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .6px; }
.input, .select, .textarea {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 11px; font-size: 14px; width: 100%;
  font-family: inherit; transition: border-color .12s, box-shadow .12s;
}
.textarea { resize: vertical; min-height: 78px; }
.input:focus, .select:focus, .textarea:focus, .search input:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft);
}
.select { appearance: none; background-image:
  url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%236A7B87' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--ink-3); pointer-events: none; }
.search input { border: 1px solid var(--line); background: var(--surface); border-radius: 20px; padding: 8px 12px 8px 32px; font-size: 13.5px; width: 220px; font-family: inherit; }

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

/* ---------- Toolbar (bộ lọc) ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .grow { flex: 1; }
.chipbar { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: 6px 12px; border-radius: 20px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: all .12s;
}
.chip:hover { border-color: #D2C9B2; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 15px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--ink-3); }
.stat.is-doing::before { background: var(--s-doing); }
.stat.is-done::before  { background: var(--s-done); }
.stat.is-over::before  { background: var(--danger); }
.stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-3); font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 750; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.stat.is-over .stat-value { color: var(--danger); }
.stat-foot { font-size: 12px; color: var(--ink-3); margin-top: 3px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 20px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-head .eyebrow { font-family: var(--mono); font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 1px; }
.panel-body { padding: 6px 8px; }

.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }

/* ---------- Danh sách việc (rows) ---------- */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .1s;
}
.row:hover { background: var(--paper); }
.row + .row { border-top: 1px solid var(--line-soft); }
.row-spine { width: 4px; align-self: stretch; border-radius: 4px; background: var(--ink-3); flex: none; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--ink-3); margin-top: 2px; flex-wrap: wrap; }
.row-id { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.row-right { display: flex; align-items: center; gap: 10px; flex: none; }

/* ---------- Board ---------- */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: start; }
.col { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 120px; transition: background .12s, box-shadow .12s; }
.col.drop-hint { background: var(--gold-soft); box-shadow: inset 0 0 0 2px var(--gold); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 10px; }
.col-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.col-name { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-2); }
.col-count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.col-body { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 9px; }
.col-empty { text-align: center; color: var(--ink-3); font-size: 12px; padding: 14px 8px; border: 1px dashed var(--line); border-radius: var(--radius-sm); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--ink-3);
  border-radius: var(--radius-sm); padding: 11px 12px; box-shadow: var(--shadow-sm);
  cursor: grab; transition: box-shadow .12s, transform .06s;
}
.card:hover { box-shadow: var(--shadow); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: .5; }
.card.overdue { border-left-color: var(--danger); }
.card-id { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); letter-spacing: .3px; }
.card-title { font-weight: 600; font-size: 13.5px; margin: 3px 0 8px; line-height: 1.35; }
.card-foot { display: flex; align-items: center; gap: 8px; justify-content: space-between; }

/* Avatar */
.avatar { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; flex: none; letter-spacing: .2px; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.assignee { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.assignee .name { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.st-todo   { background: #EEF1F3; color: #445562; }
.st-doing  { background: #E7F0F8; color: #235C93; }
.st-review { background: #F6ECD4; color: #8A6317; }
.st-done   { background: #E4F1EA; color: #22694A; }
.badge.due { background: var(--paper-2); color: var(--ink-2); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.badge.due.over { background: var(--danger-bg); color: var(--danger); }
.badge.cat { background: #F0EEE6; color: #5A5138; }
.prio { font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.prio.cao { color: var(--danger); }
.prio.tb  { color: var(--gold); }
.prio.thap{ color: var(--ink-3); }

/* ---------- Bảng nhân viên ---------- */
.emp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.emp-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 12px; }
.emp-top { display: flex; align-items: center; gap: 12px; }
.emp-name { font-weight: 700; font-size: 15px; }
.emp-role { font-size: 12px; color: var(--ink-3); }
.emp-stats { display: flex; gap: 8px; }
.emp-pill { flex: 1; text-align: center; background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 8px 4px; }
.emp-pill .n { font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; }
.emp-pill .t { font-size: 10.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; }
.emp-actions { display: flex; gap: 8px; }

/* Thanh tải công việc (dashboard) */
.load-row { display: flex; align-items: center; gap: 12px; padding: 9px 10px; }
.load-row .name { width: 130px; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { flex: 1; height: 8px; background: var(--paper-2); border-radius: 20px; overflow: hidden; display: flex; }
.bar > span { height: 100%; }
.bar .b-doing { background: var(--s-doing); }
.bar .b-todo  { background: var(--s-todo); opacity: .55; }
.bar .b-review{ background: var(--s-review); }
.load-row .n { width: 34px; text-align: right; font-family: var(--mono); font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 54px 20px; color: var(--ink-3); }
.empty .ico { width: 40px; height: 40px; margin: 0 auto 14px; color: var(--gold); opacity: .9; }
.empty h3 { margin: 0 0 6px; font-size: 16px; color: var(--ink); }
.empty p { margin: 0 auto 18px; max-width: 380px; font-size: 13.5px; }
.empty .actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Modal ---------- */
.modal-scrim { position: fixed; inset: 0; background: rgba(16,25,32,.42); display: grid; place-items: center; padding: 24px; z-index: 50; animation: fade .12s ease; }
.modal {
  background: var(--surface); border-radius: 14px; width: 560px; max-width: 100%;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(16,25,32,.28);
  animation: pop .14s cubic-bezier(.2,.9,.3,1.2);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-head .sub { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.modal-body { padding: 20px; overflow-y: auto; display: grid; gap: 15px; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.icon-btn { border: none; background: transparent; color: var(--ink-3); cursor: pointer; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toast ---------- */
.toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 10px 30px rgba(16,25,32,.3); display: flex; align-items: center; gap: 10px; animation: toast-in .18s ease; }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--s-done); flex: none; }
.toast.warn .dot { background: var(--gold); }
.toast.err .dot { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.muted { color: var(--ink-3); }
.hint { font-size: 12px; color: var(--ink-3); }
.divider { height: 1px; background: var(--line-soft); margin: 4px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .board { grid-template-columns: repeat(2, 1fr); }
  .dash-cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .brand { padding: 0 12px 0 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; margin: 0; gap: 4px; }
  .nav-item { padding: 8px 12px; white-space: nowrap; }
  .nav-item .nav-text { display: none; }
  .nav-count { margin-left: 6px !important; }
  .sidebar-foot { display: none; }
  .board { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .view, .topbar { padding-left: 16px; padding-right: 16px; }
  .search input { width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   Bổ sung cho bản Cloud: đăng nhập, chờ duyệt, phân quyền
   ============================================================ */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 50% -10%, #22384a 0%, var(--ink) 55%); }
.auth-card { width: 400px; max-width: 100%; background: var(--surface); border-radius: 16px;
  box-shadow: 0 30px 70px rgba(8,14,20,.45); overflow: hidden; }
.auth-head { text-align: center; padding: 30px 28px 8px; }
.auth-mark { width: 54px; height: 54px; border-radius: 13px; border: 1px solid var(--gold);
  color: var(--gold); background: rgba(184,134,43,.08); display: grid; place-items: center;
  font-weight: 800; font-size: 20px; margin: 0 auto 14px; letter-spacing: .5px; }
.auth-head h1 { margin: 0; font-size: 20px; }
.auth-head p { margin: 6px 0 0; color: var(--ink-3); font-size: 13px; }
.auth-body { padding: 20px 28px 26px; display: grid; gap: 14px; }
.auth-body .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 14.5px; }
.auth-tabs { display: flex; gap: 4px; background: var(--paper-2); padding: 4px; border-radius: 10px; margin: 0 28px; }
.auth-tab { flex: 1; text-align: center; padding: 8px; border: none; background: transparent; border-radius: 7px;
  font-weight: 600; font-size: 13.5px; color: var(--ink-3); cursor: pointer; }
.auth-tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.auth-err { background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 9px 12px;
  font-size: 13px; display: none; }
.auth-err.show { display: block; }
.auth-foot { text-align: center; font-size: 11.5px; color: var(--ink-3); padding: 0 28px 22px; }

.pending-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--paper); }
.pending-card { width: 440px; max-width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 32px; text-align: center; }
.pending-card .ico { width: 44px; height: 44px; color: var(--gold); margin: 0 auto 14px; }
.pending-card h2 { margin: 0 0 8px; font-size: 18px; }
.pending-card p { margin: 0 auto 18px; color: var(--ink-3); font-size: 13.5px; max-width: 320px; }

.role-badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px; text-transform: uppercase; letter-spacing: .5px; }
.role-admin   { background: var(--gold-soft); color: #8A6317; }
.role-manager { background: #E7F0F8; color: #235C93; }
.role-staff   { background: #EEF1F3; color: #445562; }
.role-pending { background: #F3E7E5; color: #9A4034; }

.userbox { display: flex; align-items: center; gap: 10px; padding: 10px 8px; margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,.07); }
.userbox .who { min-width: 0; }
.userbox .who .nm { font-size: 13px; color: #EAF0F4; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox .who .rl { font-size: 11px; color: #8EA0AC; }
.sync-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-3); }
.sync-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--s-done); }
.sync-dot.off::before { background: var(--danger); }
.role-select { border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; font-size: 12.5px; font-family: inherit; background: var(--surface); }
