/* Helpdesk IT: CSS tự viết, không phụ thuộc thư viện. Sáng/tối theo hệ điều hành. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1b1f24; --muted: #5b6471; --border: #dde1e6;
  --primary: #2155d6; --primary-text: #ffffff; --primary-soft: #e7eefc;
  --danger: #c4312b; --danger-soft: #fbe9e8; --warn: #9a5b00; --warn-soft: #fff3df;
  --ok: #18794e; --ok-soft: #e3f5ec; --info: #5b3fc4; --info-soft: #efeafd;
  --internal: #fff8db; --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1a1e24; --text: #e6e9ed; --muted: #9aa3ae; --border: #2c323a;
    --primary: #6d94ff; --primary-text: #0d1220; --primary-soft: #1f2a44;
    --danger: #ff7b72; --danger-soft: #3a1f1f; --warn: #f2b45a; --warn-soft: #3a2c16;
    --ok: #5fd49a; --ok-soft: #173326; --info: #b4a2ff; --info-soft: #2a2347;
    --internal: #332d16; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.02rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* khung */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.top-in { max-width: 1120px; margin: 0 auto; padding: .6rem 16px; display: flex; gap: .75rem 1.25rem; align-items: center; flex-wrap: wrap; }
.brand { display: flex; gap: .5rem; align-items: center; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { padding: .35rem .65rem; border-radius: 8px; color: var(--muted); }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a[aria-current] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.top-right { margin-left: auto; display: flex; gap: .6rem; align-items: center; }
.lang { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 0; }
.lang button { border: 0; background: transparent; color: var(--muted); padding: .25rem .5rem; font: inherit; font-size: .8rem; cursor: pointer; }
.lang button[aria-pressed] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.logout { margin: 0; }
.main { max-width: 1120px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.flash { background: var(--ok-soft); color: var(--ok); padding: .6rem .9rem; border-radius: var(--radius); margin: 0 0 1rem; }
.alert { background: var(--danger-soft); color: var(--danger); padding: .6rem .9rem; border-radius: var(--radius); }
.crumb { margin: 0 0 .75rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.narrow { max-width: 680px; }
.login { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* nút, form */
.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .45rem .9rem; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; line-height: 1.3;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { border-color: var(--primary); filter: brightness(1.06); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-block { display: block; width: 100%; margin: 1rem 0; }
.btn-new { white-space: nowrap; }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.link.danger { color: var(--danger); }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
.form { display: grid; gap: .8rem; margin: 0; }
.form label, .filters label { display: grid; gap: .3rem; font-weight: 550; font-size: .9rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .6rem; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { resize: vertical; }
.check { display: flex !important; gap: .45rem; align-items: center; font-weight: 400 !important; }
.check input { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.actions { display: flex; gap: 1rem; align-items: center; }
.inline { display: inline; }

/* danh sách */
.head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.filters { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin: 0; }
.filters select { width: auto; min-width: 9rem; }
.tickets { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.ticket-row + .ticket-row { border-top: 1px solid var(--border); }
.ticket-row a { display: block; padding: .8rem 1rem; color: var(--text); }
.ticket-row a:hover { background: var(--bg); text-decoration: none; }
.ticket-row.unread .row-title { font-weight: 700; }
.row-top { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; margin-bottom: .2rem; }
.row-title { font-weight: 550; overflow-wrap: anywhere; }
.row-meta { font-size: .85rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); display: inline-block; }

.badge { font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.st-new { background: var(--info-soft); color: var(--info); border-color: transparent; }
.st-accepted, .st-in_progress { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.st-waiting_requester { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.st-resolved { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.prio-urgent { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.internal-badge { background: var(--internal); color: var(--warn); border-color: transparent; }

/* chi tiết */
.ticket-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.ticket-title { margin: .35rem 0 .2rem; overflow-wrap: anywhere; }
.body { overflow-wrap: anywhere; margin-top: .6rem; }
.confirm { border-color: var(--ok); }
.confirm details { display: inline-block; margin-left: .5rem; vertical-align: top; }
.confirm details[open] { display: block; margin: .75rem 0 0; }
.thread { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .6rem; }
.comment { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; }
.comment .body { margin-top: .25rem; }
.comment.from-requester { border-left: 3px solid var(--info); }
.comment.internal { background: var(--internal); border-style: dashed; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; margin: 0; font-size: .9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.act { margin: 0 0 .6rem; }
.act > .btn, .act > summary { width: 100%; text-align: center; }
.act .form { margin-top: .6rem; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; font-size: .88rem; }
.timeline li { border-left: 2px solid var(--border); padding-left: .7rem; }
.note { color: var(--muted); font-style: italic; overflow-wrap: anywhere; }

/* quản trị */
.table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 550; padding: .4rem .3rem; border-bottom: 1px solid var(--border); }
.table td { padding: .5rem .3rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table form { margin: 0; }
.row-form { grid-template-columns: 1fr auto auto; align-items: end; }
.cat-form { display: grid; grid-template-columns: 1fr 1fr 5.5rem auto auto; gap: .5rem; align-items: center; margin: 0; }

@media (max-width: 760px) {
  .ticket-grid { grid-template-columns: 1fr; }
  .grid2, .row-form { grid-template-columns: 1fr; }
  .cat-form { grid-template-columns: 1fr 1fr; }
  .top-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .filters { width: 100%; }
  .filters label { flex: 1 1 45%; }
  .filters select { width: 100%; min-width: 0; }
  .table thead { display: none; }
}
