*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --accent: #5b9cf6;
  --accent-hover: #3d7de0;
  --danger: #e05b5b;
  --success: #4caf7d;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --border: #2d3248;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.channel {
  background: var(--surface2);
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: monospace;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.card h2 small {
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 8px;
}

/* Keywords */
.keyword-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.keyword-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 4px 4px 14px;
}

.keyword-list li span {
  font-size: 0.9rem;
}

.btn-remove {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.78rem;
  transition: background 0.15s;
}

.btn-remove:hover { background: rgba(224, 91, 91, 0.12); }

.add-form {
  display: flex;
  gap: 8px;
}

.add-form input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.add-form input:focus { border-color: var(--accent); }

.btn-add {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-add:hover { background: var(--accent-hover); }

/* Recipients */
.recipient-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recipient-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.recipient-name {
  flex: 1;
  font-weight: 500;
}

.status {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
}

.status.active  { background: rgba(76, 175, 125, 0.15); color: var(--success); }
.status.inactive { background: rgba(136, 146, 164, 0.12); color: var(--text-muted); }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* Log table */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

td { padding: 10px 12px; vertical-align: top; }

td.ts {
  white-space: nowrap;
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.78rem;
}

td.msg-text {
  max-width: 480px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.badge {
  background: rgba(91, 156, 246, 0.15);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
  font-style: italic;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 1000;
  transition: opacity 0.3s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast.success { background: var(--success); color: #fff; }
.toast.error   { background: var(--danger); color: #fff; }
.toast.hidden  { display: none; }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-box h1 { font-size: 1.4rem; color: var(--accent); text-align: center; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 0.88rem; margin-top: -12px; }

.login-error {
  background: rgba(224, 91, 91, 0.12);
  border: 1px solid rgba(224, 91, 91, 0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .field input { padding-right: 14px; font-family: inherit; }
.btn-full { width: 100%; justify-content: center; margin-top: 4px; }

/* Header right group */
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-tag {
  background: rgba(91, 156, 246, 0.15);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Recipient card */
.recipient-card { display: flex; flex-direction: column; gap: 14px; }

.recipient-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.recipient-info { display: flex; align-items: center; gap: 12px; }

.recipient-name-big {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.test-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.btn-test {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s;
}
.btn-test:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-test:disabled { opacity: 0.5; cursor: not-allowed; }

.empty-kw {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
  padding: 4px 0;
  list-style: none;
}

/* Setup page */
.btn-setup {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 14px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.btn-setup:hover { border-color: var(--accent); color: var(--accent); }

.badge-warn {
  margin-left: auto;
  background: rgba(224, 91, 91, 0.15);
  color: var(--danger);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.setup-step { display: flex; flex-direction: column; gap: 16px; }

.step-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.step-number {
  flex-shrink: 0;
  width: 32px; height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 2px;
}

.step-header h2 {
  margin-bottom: 4px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 1rem;
  color: var(--text);
}

.step-desc { color: var(--text-muted); font-size: 0.88rem; margin: 0; }

.guide {
  list-style: decimal;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.guide strong { color: var(--text); }
.guide code {
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85em;
  color: var(--accent);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-style: italic;
  font-size: 0.78rem;
}

.field input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  font-family: monospace;
  transition: border-color 0.15s;
  padding-right: 80px;
}

.field input:focus { border-color: var(--accent); }

.btn-eye {
  position: absolute;
  right: 10px;
  bottom: 9px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 4px;
}
.btn-eye:hover { color: var(--accent); }

.save-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.save-status {
  color: var(--success);
  font-size: 0.85rem;
  font-weight: 500;
}

.add-recipient-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.add-recipient-form input {
  flex: 1;
  min-width: 140px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.add-recipient-form input:focus { border-color: var(--accent); }

.chat-id-badge {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

@media (max-width: 600px) {
  .add-form { flex-direction: column; }
  td.msg-text { max-width: 180px; }
  .step-header { flex-direction: column; }
}
