:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7682;
  --line: #e2e6ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --warn: #b7791f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; color: var(--ink); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar .logout { display: flex; align-items: center; gap: 12px; }
.topbar .who { color: var(--muted); font-size: 13px; }

button {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
.logout button {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

.content { padding: 24px; max-width: 1100px; margin: 0 auto; }

.login-card {
  max-width: 360px;
  margin: 8vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
}
.login-card h1 { font-size: 20px; margin: 0 0 20px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-card input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
.login-card button { width: 100%; margin-top: 6px; }
.error { color: var(--danger); font-size: 14px; margin: 0 0 14px; }

/* --- Сторінки --- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; }
.head-actions { display: flex; align-items: center; gap: 10px; }
.center { text-align: center; }
.muted { color: var(--muted); font-size: 13px; }

.btn, a.btn {
  display: inline-block; padding: 7px 14px; border-radius: 6px;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
}
a.btn:hover { text-decoration: none; filter: brightness(1.05); }
.tab {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  color: var(--muted); background: var(--panel);
}
.tab.active { color: var(--ink); border-color: var(--accent); }

/* --- Фільтри --- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters select, .filters input {
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: var(--panel);
}

/* --- Таблиця --- */
.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.grid th, .grid td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.grid tr:last-child td { border-bottom: none; }

/* --- Бейджі --- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.st-new { background: #eef2ff; color: #3949ab; }
.st-open { background: #e6f4ea; color: var(--ok); }
.st-pending { background: #fdf3e2; color: var(--warn); }
.st-solved { background: #eceff1; color: #546e7a; }
.st-closed { background: #f0f0f0; color: #888; }
.kpi-met { background: #e6f4ea; color: var(--ok); }
.kpi-breached { background: #fdecea; color: var(--danger); }
.kpi-sla { background: #fdf3e2; color: var(--warn); }

/* --- Картка тікета --- */
.detail { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }
@media (max-width: 800px) { .detail { grid-template-columns: 1fr; } }
.thread { display: flex; flex-direction: column; gap: 12px; }
.banner { background: #fdf3e2; border: 1px solid #f0d9a8; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.msg header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.msg .body { white-space: pre-wrap; }
.msg.dir-client { border-left: 3px solid var(--accent); }
.msg.dir-agent { border-left: 3px solid var(--ok); }
.msg.dir-outreach { border-left: 3px solid var(--warn); }
.msg.dir-note { border-left: 3px solid #b0bec5; background: #fcfcfa; }
.note-form textarea, .stacked textarea, .stacked input, .stacked select { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }

.sidebar { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.card form { margin-bottom: 8px; }
.inline-form { display: flex; gap: 6px; }
.inline-form select { flex: 1; }
.stacked label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 10px 0 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

/* --- Аналітика --- */
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-label { font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.m-val { font-size: 26px; font-weight: 700; }
.m-lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 800px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-grid .card h3 { margin-top: 0; }

/* --- Адмін --- */
.grid input[type=text], .grid input[type=email] { width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px; font: inherit; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.row-actions form { margin: 0; }
.row-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-form input[type=text], .row-form input[type=email] { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.cb { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
button.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
button.ghost.danger { color: var(--danger); }
.ok-msg { color: var(--ok); font-size: 14px; margin: 0 0 14px; }
