:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #17203a;
  --muted: #64708a;
  --line: #e3e8f2;
  --accent: #4f5dff;
  --accent-soft: #eceeff;
  --red: #d92d20;
  --red-soft: #fee4e2;
  --green: #067647;
  --green-soft: #d1fadf;
  --amber: #b54708;
  --amber-soft: #fef0c7;
  --blue: #175cd3;
  --blue-soft: #d1e9ff;
  --purple: #6941c6;
  --purple-soft: #ebe9fe;
  --slate-soft: #eef2f6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 32, 58, .06), 0 4px 16px rgba(23, 32, 58, .06);
  font-size: 15px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 22px;
  position: sticky; top: 0; z-index: 40;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.2px; white-space: nowrap; }
.brand-mark { margin-right: 2px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 8px; font-weight: 600;
}
.nav button:hover { background: var(--slate-soft); color: var(--ink); }
.nav button.active { background: var(--accent-soft); color: var(--accent); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.user-chip .who { line-height: 1.15; text-align: right; }
.user-chip .who .name { font-weight: 600; font-size: 13.5px; }
.user-chip .who .role { font-size: 11.5px; color: var(--muted); }
.btn-logout {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 8px; padding: 6px 12px; font-size: 13px;
}
.btn-logout:hover { color: var(--red); border-color: var(--red-soft); background: #fffafa; }

/* ---------- layout ---------- */
.view { max-width: 1180px; margin: 0 auto; padding: 26px 22px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card .card-head {
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 14.5px;
  display: flex; align-items: center; justify-content: space-between;
}
.card .card-body { padding: 16px 18px; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 400px; max-width: 100%; padding: 34px 32px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .hint { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }
.auth-error {
  background: var(--red-soft); color: var(--red);
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 14px;
}

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn {
  border: 0; border-radius: 8px; padding: 9px 16px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 15px 17px; cursor: pointer; border-top: 3px solid var(--line);
  transition: transform .05s ease;
}
.stat-card:hover { transform: translateY(-1px); }
.stat-card .num { font-size: 27px; font-weight: 750; letter-spacing: -.5px; }
.stat-card .lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; margin-top: 1px; }
.stat-card.alarm { border-top-color: var(--red); }
.stat-card.alarm .num { color: var(--red); }
.stat-card.c-new { border-top-color: var(--blue); }
.stat-card.c-ip { border-top-color: var(--amber); }
.stat-card.c-oh { border-top-color: var(--purple); }
.stat-card.c-done { border-top-color: var(--green); }
.stat-card.has-upd { border-top-color: var(--blue); }
.stat-card.has-upd .lbl { color: var(--blue); }
.my-ticket .last-move {
  flex: 1.4; min-width: 0; color: var(--muted); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dash-cols { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .dash-cols { grid-template-columns: 1fr; } }

.my-ticket {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.my-ticket:last-child { border-bottom: 0; }
.my-ticket:hover .t { color: var(--accent); }
.my-ticket .t { flex: 1; font-weight: 600; font-size: 13.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-ticket .due { font-size: 12px; color: var(--muted); white-space: nowrap; }
.my-ticket .due.overdue { color: var(--red); font-weight: 700; }
.empty { color: var(--muted); font-size: 13.5px; padding: 14px 2px; }

.feed-item { display: flex; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.feed-item:last-child { border-bottom: 0; }
.feed-item .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.feed-item .dot.comment { background: var(--blue); }
.feed-item .dot.event { background: var(--line); }
.feed-item .fx { flex: 1; min-width: 0; }
.feed-item .fx .line1 { overflow: hidden; text-overflow: ellipsis; }
.feed-item .fx .meta { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.feed-item a { color: var(--accent); text-decoration: none; font-weight: 600; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th {
  text-align: left; color: var(--muted); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .4px; padding: 9px 12px; border-bottom: 1px solid var(--line);
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: #f8f9fe; }
table.grid td.num { color: var(--muted); font-variant-numeric: tabular-nums; }
td.overdue-cell { color: var(--red); font-weight: 700; }

/* ---------- pills ---------- */
.pill {
  display: inline-block; padding: 2.5px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.pill.st-new { background: var(--blue-soft); color: var(--blue); }
.pill.st-in_progress { background: var(--amber-soft); color: var(--amber); }
.pill.st-on_hold { background: var(--purple-soft); color: var(--purple); }
.pill.st-done { background: var(--green-soft); color: var(--green); }
.pill.upd { background: var(--blue-soft); color: var(--blue); }
.resolve-btn {
  border: 0; border-radius: 7px; padding: 4px 11px;
  background: var(--green-soft); color: var(--green);
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.resolve-btn:hover { filter: brightness(.95); }
.resolve-btn.done-hide { visibility: hidden; }
.flt-upd-active { background: var(--accent-soft) !important; color: var(--accent) !important; border-color: var(--accent-soft) !important; }
.pill.pr-low { background: var(--slate-soft); color: var(--muted); }
.pill.pr-medium { background: var(--blue-soft); color: var(--blue); }
.pill.pr-high { background: var(--amber-soft); color: var(--amber); }
.pill.pr-urgent { background: var(--red-soft); color: var(--red); }

/* ---------- tickets toolbar ---------- */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 16px;
}
.toolbar input[type="search"] {
  flex: 1; min-width: 180px; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; outline: none;
}
.toolbar input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(23, 32, 58, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 14px; width: 720px; max-width: 100%;
  box-shadow: 0 24px 60px rgba(23, 32, 58, .25);
}
.modal.narrow { width: 520px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close { border: 0; background: transparent; font-size: 20px; color: var(--muted); line-height: 1; }
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 20px 22px; }
.modal-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--line);
}

/* ---------- ticket timeline ---------- */
.timeline { margin-top: 6px; }
.event-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.event-item:last-child { border-bottom: 0; }
.event-item .who { font-weight: 700; }
.event-item .when { color: var(--muted); font-size: 11.5px; }
.event-item.kind-comment { background: #f8f9fe; border-radius: 8px; padding: 10px 12px; border: 1px solid var(--line); margin-bottom: 8px; }
.comment-box { display: flex; gap: 10px; margin-top: 14px; }
.comment-box textarea {
  flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  min-height: 44px; resize: vertical; outline: none;
}
.comment-box textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- admin ---------- */
.user-row td { vertical-align: middle; }
.inactive-row td { opacity: .5; }
.role-tag { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- toast ---------- */
.toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; border-radius: 10px;
  padding: 11px 16px; font-size: 13.5px; box-shadow: var(--shadow);
  animation: slidein .15s ease;
}
.toast.error { background: var(--red); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
