:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --primary: #7c9a92;
  --primary-dark: #62807a;
  --primary-grad: #93b0a9;
  --primary-soft: #e7efec;
  --accent: #8f9bc9;
  --accent-soft: #eef0f9;
  --accent-deep: #6b77a5;
  --warn: #b98a4d;
  --warn-soft: #f8eeda;
  --warn-text: #8a642f;
  --warn-border: #ecd9b4;
  --danger: #d07a74;
  --danger-soft: #fbe9e7;
  --success: #6d9d7c;
  --success-soft: #e7f2ea;
  --info: #6f93b8;
  --info-soft: #e8f0f9;
  --text: #413d37;
  --muted: #8f8a81;
  --border: #ece7de;
  --input: #ffffff;
  --hover: #faf8f3;
  --line: #f3efe8;
  --glass: rgba(255, 255, 255, .75);
  --glass-strong: rgba(255, 255, 255, .85);
  --glow1: #e7efec;
  --glow2: #f8eee4;
  --shadow: 0 10px 30px rgba(93, 110, 100, 0.10);
  --radius: 16px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #14161b;
  --surface: #1e2128;
  --primary: #7fa79c;
  --primary-dark: #a7c7bf;
  --primary-grad: #6b9189;
  --primary-soft: #26312f;
  --accent: #97a1d0;
  --accent-soft: #262a3b;
  --accent-deep: #b3bce6;
  --warn: #cfa463;
  --warn-soft: #362f22;
  --warn-text: #e3bd7e;
  --warn-border: #4a3f29;
  --danger: #e0867f;
  --danger-soft: #3a2726;
  --success: #7fb794;
  --success-soft: #21322a;
  --info: #82a8d0;
  --info-soft: #22303d;
  --text: #e8e6e1;
  --muted: #97928a;
  --border: #2c3038;
  --input: #24272f;
  --hover: #262a32;
  --line: #292d35;
  --glass: rgba(30, 33, 40, .8);
  --glass-strong: rgba(30, 33, 40, .88);
  --glow1: #1d2b2a;
  --glow2: #2b2320;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 85% -5%, var(--glow1) 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 10%, var(--glow2) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
h1, h2, h3, h4 { font-weight: 650; }
.subtle { color: var(--muted); font-size: .85rem; }

/* ---------- Nút ---------- */
.btn {
  border: none; cursor: pointer; border-radius: 12px;
  padding: 10px 18px; font-size: .9rem; font-weight: 600;
  transition: transform .12s, box-shadow .15s, background .15s;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-soft); color: var(--primary-dark);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(93,110,100,.14); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-grad)); color: #fff; }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(124,154,146,.35); }
.btn-ghost { background: transparent; color: var(--primary-dark); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { box-shadow: 0 6px 16px rgba(208,122,116,.2); }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 10px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- Input ---------- */
.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--input);
  font-size: .9rem;
  color: var(--text);
  outline: none;
  transition: border .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
textarea.input { resize: vertical; min-height: 90px; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 14px; color: var(--text); }
label > .input, label > select { margin-top: 6px; }

/* ---------- Đăng nhập ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 400px; max-width: 100%;
  background: var(--glass-strong);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 1.3rem; margin-top: 10px; }
.logo-badge {
  width: 60px; height: 60px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 10px 22px rgba(124,154,146,.35);
}
.logo-badge.small { width: 38px; height: 38px; font-size: 18px; border-radius: 12px; }
.form-error { color: var(--danger); font-size: .83rem; min-height: 18px; margin-bottom: 6px; }
.login-hint { text-align: center; margin-top: 18px; font-size: .8rem; color: var(--muted); }

/* ---------- Bố cục chính ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 235px; flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: blur(6px);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.brand b { display: block; font-size: .98rem; }
.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: none; background: transparent;
  border-radius: 12px;
  font-size: .92rem; font-weight: 600; color: var(--text);
  cursor: pointer;
  transition: background .15s, color .15s;
  text-align: left;
}
.nav-item:hover { background: var(--primary-soft); }
.nav-item.active { background: linear-gradient(135deg, var(--primary), var(--primary-grad)); color: #fff; box-shadow: 0 6px 14px rgba(124,154,146,.3); }
.nav-ico { width: 22px; text-align: center; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 4px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(6px);
}
.topbar-title h2 { font-size: 1.25rem; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); padding: 6px 14px 6px 6px;
  border-radius: 999px; border: 1px solid var(--border);
  font-size: .88rem; font-weight: 600;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.content { padding: 26px 28px 48px; display: flex; flex-direction: column; gap: 22px; }
.view { display: flex; flex-direction: column; gap: 22px; }

/* ---------- Thẻ thống kê ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px;
  transition: transform .15s;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-ico {
  width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  flex-shrink: 0;
}
.stat-body .stat-val { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-body .stat-lbl { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat-ico.teal { background: var(--success-soft); }
.stat-ico.sage { background: var(--primary-soft); }
.stat-ico.ind { background: var(--accent-soft); }
.stat-ico.warn { background: var(--warn-soft); }
.stat-ico.red { background: var(--danger-soft); }
.stat-ico.blue { background: var(--info-soft); }

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 1rem; }
.panel-row { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .panel-row { grid-template-columns: 1fr; } .sidebar { width: 74px; } .brand > div:last-child, .nav-item span:last-child { display:none; } .nav-item { justify-content: center; } }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 12px 20px; text-align: left; white-space: nowrap; }
thead th {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--line); transition: background .1s; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child { border-bottom: none; }
.td-main b { display: block; font-size: .92rem; }
.td-sub { font-size: .8rem; color: var(--muted); }
.text-right { text-align: right; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Badge trạng thái ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 999px;
  font-size: .78rem; font-weight: 700;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending { background: var(--info-soft); color: var(--info); }
.badge-repairing { background: var(--accent-soft); color: var(--accent-deep); }
.badge-waiting_parts { background: var(--warn-soft); color: var(--warn); }
.badge-cannot_repair { background: var(--danger-soft); color: var(--danger); }
.badge-fixed { background: var(--success-soft); color: var(--success); }
.badge-delivered { background: var(--primary-soft); color: var(--primary-dark); }
.badge-warn { background: var(--warn-soft); color: var(--warn-text); }
.badge-red { background: var(--danger-soft); color: var(--danger); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.toolbar-left { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar-left .input { width: auto; min-width: 200px; }

/* ---------- Phân trang ---------- */
.pagination { display: flex; gap: 6px; justify-content: flex-end; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); }
.pagination .pg-info { font-size: .82rem; color: var(--muted); margin-right: auto; }
.pg-btn {
  min-width: 34px; height: 34px;
  border: 1px solid var(--border); background: var(--input); border-radius: 10px;
  cursor: pointer; font-weight: 600; font-size: .85rem;
}
.pg-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-dark); }
.pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(70, 80, 76, .35);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.18);
  width: 560px; max-width: 100%;
  animation: pop .18s ease-out;
}
.modal.wide { width: 880px; }
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.05rem; }
.modal-close {
  border: none; background: var(--primary-soft); color: var(--primary-dark);
  width: 30px; height: 30px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.modal-body { padding: 22px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Upload ---------- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 22px; text-align: center;
  color: var(--muted); cursor: pointer;
  transition: background .15s, border .15s;
  font-size: .88rem;
}
.drop-zone:hover { border-color: var(--primary); background: var(--primary-soft); }
.media-preview {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px;
}
.media-thumb {
  position: relative; width: 86px; height: 86px;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--border);
}
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .video-tag {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: 10px; font-weight: 700; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.6));
  padding: 12px 6px 4px; text-align: center;
}
.media-thumb .del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 8px;
  border: none; cursor: pointer; font-size: 12px; line-height: 1;
  background: rgba(0,0,0,.55); color: #fff;
}
.media-thumb .del:hover { background: var(--danger); }
.media-note { font-size: .75rem; color: var(--muted); margin-top: 8px; }

/* ---------- Thư viện media chi tiết ---------- */
.gallery { display: flex; gap: 12px; flex-wrap: wrap; }
.gallery-item {
  width: 130px; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border); background: var(--hover);
  position: relative;
}
.gallery-item img, .gallery-item video { width: 100%; height: 120px; object-fit: cover; display: block; }
.gallery-item .g-label {
  font-size: .72rem; color: var(--muted); padding: 6px 8px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.gallery-item .g-del {
  border: none; cursor: pointer; background: var(--danger-soft); color: var(--danger);
  border-radius: 8px; padding: 2px 8px; font-size: .7rem; font-weight: 700;
}

/* ---------- Cảnh báo ---------- */
.alert-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--warn-soft); border: 1px solid var(--warn-border);
  color: var(--warn-text); border-radius: 14px;
  padding: 13px 16px; font-weight: 600; font-size: .9rem;
}
.alert-bar.info { background: var(--info-soft); border-color: var(--border); color: var(--info); }
.alert-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  font-size: .86rem; cursor: pointer;
}
.alert-item:last-child { border-bottom: none; }
.alert-item:hover { background: var(--hover); }
.alert-item .a-ico { font-size: 16px; }
.alert-item b { display: block; font-size: .88rem; }
.alert-item .a-sub { color: var(--muted); font-size: .76rem; }
.alert-list { max-height: 400px; overflow-y: auto; }

/* ---------- Biểu đồ ---------- */
.chart-wrap { padding: 18px 22px 22px; }
canvas { width: 100%; }

/* ---------- Toast ---------- */
#toastBox { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border-left: 5px solid var(--primary);
  padding: 12px 18px; border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,.16);
  font-size: .88rem; font-weight: 600;
  animation: slideIn .25s ease-out;
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Chi tiết phiếu ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin: 6px 0 16px; font-size: .9rem; }
.detail-grid .full { grid-column: 1 / -1; }
.detail-grid .k { color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.detail-grid .v { font-weight: 600; margin-top: 2px; }
.detail-section { margin-top: 14px; }
.detail-section h4 { font-size: .9rem; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
/* ---------- Nút đổi giao diện + chip người dùng ---------- */
.theme-toggle { padding: 8px 12px; font-size: 1rem; border-radius: 999px; }
.user-chip .user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-chip .user-role { font-size: .72rem; color: var(--muted); font-weight: 600; }
.role-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.role-admin { background: var(--primary-soft); color: var(--primary-dark); }
.role-technician { background: var(--accent-soft); color: var(--accent-deep); }
.role-accountant { background: var(--warn-soft); color: var(--warn-text); }

/* ---------- Kanban ---------- */
.kanban-board {
  display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start;
}
.kan-col {
  flex: 1 0 240px; min-width: 240px; max-width: 300px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: calc(100vh - 210px);
  transition: border .15s, background .15s;
}
.kan-col.over { border-color: var(--primary); background: var(--primary-soft); }
.kan-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.kan-col-head .kc-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .88rem; }
.kan-col-head .kc-count {
  background: var(--hover); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 9px; font-size: .74rem; font-weight: 700; color: var(--muted);
}
.kan-col-head .kc-add {
  border: none; background: var(--primary-soft); color: var(--primary-dark);
  width: 24px; height: 24px; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 14px;
}
.kan-col-head .kc-add:hover { background: var(--primary); color: #fff; }
.kan-col-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.kan-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; cursor: grab; box-shadow: 0 2px 8px rgba(0,0,0,.04);
  transition: transform .1s, box-shadow .15s, opacity .15s;
}
.kan-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(93,110,100,.16); }
.kan-card.dragging { opacity: .45; cursor: grabbing; }
.kan-card .kc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.kan-card .kc-id { font-size: .74rem; font-weight: 700; color: var(--muted); }
.kan-card .kc-device { font-weight: 650; font-size: .9rem; margin-bottom: 2px; }
.kan-card .kc-cust { font-size: .8rem; color: var(--muted); }
.kan-card .kc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: .76rem; color: var(--muted); }
.kan-card .kc-price { font-weight: 700; color: var(--primary-dark); }
.kan-card .kc-status-sel {
  width: 100%; margin-top: 8px; padding: 5px 8px; font-size: .76rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--input); color: var(--text);
}
.kan-empty { padding: 18px; text-align: center; color: var(--muted); font-size: .8rem; }
@media (max-width: 1000px) {
  .kan-col { flex-basis: 78%; }
}
