:root {
  --ink: #0f172a;
  --ink-2: #1e293b;
  --ink-3: #334155;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-weak: #eef2ff;

  --st-new: #f59e0b;
  --st-progress: #3b82f6;
  --st-answered: #8b5cf6;
  --st-closed: #10b981;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Кнопки и поля ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f8fafc; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fecaca; }

.input, .field input, .field select, select.input {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
}
.input:focus, .field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); }
.form-error { margin-top: 10px; color: #b91c1c; font-size: 13px; }
.form-error.ok { color: #047857; }

/* ---------- Экран входа ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 100% -10%, #e0e7ff 0%, transparent 55%),
    radial-gradient(1000px 500px at -10% 110%, #dbeafe 0%, transparent 50%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-logo { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.login-logo span { color: var(--accent); margin: 0 1px; }
.login-sub { color: var(--muted); margin: 6px 0 24px; font-size: 13px; }

/* ---------- Каркас приложения ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { color: #fff; font-weight: 700; font-size: 18px; letter-spacing: -.02em; padding: 0 8px 22px; }
.brand span { color: #818cf8; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; color: #cbd5e1;
  font: inherit; font-weight: 500; text-align: left;
  padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--ink-2); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .55; }
.nav-item.active .nav-dot { opacity: 1; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 18px; }
.user-box { padding: 0 8px; }
.user-name { color: #fff; font-weight: 600; }
.user-role { color: #94a3b8; font-size: 12px; text-transform: capitalize; }
.sidebar-foot .btn-ghost { border-color: var(--ink-3); color: #cbd5e1; }
.sidebar-foot .btn-ghost:hover { background: var(--ink-2); color: #fff; }

.main { padding: 28px 32px; overflow: auto; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.view-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0; }

/* ---------- Фильтры ---------- */
.filters {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1.4fr;
  gap: 10px;
  margin-bottom: 18px;
}

/* ---------- Таблицы ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; color: var(--muted);
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: #f8fafc;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; transition: background .12s; }
.table tbody tr:hover { background: #f8fafc; }
.table .id-cell { font-weight: 700; color: var(--ink); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- Бейджи статусов ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: #f1f5f9; color: var(--ink-3);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.new { background: #fff7ed; color: #b45309; }
.badge.in_progress { background: #eff6ff; color: #1d4ed8; }
.badge.answered { background: #f5f3ff; color: #6d28d9; }
.badge.closed { background: #ecfdf5; color: #047857; }

/* ---------- Пагинация ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.page-info { color: var(--muted); font-size: 13px; min-width: 120px; text-align: center; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; color: var(--ink); }
.kpi-label { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Карточки/графики ---------- */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.charts-grid .card:first-child { grid-column: 1 / -1; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.card-title { font-weight: 600; margin-bottom: 14px; }

/* ---------- Команда IT ---------- */
.staff-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.staff-form-card { position: sticky; top: 20px; }

/* ---------- Модалка ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.modal-card {
  position: relative; width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 26px 28px;
}
.modal-close {
  position: absolute; top: 14px; right: 16px; border: 0; background: transparent;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.t-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.t-head h2 { margin: 0; font-size: 20px; }
.t-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; margin: 16px 0; }
.t-meta div { font-size: 13px; }
.t-meta .k { color: var(--muted); }
.t-desc {
  background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; white-space: pre-wrap; margin: 8px 0 16px;
}
.t-photo { margin: 8px 0 16px; }
.t-photo img { max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.section-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 16px 0 8px; }

.history { display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 13px; }
.msg .who { font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.it_staff { background: var(--accent-weak); border-color: #e0e7ff; }
.msg.system { background: #f8fafc; color: var(--muted); }
.msg.employee { background: #fff; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.reply-box { margin-top: 14px; }
.reply-box textarea {
  width: 100%; min-height: 80px; resize: vertical; font: inherit;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.reply-box textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.notice { font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); margin-top: 10px; }
.notice.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.notice.ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }

/* ---------- Адаптив ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: 8px; padding: 12px 14px;
  }
  .brand { padding: 0 8px 0 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding-top: 0; }
  .main { padding: 18px 16px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .staff-layout { grid-template-columns: 1fr; }
  .t-meta { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.modal[hidden] { display: none; }
