:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #6b7388;
  --line: #e2e5ef;
  --brand: #3b4cca;
  --brand-ink: #ffffff;
  --brand-soft: #e9ecff;
  --ok: #1f8a54;
  --ok-soft: #e3f6ec;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --bad: #c0392b;
  --bad-soft: #fde8e5;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

button, .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: .6rem .95rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
}
button:hover { border-color: #c4c9dd; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: #f0c4be; }
button.link { border: 0; background: none; color: var(--brand); padding: .25rem .4rem; min-height: 0; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  min-height: 44px;
}
textarea { resize: vertical; min-height: 120px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; font-size: .95rem; }
.check input { width: 22px; height: 22px; min-height: 0; margin-top: 2px; flex: none; }

.field { margin-bottom: .85rem; }
.grid2 { display: grid; gap: .85rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.top {
  background: var(--brand);
  color: #fff;
  padding: .7rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.05rem; }
.who { font-size: .9rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.who button.link { color: #fff; }
.pill { background: rgba(255, 255, 255, .2); padding: .1rem .55rem; border-radius: 99px; font-size: .78rem; }

.tabs {
  display: flex;
  gap: .25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 .5rem;
  overflow-x: auto;
}
.tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  padding: .8rem 1rem;
  white-space: nowrap;
  font-weight: 600;
  color: var(--muted);
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

main { max-width: 980px; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

.login { max-width: 380px; margin: 12vh auto 0; padding: 1rem; }
.login .card { padding: 1.5rem; }
.error { color: var(--bad); background: var(--bad-soft); padding: .6rem .8rem; border-radius: 10px; margin-bottom: .85rem; font-size: .9rem; }
.notice { color: var(--warn); background: var(--warn-soft); padding: .6rem .8rem; border-radius: 10px; margin-bottom: .85rem; font-size: .9rem; }
.success { color: var(--ok); background: var(--ok-soft); padding: .6rem .8rem; border-radius: 10px; margin-bottom: .85rem; font-size: .9rem; }

.stats { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .8rem; font-size: .85rem; }
.stat b { font-size: 1.1rem; display: block; }

.toolbar { display: grid; gap: .5rem; grid-template-columns: 1fr; margin-bottom: 1rem; }
@media (min-width: 700px) { .toolbar { grid-template-columns: 2fr 1fr 1fr auto; } }

.toolbar.filters { margin-bottom: .6rem; }
@media (min-width: 700px) {
  .toolbar.filters.two { grid-template-columns: 2fr 1fr; }
  .toolbar.filters.three { grid-template-columns: 2fr 1fr 1fr; }
}
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

.list { display: grid; gap: .6rem; }
.row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  text-align: left;
  width: 100%;
}
.row:hover { border-color: var(--brand); }
.row .name { font-weight: 650; }
.row .meta { color: var(--muted); font-size: .85rem; }
.badge { font-size: .75rem; padding: .15rem .55rem; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

dialog {
  width: min(680px, 100vw);
  max-height: 100dvh;
  border: 0;
  border-radius: 16px;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}
dialog::backdrop { background: rgba(20, 24, 40, .5); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1rem .25rem; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.dlg-body { padding: 0 1rem 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.actions .spacer { flex: 1; }

.timeline { display: grid; gap: .5rem; margin-top: .75rem; }
.event { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; font-size: .92rem; white-space: pre-wrap; }
.event .when { color: var(--muted); font-size: .78rem; display: block; margin-bottom: .15rem; }
.inline { display: flex; gap: .5rem; }
.inline input { flex: 1; }

.segmented { display: flex; gap: .4rem; flex-wrap: wrap; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 0; }
.segmented span { display: inline-block; padding: .55rem .9rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-weight: 600; min-height: 44px; line-height: 1.7; }
.segmented input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .35rem 0 .75rem; }
.chip { font-size: .82rem; padding: .3rem .65rem; min-height: 0; border-radius: 99px; background: var(--brand-soft); border-color: transparent; color: var(--brand); font-weight: 600; }

.recips { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.recip { display: flex; gap: .7rem; align-items: center; padding: .55rem .75rem; border-bottom: 1px solid var(--line); cursor: pointer; margin: 0; font-weight: 500; }
.recip:last-child { border-bottom: 0; }
.recip input { width: 22px; height: 22px; min-height: 0; flex: none; }
.recip .info { flex: 1; min-width: 0; }

.bubble { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: .9rem 1rem; white-space: pre-wrap; word-break: break-word; }
.bubble .subj { font-weight: 700; border-bottom: 1px solid var(--line); padding-bottom: .4rem; margin-bottom: .6rem; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.tbl-wrap { overflow-x: auto; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 150%);
  background: #1d2433;
  color: #fff;
  padding: .7rem 1.1rem;
  border-radius: 10px;
  transition: transform .25s;
  z-index: 100;
  max-width: 90vw;
}
#toast.show { transform: translate(-50%, 0); }
