:root {
  --paper: #fbfbf8;
  --ink: #111f1d;
  --teal: #439e9f;
  --teal-d: #2a6e6f;
  --teal-l: #eaf4f3;
  --line: #e4e8e2;
  --line2: #eef1ec;
  --muted: #68756e;
  --soft: #f2f5f1;
  --white: #fff;
  --ok: #2fa96b;
  --warn: #dd8b2c;
  --danger: #c0564f;
  --wa: #25d366;
  --wa-d: #075e54;
  --r: 14px;
  --shadow: 0 18px 44px -20px rgba(17, 31, 29, .22);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1;
}

a { color: var(--teal-d); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { display: flex; min-height: 100vh; }

/* Rail */
.rail {
  width: 240px;
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--white);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  z-index: 60;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: auto; display: block; object-fit: contain; }
.brand .nm { font-size: 16.5px; font-weight: 800; letter-spacing: -.025em; line-height: 1.1; }
.brand .nm small {
  display: block;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}

.rnav { display: flex; flex-direction: column; gap: 2px; }
.rnav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: #37474a;
  text-decoration: none;
  position: relative;
}
.rnav a .ic { width: 18px; text-align: center; font-size: 14px; opacity: .62; flex: none; }
.rnav a:hover { background: var(--soft); color: var(--ink); text-decoration: none; }
.rnav a.on { background: var(--teal-l); color: var(--teal-d); }
.rnav a.on .ic { opacity: 1; }
.rnav a.on::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 19px;
  border-radius: 0 3px 3px 0;
  background: var(--teal);
}
.rnav .count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--soft);
  border-radius: 999px;
  padding: 1px 7px;
}
.rnav a.on .count { background: var(--white); color: var(--teal-d); }

.rail .spacer { flex: 1; }
.railbox {
  background: var(--soft);
  border: 1px solid var(--line2);
  border-radius: 11px;
  padding: 13px;
}
.railbox .lv {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--ok);
  letter-spacing: .02em;
  margin-bottom: 7px;
}
.railbox .lv i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 169, 107, .16);
}
.railbox b { display: block; font-size: 15px; letter-spacing: -.02em; margin-bottom: 1px; }
.railbox p { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 0; }

.page { flex: 1; min-width: 0; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(251, 251, 248, .9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar .in {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 560px;
}
.search span { color: var(--muted); font-size: 16px; }
.search input {
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  width: 100%;
  color: var(--ink);
}
.tb-r { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ok);
  background: #e7f6ec;
  border: 1px solid #c3e6d1;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}
.local-badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}

.wrap { max-width: 1400px; margin: 0 auto; padding: 22px 22px 48px; }

.eyebrow {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.h1 { font-size: 26px; margin: 5px 0 4px; letter-spacing: -.025em; line-height: 1.2; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0; max-width: 760px; }
.head { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid #dfe5e0;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.2;
}
.btn:hover { border-color: var(--teal); color: var(--teal-d); text-decoration: none; }
.btn.pri { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.pri:hover { background: var(--teal-d); color: #fff; }
.btn.wa { background: var(--wa-d); border-color: var(--wa-d); color: #fff; }
.btn.wa:hover { background: #064a43; color: #fff; }
.btn.danger { color: var(--danger); border-color: #eccaca; }
.btn.danger:hover { background: #fdecec; border-color: var(--danger); }
.btn.sm { padding: 5px 9px; font-size: 11.5px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
}
.card-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.card-sub { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat b { font-size: 25px; letter-spacing: -.03em; color: var(--teal-d); line-height: 1.1; }
.stat span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.stat.warn b { color: var(--warn); }
.stat.dead b { color: var(--danger); }
.stat.wa b { color: var(--wa-d); }

.cols { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; }
.cols3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: #f7f9f7;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fbf9; }
.table .num { text-align: right; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }

.person-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--teal-l);
  color: var(--teal-d);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  flex: none;
  letter-spacing: .02em;
}
.avatar.lg { width: 54px; height: 54px; font-size: 17px; }
.person-cell .nm { font-weight: 700; line-height: 1.25; }
.person-cell .meta { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
}
.chip.wa { background: #e7f8ec; border-color: #c3e6d1; color: #116d4e; }
.chip.google { background: #e8f0fe; border-color: #c9daf8; color: #2456a6; }
.chip.icloud { background: #eef2f7; border-color: #d8e1ea; color: #48657f; }
.chip.torg { background: #e6f4f3; border-color: #c5e3e1; color: var(--teal-d); }
.chip.dead { background: #fdecec; border-color: #f3caca; color: #a02b2b; }
.chip.arch { background: #f4f1e8; border-color: #e5ddc8; color: #7b6a3a; }
.chip.protect { background: #eef7ef; border-color: #cfe6d2; color: #2b6b3b; }
.chip.score { background: #fff4e0; border-color: #f0d9b5; color: #8a5a17; }
.chip.tag { background: var(--teal-l); border-color: #cfe6e4; color: var(--teal-d); }

/* Forms */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 14px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.field label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.input, .select, textarea.input {
  padding: 8px 10px;
  border: 1px solid #dfe5e0;
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  background: var(--white);
  color: var(--ink);
  outline: none;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(67, 158, 159, .12); }
.input.grow { min-width: 220px; flex: 1; }
textarea.input { resize: vertical; min-height: 74px; }

/* Pager */
.pager { display: flex; align-items: center; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager .btn { min-width: 34px; justify-content: center; }
.pager .cur { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line2); }
.tl-item:last-child { border-bottom: 0; }
.tl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  margin-top: 7px;
  flex: none;
}
.tl-dot.wa { background: var(--wa); }
.tl-dot.warn { background: var(--warn); }
.tl-dot.dead { background: var(--danger); }
.tl-body { min-width: 0; flex: 1; }
.tl-title { font-size: 12.5px; font-weight: 600; line-height: 1.35; }
.tl-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* Detail */
.detail-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head .who { flex: 1; min-width: 240px; }
.detail-head .who h1 { margin: 0; font-size: 27px; letter-spacing: -.03em; line-height: 1.15; }
.detail-head .who .line { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 14px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.kv .v { min-width: 0; overflow-wrap: anywhere; }
.label-row { display: flex; gap: 8px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line2); font-size: 12.5px; }
.label-row:last-child { border-bottom: 0; }
.label-row .val { font-weight: 600; }
.label-row .own { color: var(--muted); font-size: 11px; }
.label-row .period { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.event-row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line2); font-size: 12.5px; }
.event-row:last-child { border-bottom: 0; }
.event-row .ev { font-weight: 600; white-space: nowrap; }
.event-row .delta { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }

/* Duplicates */
.dup { border: 1px solid var(--line); border-radius: var(--r); background: var(--white); padding: 14px; margin-bottom: 12px; }
.dup-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.dup-top .score { margin-left: auto; }
.dup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dup-side { border: 1px solid var(--line2); border-radius: 10px; padding: 12px; background: #fcfdfc; }
.dup-side .nm { font-weight: 700; font-size: 14px; }
.dup-side .meta { font-size: 11.5px; color: var(--muted); }
.dup-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line2); }
.reasons { display: flex; gap: 5px; flex-wrap: wrap; }

/* Empty */
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty b { display: block; font-size: 16px; color: var(--ink); margin-bottom: 4px; }

/* Flash */
.flash { display: grid; gap: 8px; margin-bottom: 14px; }
.fl { padding: 10px 14px; border-radius: 10px; font-size: 13px; border: 1px solid var(--line); background: var(--white); }
.fl.success { background: #e7f6ec; border-color: #c3e6d1; color: #1d6b41; }
.fl.error { background: #fdecec; border-color: #f3caca; color: #a02b2b; }
.fl.warning { background: #fff8e1; border-color: #f0d9b5; color: #8a5a17; }

/* Footer */
.foot {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 22px 30px;
  color: var(--muted);
  font-size: 11.5px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Mobile */
.mobhead { display: none; }
.mobnav { display: none; }

@media (max-width: 980px) {
  .rail { display: none; }
  .mobhead {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 70;
  }
  .mobhead .brand { padding: 0; }
  .mobnav {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 8px 12px;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 57px;
    z-index: 65;
  }
  .mobnav a {
    padding: 7px 11px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    text-decoration: none;
  }
  .mobnav a.on { background: var(--teal-l); color: var(--teal-d); }
  .topbar { position: static; }
  .topbar .in { padding: 10px 16px; }
  .wrap { padding: 16px 16px 36px; }
  .cols, .detail-grid { grid-template-columns: 1fr; }
  .dup-grid { grid-template-columns: 1fr; }
  .h1 { font-size: 23px; }
}

@media (max-width: 560px) {
  .search { max-width: none; }
  .tb-r .btn { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .detail-head .who h1 { font-size: 23px; }
  .filters { padding: 10px; }
  .field { min-width: 100%; }
  .input.grow { min-width: 0; }
  .foot { flex-direction: column; }
}

/* Login */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 10%, #eaf4f3 0, #fbfbf8 45%, #f2f5f1 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card img { display: block; }

.chip.hidden {
  background: #2b2f33;
  border-color: #2b2f33;
  color: #fff;
}
