* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #101828;
  --sidebar-text: #cbd5e1;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e4e8ef;
  --text: #1d2939;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #059669;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

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

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 16px; }
.brand-icon { font-size: 26px; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; }
.brand-sub { font-size: 11px; color: #94a3b8; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; flex: 1; }
#nav button {
  all: unset; cursor: pointer; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; color: var(--sidebar-text); transition: background .15s;
}
#nav button:hover { background: rgba(255,255,255,.07); }
#nav button.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 14px 16px; font-size: 11px; color: #64748b; }
.online-users { padding: 10px 16px 0; border-top: 1px solid rgba(255,255,255,.08); margin-top: 4px; }
.online-users:empty { display: none; padding: 0; border: none; margin: 0; }
.online-title { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }
.online-person { font-size: 12.5px; color: var(--sidebar-text); padding: 2px 0; display: flex; align-items: center; }
.online-person i { color: #64748b; font-style: normal; margin-left: 4px; }

/* ---------- Nội dung ---------- */
main { flex: 1; min-width: 0; padding: 24px 28px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Nút ---------- */
.btn {
  border: none; cursor: pointer; border-radius: 8px; padding: 9px 14px;
  font-size: 13.5px; font-weight: 600; background: var(--primary); color: #fff;
  transition: background .15s;
  /* Nút dạng link (<a class="btn">, VD nút xuất PDF) mặc định bị gạch chân → bỏ đi cho giống nút thật */
  text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f1f5f9; }
.btn.danger { background: #fee2e2; color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Thẻ ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.card .label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.card .value { font-size: 21px; font-weight: 700; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }
.section-title { font-size: 15px; font-weight: 700; margin: 20px 0 10px; }

/* ---------- Bảng ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.wrap { white-space: normal; }
/* Bảng Đơn hàng: ô Mã máy cắt ngắn tên máy dài (tên đầy đủ ở ô dịch vụ), ô dịch vụ gom theo máy */
td.dev-cell .dev-code { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.svc-cell { min-width: 240px; max-width: 420px; }
.svc-line { margin-bottom: 7px; }
.svc-line:last-child { margin-bottom: 0; }
.svc-dev { font-size: 11.5px; color: var(--muted); font-weight: 600; max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.right { text-align: right; }
.money-in { color: var(--green); font-weight: 600; }
.money-out { color: var(--red); font-weight: 600; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Badge ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.new { background: #eff6ff; color: #1d4ed8; }
.badge.processing, .badge.doing { background: #fffbeb; color: var(--amber); }
.badge.done { background: #ecfdf5; color: var(--green); }
.badge.hanoi { background: #fef3c7; color: #b45309; }
.badge.delivered { background: #f0fdfa; color: #0d9488; }
.badge.cancelled { background: #fef2f2; color: var(--red); }
.badge.todo { background: #f1f5f9; color: var(--muted); }
.badge.telegram { background: #eff6ff; color: #1d4ed8; }
.badge.web { background: #f1f5f9; color: var(--muted); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.kanban-col { background: #eef1f6; border-radius: var(--radius); padding: 10px; min-height: 180px; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); }
.kanban-col h3 { font-size: 13px; color: var(--muted); padding: 4px 6px 10px; text-transform: uppercase; letter-spacing: .04em; }
.task-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
}
.task-card:hover { border-color: var(--primary); }
.task-card .t-title { font-weight: 600; margin-bottom: 6px; }
.task-card .t-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.progress { height: 6px; background: #e4e8ef; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 99px; transition: width .2s; }
.progress > div.full { background: var(--green); }
.t-progress-label { font-size: 11.5px; color: var(--muted); margin-top: 4px; text-align: right; }

/* ---------- Form ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
/* Ô tick/radio KHÔNG được ăn width:100% ở trên — nếu không nó phình ra cả dòng và đẩy
   chữ nhãn văng sang phải (nhìn như bị nhảy dòng). */
input[type="checkbox"], input[type="radio"] {
  width: auto; flex: 0 0 auto; padding: 0; margin: 0;
  accent-color: var(--primary); cursor: pointer;
}
/* Ẩn 2 mũi tên tăng/giảm của ô nhập số — bấm nhầm là đổi số lượng/số tiền lúc nào không hay.
   Chỉ cho nhập bằng bàn phím (cuộn chuột cũng đã chặn trong app.js). */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.form-row { display: flex; gap: 10px; }
.form-row > * { flex: 1; }
/* Nhóm các ô đánh dấu của đơn hàng thành 1 khối gọn, mỗi dòng 1 mục cho dễ đọc */
.check-group {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2px 14px; margin-bottom: 16px; background: var(--card);
}
.check-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  font-size: 13.5px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.check-row:last-child { border-bottom: none; }
.check-row:hover { color: var(--primary); }
.check-when { color: var(--muted); font-size: 12.5px; font-weight: 400; }
select.inline-status { width: auto; padding: 5px 8px; font-size: 12.5px; border-radius: 99px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.5);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.wide { max-width: 1100px; }
.order-grid { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 28px; align-items: start; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-close { all: unset; cursor: pointer; font-size: 20px; color: var(--muted); padding: 0 4px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- Item rows trong đơn hàng ---------- */
.item-row { display: grid; grid-template-columns: 1fr 70px 130px 30px; gap: 8px; margin-bottom: 8px; align-items: center; }
.item-row .del-item { all: unset; cursor: pointer; color: var(--red); text-align: center; font-size: 16px; }
.order-total { text-align: right; font-weight: 700; margin: 8px 0 14px; }

/* ---------- Hộp chọn dịch vụ 3 bước trong đơn hàng ---------- */
/* Nhóm theo mã máy (1 đơn có thể nhiều máy, mỗi máy nhiều dòng dịch vụ) bọc ngoài các .svc-item */
.svc-group { border: 1.5px solid var(--primary, #2563eb); border-radius: 10px; padding: 10px; margin-bottom: 12px; background: rgba(37, 99, 235, .04); }
.svc-item { border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 10px; margin-bottom: 10px; background: var(--card-bg, #fff); }
.svc-group .svc-item:last-child { margin-bottom: 0; }
.svc-item .del-item, .svc-group > div > .del-item { all: unset; cursor: pointer; color: var(--red); text-align: center; font-size: 16px; padding: 0 4px; }

/* ---------- Báo cáo ---------- */
.report-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.report-item { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.report-item:last-child { border-bottom: none; }
.report-item .r-meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------- Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.dash-grid .span2 { grid-column: 1 / -1; }
.dash-grid .chart-card { margin-bottom: 0; }
@media (max-width: 1000px) { .dash-grid { grid-template-columns: 1fr; } }
.delta { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; }
.delta.up { background: #ecfdf5; color: var(--green); }
.delta.down { background: #fef2f2; color: var(--red); }
.delta.flat { background: #f1f5f9; color: var(--muted); }
.hbar-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 13px; }
.hbar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: #eef1f6; border-radius: 99px; height: 14px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 99px; min-width: 2px; }
.hbar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.status-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.status-row:last-child { border-bottom: none; }
.status-row b { font-size: 15px; }

/* ---------- Biểu đồ ---------- */
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 22px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.chart-head h2 { font-size: 15px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 99px; margin-right: 5px; vertical-align: -1px; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg .bar { cursor: pointer; }
.chart-svg .bar:hover { opacity: .8; }
.chart-svg text { font-family: inherit; }
#viz-tooltip {
  position: fixed; pointer-events: none; z-index: 90;
  background: var(--sidebar-bg); color: #fff; padding: 7px 11px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.5; opacity: 0; transition: opacity .1s;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
#viz-tooltip.show { opacity: 1; }
.perf-good { color: var(--green); font-weight: 700; }
.perf-mid { color: var(--amber); font-weight: 700; }
.perf-low { color: var(--red); font-weight: 700; }

/* ---------- Đăng nhập ---------- */
body.auth-mode .layout { display: none; }
#auth-root .auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #101828 0%, #1d3a6e 100%); padding: 20px;
}
.auth-box {
  background: var(--card); border-radius: 16px; padding: 32px 30px;
  width: 100%; max-width: 400px; box-shadow: 0 24px 64px rgba(0,0,0,.35);
}
.auth-box .auth-logo { text-align: center; font-size: 40px; }
.auth-box h1 { text-align: center; font-size: 19px; margin: 6px 0 2px; }
.auth-box .auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.auth-box .btn { width: 100%; padding: 11px; font-size: 14.5px; margin-top: 4px; }
.auth-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }

/* ---------- Người dùng ở sidebar ---------- */
.user-chip { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.user-chip .u-name { color: #fff; font-weight: 600; font-size: 13px; }
.user-chip .u-role { font-size: 11px; color: #94a3b8; margin-bottom: 8px; }
.user-chip .u-lan { font-size: 11px; color: #64748b; margin-bottom: 8px; word-break: break-all; }
.user-chip button {
  all: unset; cursor: pointer; font-size: 12px; color: #cbd5e1;
  border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: 4px 10px;
}
.user-chip button:hover { background: rgba(255,255,255,.1); }

/* ---------- Trễ hạn ---------- */
.task-card.overdue { border-color: var(--red); background: #fff7f7; }
.badge.overdue { background: #fef2f2; color: var(--red); }
.card.alert-card { border-color: #fecaca; background: #fff7f7; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--sidebar-bg); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 100;
}
#toast.show { opacity: 1; }

/* ---------- Hướng dẫn telegram ---------- */
.guide { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-top: 16px; line-height: 1.7; }
.guide code { background: #f1f5f9; padding: 2px 7px; border-radius: 6px; font-size: 13px; }
.guide ol { padding-left: 20px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 99px; margin-right: 6px; }
.status-dot.on { background: var(--green); }
.status-dot.off { background: var(--red); }

@media (max-width: 900px) {
  .kanban { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .order-grid { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- Dải cảnh báo BẢN CHẠY THỬ (chỉ hiện khi chạy với PHL_TRIAL=1) ---------- */
body.trial-mode::before {
  content: "⚠️ BẢN CHẠY THỬ — dữ liệu ở đây KHÔNG phải dữ liệu thật và sẽ bị xóa. Nhập liệu thật vẫn dùng bản trên MacBook.";
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: #b91c1c; color: #fff; font-weight: 700; font-size: 13px;
  text-align: center; padding: 8px 14px; line-height: 1.4;
}
body.trial-mode { padding-top: 36px; }
body.trial-mode .sidebar { top: 36px; }
