/* ============ Cổng yêu cầu — bộ giao diện dùng chung ============ */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --border: #e5e7f0;
  --border-strong: #d3d7e4;
  --text: #1e2333;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --primary-dark: #4338ca;
  --accent: #0d9488;
  --danger: #e11d48;
  --warn: #d97706;
  --ok: #059669;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .16);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c; --surface: #1a1d27; --surface-2: #20242f; --border: #2b3040; --border-strong: #3a4055;
    --text: #e8eaf2; --muted: #9aa1b4; --primary: #8b86ff; --primary-soft: #262a45; --primary-dark: #a5a1ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -16px rgba(0,0,0,.7); --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .35em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
p { margin: .35em 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.tiny { font-size: .76rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- khung trang công khai ---------- */
.pub-wrap { max-width: 780px; margin: 0 auto; padding: 28px 18px 72px; }
.pub-head { text-align: center; margin-bottom: 22px; }
.pub-head .badge-soft {
  display: inline-block; background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 999px; padding: 4px 12px; font-size: .8rem; font-weight: 600; letter-spacing: .02em;
}
.pub-head h1 { margin-top: 12px; }
.pub-head p { color: var(--muted); max-width: 560px; margin: 6px auto 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.card + .card { margin-top: 16px; }
.card-flat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; }

/* ---------- biểu mẫu ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span.lb { display: block; font-weight: 600; font-size: .89rem; margin-bottom: 6px; }
label.field > span.lb .req { color: var(--danger); margin-left: 2px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-left: 6px; }
input[type=text], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
textarea { resize: vertical; min-height: 110px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 620px) { .grid2 { grid-template-columns: 1fr; } }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-radio { position: relative; }
.chip-radio input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip-radio span {
  display: inline-block; padding: 7px 13px; border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: .87rem; cursor: pointer; background: var(--surface); transition: all .12s;
}
.chip-radio input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.chip-radio input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 10px 17px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .06s, background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: .84rem; border-radius: 8px; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* danh sách tệp */
.file-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.file-item { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: .85rem; }

/* thông báo */
.alert { border-radius: var(--radius-sm); padding: 11px 14px; font-size: .9rem; border: 1px solid; margin-bottom: 14px; }
.alert-err { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); }
.alert-ok { background: color-mix(in srgb, var(--ok) 8%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); color: var(--ok); }
.alert-info { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 25%, var(--border)); color: var(--primary-dark); }
.color-danger { color: var(--danger); } .color-warn { color: var(--warn); } .color-ok { color: var(--ok); }

/* huy hiệu */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: .76rem; font-weight: 650; border: 1px solid transparent; white-space: nowrap; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-soft { background: var(--surface-2); border-color: var(--border); color: var(--muted); font-weight: 600; }

/* mã yêu cầu */
.code-box {
  display: flex; align-items: center; gap: 10px; background: var(--primary-soft); border: 1px dashed color-mix(in srgb, var(--primary) 45%, var(--border));
  border-radius: var(--radius-sm); padding: 12px 14px; margin: 12px 0;
}
.code-box .code { font-family: var(--mono); font-size: 1.35rem; font-weight: 700; letter-spacing: .06em; color: var(--primary-dark); }

/* tiến trình trạng thái */
.steps { display: flex; align-items: flex-start; gap: 0; margin: 18px 0 6px; }
.step { flex: 1; text-align: center; position: relative; }
.step .dot { width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 7px; display: grid; place-items: center;
  background: var(--surface-2); border: 2px solid var(--border-strong); color: var(--muted); font-size: .76rem; font-weight: 700; }
.step .nm { font-size: .78rem; color: var(--muted); }
.step.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done .nm { color: var(--text); font-weight: 600; }
.step.active .dot { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
.step.active .nm { color: var(--primary-dark); font-weight: 650; }
.step::before { content: ''; position: absolute; top: 13px; left: -50%; width: 100%; height: 2px; background: var(--border-strong); z-index: 0; }
.step:first-child::before { display: none; }
.step.done::before, .step.active::before { background: var(--ok); }
.step .dot, .step .nm { position: relative; z-index: 1; }

/* dòng thời gian */
.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong); }
.timeline li.k-status::before { border-color: var(--primary); }
.timeline li.k-created::before { border-color: var(--ok); background: var(--ok); }
.timeline li.k-reply::before { border-color: var(--accent); background: var(--accent); }
.timeline li.k-note::before { border-color: var(--warn); background: var(--warn); }
.timeline li.k-due::before { border-color: var(--warn); }
.timeline .when { font-size: .76rem; color: var(--muted); }
.timeline .txt { font-size: .92rem; }
.timeline li.private { opacity: .8; }
.timeline li.private .txt::after { content: ' · riêng tư'; font-size: .74rem; color: var(--warn); font-weight: 600; }

/* hộp tra cứu + thông tin */
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 550; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dt { margin-top: 6px; } }

/* ---------- khu quản trị ---------- */
.adm-top { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.adm-top .inner { max-width: 1500px; margin: 0 auto; padding: 10px 18px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab { padding: 7px 13px; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .89rem; cursor: pointer; white-space: nowrap; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.on { background: var(--primary-soft); color: var(--primary-dark); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.adm-body { max-width: 1500px; margin: 0 auto; padding: 16px 18px 80px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow-sm); }
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.warn .n { color: var(--warn); } .stat.danger .n { color: var(--danger); } .stat.ok .n { color: var(--ok); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; min-width: 130px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.panel-body { padding: 14px 16px; }

/* todo */
.todo-group { margin-bottom: 18px; }
.todo-group > h3 { display: flex; align-items: center; gap: 8px; font-size: .95rem; margin-bottom: 8px; }
.todo-group > h3 .cnt { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; font-size: .78rem; color: var(--muted); }
.todo-item { display: flex; gap: 12px; align-items: flex-start; padding: 11px 13px; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--border-strong); border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer; transition: box-shadow .15s, transform .06s; }
.todo-item:hover { box-shadow: var(--shadow); }
.todo-item .t { font-weight: 600; }
.todo-item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 250px; }

/* kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(248px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); min-height: 140px; display: flex; flex-direction: column; }
.kcol-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: .88rem; position: sticky; top: 0; }
.kcol-head .bar { width: 9px; height: 9px; border-radius: 3px; }
.kcol-head .cnt { margin-left: auto; color: var(--muted); font-size: .8rem; }
.kcol-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 80px; }
.kcol.over { outline: 2px dashed var(--primary); outline-offset: -3px; background: var(--primary-soft); }
.kcard { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 11px; cursor: grab; box-shadow: var(--shadow-sm); }
.kcard:hover { box-shadow: var(--shadow); }
.kcard.dragging { opacity: .45; }
.kcard .t { font-weight: 620; font-size: .9rem; margin-bottom: 5px; }
.kcard .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: .76rem; color: var(--muted); }

/* gantt */
.gantt-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.gantt { min-width: 100%; position: relative; }
.g-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.g-row:hover .g-label { background: var(--surface-2); }
.g-label { width: 300px; min-width: 300px; padding: 8px 12px; border-right: 1px solid var(--border); font-size: .85rem; background: var(--surface); position: sticky; left: 0; z-index: 3; }
.g-track { position: relative; flex: 1; min-height: 36px; }
.g-bar { position: absolute; top: 9px; height: 18px; border-radius: 9px; display: flex; align-items: center; padding: 0 8px;
  font-size: .74rem; color: #fff; white-space: nowrap; overflow: hidden; cursor: pointer; box-shadow: var(--shadow-sm); }
.g-bar.late { outline: 2px solid var(--danger); }
.g-head { display: flex; position: sticky; top: 0; z-index: 4; background: var(--surface); border-bottom: 1px solid var(--border); }
.g-head .g-label { font-weight: 650; }
.g-days { position: relative; flex: 1; height: 34px; }
.g-day { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); font-size: .68rem; color: var(--muted); padding: 2px 0 0 3px; }
.g-day.weekend { background: color-mix(in srgb, var(--muted) 7%, transparent); }
.g-day.today { border-left: 2px solid var(--danger); }
.g-today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); z-index: 2; pointer-events: none; }

/* lịch */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-dow { text-align: center; font-size: .78rem; color: var(--muted); font-weight: 650; padding: 4px 0; }
.cal-cell { min-height: 104px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.cal-cell:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.cal-cell.out { opacity: .45; }
.cal-cell.today { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent); }
.cal-cell .dnum { font-size: .8rem; font-weight: 650; color: var(--muted); margin-bottom: 4px; }
.cal-cell.today .dnum { color: var(--primary-dark); }
.cal-ev { font-size: .72rem; padding: 2px 5px; border-radius: 5px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.cal-more { font-size: .7rem; color: var(--muted); }

/* bảng danh sách */
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl tr:hover td { background: var(--surface-2); cursor: pointer; }
.tbl-wrap { overflow: auto; max-height: 72vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

/* ngăn chi tiết */
.drawer-bg { position: fixed; inset: 0; background: rgba(15, 18, 30, .45); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); background: var(--bg); z-index: 61; box-shadow: -12px 0 40px rgba(0,0,0,.22); display: flex; flex-direction: column; }
.drawer-head { padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; align-items: center; }
.drawer-body { overflow: auto; padding: 16px 18px 60px; flex: 1; }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; align-items: center; }
.sect { margin-bottom: 18px; }
.sect > h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* đăng nhập */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); }

/* toast */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1e2333; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .87rem; box-shadow: var(--shadow); animation: tin .2s ease-out; }
.toast.err { background: var(--danger); } .toast.ok { background: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: .9rem; }

/* ---------- điện thoại (≤ 700px) ---------- */
@media (max-width: 700px) {
  .adm-top .inner { padding: 8px 12px; gap: 8px 10px; }
  .tabs { flex-wrap: wrap; overflow: visible; }
  .tab { padding: 6px 10px; font-size: .84rem; border-radius: 8px; }
  .adm-body { padding: 12px 12px 70px; }
  .toolbar input[type=search] { max-width: none; width: 100%; }
  /* việc cần làm: chữ chiếm trọn dòng, các nút xuống hàng dưới */
  .todo-item { flex-wrap: wrap; align-items: flex-start; }
  .todo-item .grow { flex: 1 1 calc(100% - 34px); }
  .todo-item .acts { flex: 1 1 100%; max-width: none; justify-content: flex-start; margin-left: 26px; }
  /* bảng danh sách: giữ cột đọc được rồi cuộn ngang */
  .tbl-wrap { -webkit-overflow-scrolling: touch; }
  .tbl { min-width: 680px; }
  .tbl td:nth-child(2) { min-width: 220px; }
  .drawer { width: 100vw !important; }
  .kanban { grid-auto-columns: minmax(232px, 1fr); }
}
