:root {
  --ti-bg: #eef2f0;
  --ti-panel: #ffffff;
  --ti-line: #c9d3cf;
  --ti-fg: #16231e;
  --ti-muted: #5a6a64;
  --ti-accent: #0f7a5c;
  --ti-accent-fg: #ffffff;
  --ti-head: #d6e8f5;
  --ti-head-fg: #173a57;
  --ti-head2: #d3ecd0;
  --ti-head2-fg: #1f5a22;
  --ti-hm: #fff3c9;
  --ti-hm-fg: #2e7a2f;
  --ti-band: #f2b8b2;
  --ti-band-fg: #6d1d16;
  --ti-info-bg: #dceafb;
  --ti-info-fg: #1e4f8f;
  --ti-warn-bg: #fde8c8;
  --ti-warn-fg: #8a4b06;
  --ti-bad-bg: #fbdcd8;
  --ti-bad-fg: #a12a1c;
  --ti-ok-bg: #d8f0e2;
  --ti-ok-fg: #1b6b42;
  --ti-sel: #e6f4ee;
  --ti-strike: #8b9893;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ti-bg: #0f171a;
    --ti-panel: #162127;
    --ti-line: #2c3c42;
    --ti-fg: #e4ede9;
    --ti-muted: #93a6a0;
    --ti-accent: #3cbf8c;
    --ti-accent-fg: #06231a;
    --ti-head: #1e3447;
    --ti-head-fg: #c4def2;
    --ti-head2: #1f3a24;
    --ti-head2-fg: #bfe6bb;
    --ti-hm: #33301a;
    --ti-hm-fg: #a6df9f;
    --ti-band: #55211c;
    --ti-band-fg: #ffd2cc;
    --ti-info-bg: #1b3350;
    --ti-info-fg: #b9d6fb;
    --ti-warn-bg: #46320f;
    --ti-warn-fg: #fcd59a;
    --ti-bad-bg: #4d1d18;
    --ti-bad-fg: #ffbdb3;
    --ti-ok-bg: #163a29;
    --ti-ok-fg: #a8e6c4;
    --ti-sel: #1b3229;
    --ti-strike: #6f807a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ti-bg: #0f171a;
  --ti-panel: #162127;
  --ti-line: #2c3c42;
  --ti-fg: #e4ede9;
  --ti-muted: #93a6a0;
  --ti-accent: #3cbf8c;
  --ti-accent-fg: #06231a;
  --ti-head: #1e3447;
  --ti-head-fg: #c4def2;
  --ti-head2: #1f3a24;
  --ti-head2-fg: #bfe6bb;
  --ti-hm: #33301a;
  --ti-hm-fg: #a6df9f;
  --ti-band: #55211c;
  --ti-band-fg: #ffd2cc;
  --ti-info-bg: #1b3350;
  --ti-info-fg: #b9d6fb;
  --ti-warn-bg: #46320f;
  --ti-warn-fg: #fcd59a;
  --ti-bad-bg: #4d1d18;
  --ti-bad-fg: #ffbdb3;
  --ti-ok-bg: #163a29;
  --ti-ok-fg: #a8e6c4;
  --ti-sel: #1b3229;
  --ti-strike: #6f807a;
  color-scheme: dark;
}

.ti-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  color: var(--ti-fg);
  font-family: inherit;
  font-size: 13px;
  user-select: text;
}

.ti-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 8px;
}

.ti-f {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
}

.ti-f label {
  font-size: 11px;
  color: var(--ti-muted);
  letter-spacing: .02em;
  white-space: nowrap;
}

.ti-f select, .ti-f input[type=text], .ti-f input[type=date] {
  font: inherit;
  font-size: 12px;
  height: 30px;
  border: 1px solid var(--ti-line);
  border-radius: 6px;
  background: var(--ti-panel);
  color: var(--ti-fg);
  padding: 0 6px;
  min-width: 0;
}

.ti-chk {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--ti-muted);
  height: 30px;
  cursor: pointer;
  white-space: nowrap;
}

.ti-scroll {
  overflow-x: auto;
  background: var(--ti-panel);
  border: 1px solid var(--ti-line);
  border-radius: 8px;
  user-select: text;
}

table.ti-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
  table-layout: fixed;
  font-size: 12px;
  line-height: 1.5;
  user-select: text;
}

table.ti-table th, table.ti-table td {
  border: 1px solid var(--ti-line);
  padding: 5px 6px;
  vertical-align: top;
  word-wrap: break-word;
}

table.ti-table th {
  background: var(--ti-head);
  color: var(--ti-head-fg);
  font-weight: 600;
  text-align: center;
  position: sticky;
  top: 0;
}

table.ti-table th.ti-g {
  background: var(--ti-head2);
  color: var(--ti-head2-fg);
}

table.ti-table td.ti-c {
  text-align: center;
}

table.ti-table td.ti-hm {
  background: var(--ti-hm);
  color: var(--ti-hm-fg);
  font-weight: 600;
  text-align: center;
}

table.ti-table tr.ti-band td {
  background: var(--ti-band);
  color: var(--ti-band-fg);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 10px;
}

table.ti-table tbody tr.ti-row {
  cursor: pointer;
}

table.ti-table tbody tr.ti-row:hover td {
  background: var(--ti-sel);
}

table.ti-table tbody tr.ti-row:hover td.ti-hm {
  background: var(--ti-hm);
}

table.ti-table tr.ti-on td {
  box-shadow: inset 0 0 0 9999px var(--ti-sel);
}

.ti-late {
  color: var(--ti-bad-fg);
  font-weight: 600;
}

.ti-pill {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.ti-p-info { background: var(--ti-info-bg); color: var(--ti-info-fg); }
.ti-p-warn { background: var(--ti-warn-bg); color: var(--ti-warn-fg); }
.ti-p-bad  { background: var(--ti-bad-bg);  color: var(--ti-bad-fg); }
.ti-p-ok   { background: var(--ti-ok-bg);   color: var(--ti-ok-fg); }
.ti-p-mut  { background: var(--ti-line);    color: var(--ti-fg); }

.ti-done, .ti-strike {
  color: var(--ti-strike);
  text-decoration: line-through;
}

ul.ti-sub {
  margin: 4px 0 0;
  padding-left: 16px;
}

.ti-panel {
  background: var(--ti-panel);
  border: 1px solid var(--ti-line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.ti-panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.ti-panel h3 {
  font-size: 12px;
  font-weight: 600;
  margin: 0;
  color: var(--ti-muted);
  letter-spacing: .03em;
  text-transform: uppercase;
}

.ti-grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

@media (max-width: 820px) {
  .ti-grid2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

.ti-hist p {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
}

.ti-hist .ti-d {
  color: var(--ti-muted);
  font-variant-numeric: tabular-nums;
}

.ti-thumbs {
  display: flex;
  gap: 6px;
  margin: 2px 0 6px 0;
  flex-wrap: wrap;
}

.ti-thumbs img {
  width: 64px;
  height: 46px;
  border-radius: 5px;
  border: 1px solid var(--ti-line);
  object-fit: cover;
}

.ti-subrow {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  padding: 4px 0;
  border-top: 1px dashed var(--ti-line);
}

.ti-subrow:first-child {
  border-top: 0;
}

.ti-subrow .ti-t {
  flex: 1;
  min-width: 0;
}

.ti-chat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.ti-chat .ti-m b {
  font-weight: 600;
}

.ti-row-flex {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.ti-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 24px;
  background: var(--ti-fg);
  color: var(--ti-bg);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: min(560px, calc(100% - 32px));
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

td.ti-img img {
  width: 72px;
  height: 52px;
  border-radius: 5px;
  border: 1px solid var(--ti-line);
  object-fit: cover;
  display: block;
}

.ti-num {
  font-variant-numeric: tabular-nums;
}

.ti-btn {
  font: inherit;
  font-size: 12px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--ti-line);
  border-radius: 6px;
  background: var(--ti-panel);
  color: var(--ti-fg);
  cursor: pointer;
  white-space: nowrap;
}

.ti-btn:hover {
  border-color: var(--ti-accent);
}

.ti-btn.ti-pri {
  background: var(--ti-accent);
  color: var(--ti-accent-fg);
  border-color: var(--ti-accent);
}

.ti-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.ti-input, .ti-select, .ti-textarea {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--ti-line);
  border-radius: 6px;
  background: var(--ti-panel);
  color: var(--ti-fg);
  padding: 4px 6px;
}

.ti-textarea {
  resize: vertical;
  min-height: 40px;
  width: 100%;
}

.ti-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}

.ti-stat {
  background: var(--ti-panel);
  border: 1px solid var(--ti-line);
  border-radius: 8px;
  padding: 8px 12px;
}

.ti-stat .ti-n {
  font-size: 22px;
  font-weight: 600;
}

.ti-stat .ti-l {
  font-size: 11px;
  color: var(--ti-muted);
}

.ti-edit-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0;
  padding: 8px;
  background: rgba(0,0,0,0.02);
  border-radius: 6px;
  border: 1px solid var(--ti-line);
}

.ti-edit-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ti-muted);
}

/* TD6 Modal Tạo vướng mắc */
.ti-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}

.ti-modal {
  background: var(--ti-panel);
  border: 1px solid var(--ti-line);
  border-radius: 8px;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 11px;
}

.ti-modal h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.ti-create-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
}

.ti-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.ti-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ti-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ti-muted);
}

.ti-field input, .ti-field select, .ti-field textarea {
  font: inherit;
  font-size: 11px;
  border: 1px solid var(--ti-line);
  border-radius: 4px;
  background: var(--ti-panel);
  color: var(--ti-fg);
  padding: 4px 6px;
}

.ti-field textarea {
  resize: vertical;
  min-height: 50px;
}

/* TD6 Chat box */
.ti-chat-box {
  margin-top: 10px;
  border-top: 1px solid var(--ti-line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ti-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(0,0,0,0.02);
  border: 1px solid var(--ti-line);
  border-radius: 6px;
  padding: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.ti-chat-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  line-height: 1.4;
}

.ti-chat-meta {
  font-size: 10px;
  color: var(--ti-muted);
  display: flex;
  gap: 6px;
}

.ti-chat-body {
  font-size: 12px;
  word-break: break-word;
}
