:root {
  --ink: #16161a;
  --muted: #71717a;
  --line: #e6e6e9;
  --bg: #f5f5f7;
  --card: #ffffff;
  --accent: #16161a;
  --ok: #157f3d;
  --ok-bg: #e8f6ee;
  --warn: #b45309;
  --warn-bg: #fdf3e4;
  --bad: #b91c1c;
  --bad-bg: #fdebeb;
  --ai: #6d28d9;
  --ai-2: #9333ea;
  --link: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 22, 26, .05), 0 4px 16px rgba(22, 22, 26, .05);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); font-weight: 400; }
.center { text-align: center; }
.error { color: var(--bad); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.gg-icon { flex: 0 0 auto; vertical-align: -2px; }

/* przyciski */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 8px 16px; transition: background .15s, box-shadow .15s, transform .05s;
}
button:hover { background: #303036; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
button.ghost {
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(22,22,26,.04);
}
button.ghost:hover { background: var(--bg); }
button.small { padding: 4px 11px; font-size: 12.5px; }
button.ai-btn {
  background: linear-gradient(120deg, var(--ai), var(--ai-2));
  color: #fff; border: 0;
  box-shadow: 0 2px 10px rgba(124, 45, 218, .3);
}
button.ai-btn:hover { background: linear-gradient(120deg, #5b21b6, #7e22ce); }
.linklike {
  display: inline; background: none; border: 0; padding: 0; box-shadow: none;
  color: var(--link); cursor: pointer; font: inherit; font-weight: 500; text-decoration: none;
}
.linklike:hover { background: none; text-decoration: underline; }

/* pola formularzy */
input[type="text"], input[type="email"], input[type="password"], textarea, select {
  font: inherit; color: var(--ink);
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--card); transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(22, 22, 26, .08);
}

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; width: 340px; display: grid; gap: 15px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.02em; }
.login-card label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap;
  background: rgba(255, 255, 255, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 22px; position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 16px; letter-spacing: -.02em; white-space: nowrap; }
.brand .muted { font-weight: 500; }
.search { display: flex; gap: 8px; flex: 0 1 520px; }
.search input { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.whoami { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

/* nav w topbarze */
.nav { display: flex; gap: 4px; }
.nav a {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); text-decoration: none; padding: 7px 13px; border-radius: 9px;
  font-weight: 600; font-size: 13.5px; transition: color .15s, background .15s;
}
.nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--ink); color: #fff; }

/* layout */
.container { max-width: 1200px; margin: 22px auto; padding: 0 22px; display: grid; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 14.5px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.card h2 .src { font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* order header */
.order-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 18px; }
.order-head .num { font-size: 21px; font-weight: 800; letter-spacing: -.02em; }

/* badge — tintowane tło zamiast obrysu */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
  background: var(--bg); color: var(--muted); border: 0;
}
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }

/* tabele */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: #fafafa; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.chip {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 5px;
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.src-error { color: var(--bad); font-size: 13px; }
.section-empty { color: var(--muted); font-size: 13px; }
.loading { color: var(--muted); }

/* zendesk */
.zd-comments { margin: 8px 0 0; padding: 12px; background: var(--bg); border-radius: 10px; display: grid; gap: 10px; }
.zd-comment { border-left: 3px solid var(--line); padding-left: 10px; white-space: pre-wrap; font-size: 13px; }
.zd-comment.internal { border-left-color: var(--warn); }
.zd-comment .meta { color: var(--muted); font-size: 12px; margin-bottom: 2px; }

/* tłumaczenie pod bąbelkiem */
.tr-slot {
  margin-top: 8px; padding: 7px 11px; border-left: 3px solid #c9b8ee;
  background: #faf8ff; border-radius: 8px; font-size: 13px; color: var(--ink);
  font-style: italic; white-space: pre-wrap;
}

/* formularz klientki */
.form-wide { width: min(500px, 92vw); }
.hp { position: absolute; left: -9999px; opacity: 0; height: 0; }

/* wątek (czat) */
.thread-container { max-width: 720px; }
.chat { display: grid; gap: 10px; margin-top: 8px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }
.bubble .meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.bubble .body { white-space: pre-wrap; font-size: 13.5px; }
.bubble.mine { justify-self: end; background: #eef3fe; border-color: #dbe6fd; border-bottom-right-radius: 4px; }
.bubble.theirs { justify-self: start; background: var(--card); border-bottom-left-radius: 4px; }
.reply-form { display: grid; gap: 10px; }
.reply-form label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
.reply-form textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.form-wide textarea { min-height: 140px; resize: vertical; line-height: 1.55; }

/* widok 360 — boczne menu + zakładki */
.layout360 {
  max-width: 1280px; margin: 22px auto; padding: 0 22px;
  display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px;
  align-items: start;
}
.layout360:has(.sidenav[hidden]) { grid-template-columns: 1fr; }
.sidenav {
  position: sticky; top: 72px;
  display: grid; gap: 3px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow);
}
.sidenav .nav-item {
  display: flex; align-items: center; gap: 9px;
  background: none; border: 0; border-radius: 8px; padding: 9px 11px;
  font: inherit; font-weight: 600; font-size: 13px; color: var(--muted);
  text-align: left; cursor: pointer; box-shadow: none;
  transition: background .12s, color .12s;
}
.sidenav .nav-item .nav-label { flex: 1; }
.sidenav .nav-item:hover { background: var(--bg); color: var(--ink); }
.sidenav .nav-item.active { background: var(--ink); color: #fff; }
.sidenav .nav-count {
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
}
.sidenav .nav-item.active .nav-count { background: rgba(255,255,255,.92); border-color: transparent; }
.content360 { display: grid; gap: 16px; min-width: 0; }
.summary360 { position: sticky; top: 72px; z-index: 4; }
.tab-panel { display: grid; gap: 16px; }
@media (max-width: 900px) {
  .layout360 { grid-template-columns: 1fr; }
  .sidenav { position: static; grid-auto-flow: column; overflow-x: auto; }
  .summary360 { position: static; }
}

/* kolejka BOK — lista */
.ticket-container { max-width: 1100px; }
.filters { display: flex; gap: 8px; align-items: center; }
.filters .filter.active, .filters .filter-moje.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.filter-sep { flex: 0 0 12px; }
.t-row { cursor: pointer; }
.t-row .order-nr { font-weight: 700; }
.t-row.t-new td { background: #fffdf6; }
.t-row.t-new:hover td { background: #fdf8ea; }
td.preview { max-width: 320px; }

/* kolejka BOK — szczegół zgłoszenia: metadane po LEWEJ, rozmowa po prawej */
.detail-layout {
  display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 14px;
  align-items: start;
}
.ticket-side { position: sticky; top: 72px; display: grid; gap: 14px; }
.ticket-side > button#backBtn { justify-self: start; }
.ticket-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ticket-title .num { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.side-kv { grid-template-columns: auto 1fr; gap: 7px 12px; }
.side-kv .order-link { font-weight: 700; }
.wrap-any { overflow-wrap: anywhere; }
.side-actions { display: grid; gap: 8px; }
.side-actions button { width: 100%; justify-content: flex-start; }
.detail-main { display: grid; gap: 18px; min-width: 0; align-content: start; }
.detail-main .bubble { max-width: 82%; }
.detail-main .compose { border-top: 1px solid var(--line); padding-top: 16px; }
@media (max-width: 900px) {
  .detail-layout { grid-template-columns: 1fr; }
  .ticket-side { position: static; }
}

/* kompozytor odpowiedzi — duże, wygodne pole */
.compose { display: grid; gap: 10px; }
.compose-label { font-weight: 600; font-size: 13px; }
.compose-label .muted { font-weight: 400; }
.compose textarea {
  width: 100%; min-height: 170px; resize: vertical;
  font-size: 14px; line-height: 1.55; padding: 12px 14px;
}
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* załączniki */
.file-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-btn { cursor: pointer; }
.file-names { font-size: 12.5px; }
.att-list { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.att-thumb { max-width: 160px; max-height: 160px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.att-file {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-size: 12.5px; color: var(--ink); text-decoration: none;
}
.att-file:hover { background: #ececee; text-decoration: none; }

/* braki magazynowe blokujące zlecenie */
.brak-info { margin-top: 6px; display: grid; gap: 3px; }
.brak-line { font-size: 12px; color: var(--bad); }
.brak-line .muted { color: var(--muted); }

/* akcje na zamówieniu (anulacje) */
.order-cancel-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
button.danger { color: var(--bad); border-color: #f3caca; }
button.danger:hover { background: var(--bad-bg); }
button.danger:disabled { color: var(--muted); border-color: var(--line); }
.sel-cell { width: 26px; }
.item-check { width: 15px; height: 15px; accent-color: var(--bad); cursor: pointer; }

/* maile do magazynów (anulacje) — popup z treścią do zatwierdzenia */
.wh-mail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 25, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal { width: min(640px, 100%); max-height: 90vh; overflow-y: auto; display: grid; gap: 10px; }
.modal label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
.modal input, .modal textarea { font: inherit; }
.modal textarea { resize: vertical; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* drag&drop + chipsy załączników */
form.drag-over { outline: 2px dashed var(--accent, #7c5cff); outline-offset: 4px; border-radius: 10px; }
.file-hint { font-size: 12px; }
.file-names { display: inline-flex; gap: 6px; flex-wrap: wrap; font-size: 12.5px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 6px 3px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); font-size: 12px;
}
.file-chip-x {
  border: 0; background: none; cursor: pointer; font-size: 14px; line-height: 1;
  padding: 0 4px; color: var(--muted);
}
.file-chip-x:hover { color: var(--bad); }
