/* Telegram Bridge admin. Apple-inspired design system. */

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --surface-3: #f0f0f3;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --line: #d2d2d7;
  --line-soft: #e8e8ed;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: #eaf3fd;
  --green: #248a3d;
  --green-dot: #34c759;
  --green-bg: #e9f8ee;
  --orange: #b25000;
  --orange-dot: #ff9500;
  --orange-bg: #fff3e0;
  --red: #d70015;
  --red-dot: #ff3b30;
  --red-bg: #ffebe9;
  --radius: 16px;
  --radius-s: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 10px 32px rgba(0, 0, 0, 0.05);
  --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font: 400 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* ---------- header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line-soft);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(180deg, #0a84ff, #0066d6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand small {
  color: var(--text-3);
  font-weight: 500;
}

nav.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 980px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

nav.tabs a:hover { color: var(--text); background: var(--surface-3); }

nav.tabs a.active { color: var(--text); background: var(--surface-3); }

.nav-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 980px;
  background: var(--orange-dot);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0;
  vertical-align: middle;
  position: relative;
  top: 0.5px;
}

/* ---------- layout ---------- */

main.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

@media (prefers-reduced-motion: no-preference) {
  main.page {
    animation: page-rise 0.32s ease both;
  }
  @keyframes page-rise {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 6px;
}

.page-sub {
  color: var(--text-2);
  font-size: 15px;
  margin: 0 0 28px;
}

/* ---------- cards & sections ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.015em;
}

.card-sub {
  color: var(--text-2);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ---------- tables ---------- */

.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr { transition: background 0.12s ease; }

tbody tr:hover { background: var(--surface-2); }

.cell-strong { font-weight: 600; }
.cell-muted, .muted { color: var(--text-2); }
.cell-small { font-size: 12.5px; color: var(--text-3); white-space: nowrap; }
.cell-num { font-variant-numeric: tabular-nums; }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 980px;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.ok::before { background: var(--green-dot); }
.badge.warn { background: var(--orange-bg); color: var(--orange); }
.badge.warn::before { background: var(--orange-dot); }
.badge.err { background: var(--red-bg); color: var(--red); }
.badge.err::before { background: var(--red-dot); }
.badge.neutral { background: var(--surface-3); color: var(--text-2); }
.badge.neutral::before { background: var(--text-3); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.info::before { background: var(--accent); }

a.hsid {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

a.hsid:hover { text-decoration: underline; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 980px;
  font: 600 14px/1 var(--font);
  letter-spacing: -0.01em;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }

.btn:focus-visible,
nav.tabs a:focus-visible,
a.hsid:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus {
  outline: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
}

.btn-secondary:hover { background: var(--line-soft); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
}

.btn-danger:hover { background: #ffdfdc; }

.btn-sm { padding: 6px 13px; font-size: 13px; }

.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ---------- forms ---------- */

input[type="text"], input[type="password"], input[type="number"],
input[type="email"] {
  font: 400 14px var(--font);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-s);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease;
  min-width: 0;
}

input:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.16);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

.field { margin-bottom: 18px; }
.field input { width: 100%; max-width: 420px; }
.field-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field-inline .btn { margin-bottom: 1px; }
.field-inline input { flex: 0 1 auto; }

.hint { color: var(--text-3); font-size: 12.5px; margin-top: 6px; }

/* ---------- callouts ---------- */

.callout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 13px 16px;
  border-radius: var(--radius-s);
  font-size: 13.5px;
  margin-bottom: 20px;
}

.callout-ok { background: var(--green-bg); color: var(--green); }
.callout-err { background: var(--red-bg); color: var(--red); }

/* ---------- empty state ---------- */

.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-2);
}

.empty .glyph { font-size: 34px; margin-bottom: 10px; }
.empty .primary { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty .secondary { font-size: 13.5px; }

/* ---------- misc ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  row-gap: 8px;
  align-items: center;
}

.actions form { display: inline-flex; margin: 0; }

.inline-form {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

code {
  font: 500 12.5px ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 6px;
}

.divider { border: none; border-top: 1px solid var(--line-soft); margin: 20px 0; }

footer.pagefoot {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 40px;
  color: var(--text-3);
  font-size: 12px;
}

.msg-toggle {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.msg-toggle:hover { text-decoration: underline; }

.dir-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
}

.dir-out {
  background: var(--green-bg);
  color: var(--green);
}

.dir-in {
  background: var(--red-bg);
  color: var(--red);
}

tr.msgs-row > td {
  background: var(--surface-2);
  padding: 6px 18px 14px;
}

.bubbles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 4px 2px;
  width: 100%;
}

.bubble {
  max-width: 76%;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 14px;
  box-shadow: var(--shadow-s);
}

.bubble.in {
  align-self: flex-start;
  margin-right: auto;
  background: var(--surface-3);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.bubble.out {
  align-self: flex-end;
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble-from {
  font-size: 10.5px;
  font-weight: 600;
  opacity: 0.65;
  margin-bottom: 2px;
  letter-spacing: 0.01em;
}

.bubble-time {
  font-size: 10.5px;
  margin-top: 3px;
  opacity: 0.6;
  text-align: right;
}

/* iOS-style segmented toggle */
.ios-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-3);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}

.ios-seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-3);
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
  background: transparent;
}

.ios-seg:hover {
  color: var(--text-2);
}

.ios-seg svg {
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

/* active segment: white pill, shadow, brand icon color */
.ios-act {
  background: var(--surface);
  color: var(--text);
  box-shadow:
    0 1px 3px rgba(0,0,0,0.08),
    0 1px 2px rgba(0,0,0,0.06);
}

.ios-act svg { opacity: 1; }

.ios-act-tg svg { color: #229ED9; }
.ios-act-wa svg { color: #25D366; }

/* old styles removed */

@media (max-width: 720px) {
  .topbar-inner { gap: 14px; padding: 0 16px; }
  .brand small { display: none; }
  main.page { padding: 24px 16px 56px; }
  .page-title { font-size: 24px; }
  .card { padding: 18px; }
  td, th { padding: 11px 12px; }
}
