:root {
  --ink: #13251f;
  --muted: #5b6f68;
  --line: #d7e4de;
  --paper: #f4f1ea;
  --card: #fffdf8;
  --teal: #0d5c4e;
  --teal-2: #147a68;
  --teal-soft: #e7f4ef;
  --gold: #c2782a;
  --gold-soft: #f8ead7;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --ok: #157a3a;
  --shadow: 0 10px 30px rgba(19, 37, 31, 0.08);
  --radius: 18px;
  --tap: 46px;
  --pad: clamp(12px, 2.4vw, 28px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "Avenir Next", system-ui, sans-serif;
  color: var(--ink);
  overflow-x: hidden;
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9efe7 0%, transparent 55%),
    radial-gradient(900px 400px at 110% 0%, #f8ead7 0%, transparent 50%),
    var(--paper);
}
button, input, select, textarea { font: inherit; color: inherit; }
input:not([type="radio"]):not([type="checkbox"]), select, textarea { font-size: 16px; }
button { cursor: pointer; }
a { color: var(--teal); }
img, canvas, svg, table { max-width: 100%; }

.app {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: max(var(--pad), env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right))
    calc(72px + env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0 18px; flex-wrap: wrap;
}
.brand { display: flex; gap: 12px; align-items: center; }
.mark {
  width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(160deg, var(--teal), #0a3f36);
  color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: .04em;
  box-shadow: var(--shadow);
}
.brand h1 { font-size: 1.05rem; margin: 0; line-height: 1.2; }
.brand p { margin: 0; color: var(--muted); font-size: .82rem; }
.who { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip {
  background: var(--teal-soft); color: var(--teal); border-radius: 999px;
  padding: 6px 12px; font-size: .82rem; font-weight: 650;
  max-width: 100%; overflow-wrap: anywhere;
}
.ghost, .btn, .danger, .gold {
  min-height: var(--tap); border: 0; border-radius: 12px; padding: 0 14px; font-weight: 700;
}
.ghost { background: transparent; border: 1px solid var(--line); }
.btn { background: var(--teal); color: #fff; }
.btn:active { transform: translateY(1px); }
.gold { background: var(--gold); color: #fff; }
.danger { background: var(--danger-soft); color: var(--danger); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.hero { padding: 22px 18px; margin-bottom: 16px; }
.hero h2 { margin: 0 0 6px; font-size: 1.45rem; }
.hero p { margin: 0; color: var(--muted); }
.roles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px;
}
.role {
  text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px; min-height: 132px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.role:hover { border-color: var(--teal-2); }
.role b { font-size: 1.02rem; }
.role span { color: var(--muted); font-size: .86rem; margin-top: 8px; }
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) {
  .grid.form { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
  .grid.four { grid-template-columns: repeat(4, 1fr); }
}
.span-2 { grid-column: 1 / -1; }
label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input:not([type="radio"]):not([type="checkbox"]),
.field select,
.field textarea {
  width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 12px;
  background: #fff; padding: 10px 12px;
}
.field textarea { min-height: 110px; resize: vertical; }
.field input:not([type="radio"]):not([type="checkbox"]):focus,
.field select:focus,
.field textarea:focus {
  outline: 3px solid #cde7df; border-color: var(--teal-2);
}
.seg {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch;
}
.seg label {
  margin: 0; min-height: 42px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff;
  display: inline-flex; align-items: center; justify-content: flex-start; gap: 8px;
  color: var(--ink); font-weight: 650; cursor: pointer;
  flex: 0 1 auto; width: auto; max-width: 100%;
}
.seg input[type="radio"],
.seg input[type="checkbox"] {
  appearance: auto;
  width: 18px; height: 18px;
  min-width: 18px; min-height: 18px;
  max-width: 18px; max-height: 18px;
  margin: 0; padding: 0;
  flex: 0 0 18px;
  accent-color: var(--teal);
  border: 0;
  background: none;
}
.seg label:has(input:checked) { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }
.section { margin-top: 14px; }
.section h3 {
  margin: 0 0 12px; font-size: .92rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--teal); display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fff; text-align: left;
  width: 100%; min-width: 0;
}
.item > div { min-width: 0; }
.item:hover { border-color: var(--teal-2); }
.pid { font-weight: 800; color: var(--teal); letter-spacing: .04em; }
.search {
  display: flex; flex-direction: row; flex-wrap: nowrap; align-items: stretch;
  gap: 8px; margin-bottom: 12px; width: 100%; max-width: 640px;
}
.search input {
  flex: 1 1 auto; min-width: 0; min-height: var(--tap); width: auto;
  border-radius: 12px; border: 1px solid var(--line); padding: 0 12px;
}
.search .btn, .search button {
  flex: 0 0 auto; width: auto; min-width: 4.8rem; white-space: nowrap;
}
.live-hits {
  margin-top: 4px;
  max-height: min(52vh, 380px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.tabs button { flex: 1 1 140px; }
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.hidden { display: none !important; }
.badge {
  display: inline-block; background: var(--gold-soft); color: #7a4a12;
  padding: 4px 8px; border-radius: 8px; font-size: .75rem; font-weight: 800;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.rx { border: 1px dashed var(--line); border-radius: 14px; padding: 12px; margin-bottom: 8px; background: #fff; }
.modal-bg {
  position: fixed; inset: 0; background: rgba(19,37,31,.45); display: grid; place-items: center; z-index: 40; padding: 16px;
}
.modal { width: min(520px, 100%); }
.code-xl { font-size: 1.6rem; font-weight: 800; color: var(--teal); letter-spacing: .04em; }
.empty { color: var(--muted); padding: 18px 8px; text-align: center; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.kpi b { display: block; font-size: 1.4rem; }
.charts { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) { .charts { grid-template-columns: 1fr 1fr; } }
.chart-card canvas { width: 100% !important; max-height: 280px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { border: 1px solid var(--line); padding: 8px; text-align: left; }
th { background: var(--teal-soft); }
.sticky {
  background: rgba(255,253,248,.95); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
  margin-top: 14px;
}
.note { font-size: .85rem; color: var(--muted); }
.admin-link { font-size: .82rem; color: var(--muted); }
.heat { font-size: .82rem; }
.heat th, .heat td { text-align: center; min-width: 64px; }
.heat td.diag { font-weight: 800; }
#joint { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 639px) {
  .brand h1 { font-size: .95rem; }
  .who { width: 100%; }
  .who .ghost, .who .gold, .who .btn { flex: 1; }
  .roles { grid-template-columns: 1fr; }
  .code-xl { font-size: 1.25rem; word-break: break-word; }
  .seg label { flex: 0 1 auto; justify-content: flex-start; }
  .hero h2 { font-size: 1.2rem; }
  .card { padding: 14px; }
}
@media (min-width: 640px) and (max-width: 1023px) {
  .roles { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1280px) {
  .app { max-width: 1320px; }
}
@media (min-width: 1600px) {
  .app { max-width: 1480px; }
}
@media (hover: none) {
  .item:hover, .role:hover { border-color: var(--line); }
  .item:active, .role:active { border-color: var(--teal-2); }
}
