:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e8ecf1;
  --text: #1a1d26;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --navbar-h: 60px;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
  scrollbar-width: none;
}

*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.admin-layout {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.admin-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 16px clamp(12px, 2vw, 20px);
  display: flex;
  flex-direction: column;
}

/* ── Navbar ── */
.admin-navbar {
  flex-shrink: 0;
  position: relative;
  z-index: 100;
  height: var(--navbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.navbar-inner {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon svg {
  width: 18px;
  height: 18px;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

/* ── Table card ── */
.card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  max-width: 100%;
  scrollbar-width: thin;
}

.table-wrap::-webkit-scrollbar {
  display: block;
  width: 8px;
  height: 8px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #c5cbd3;
  border-radius: 8px;
}

.data-table {
  width: 100%;
  height: auto;
  min-height: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table thead {
  background: #f9fafb;
}

.data-table thead tr {
  height: 44px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr {
  height: auto;
}

.data-table td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
  height: inherit;
}

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

.data-table tbody tr:hover td {
  background: #fafbfc;
}

.col-id,
.id-cell {
  width: 4%;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.col-account,
.account-cell {
  width: 14%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.col-nickname,
.nickname-cell {
  width: 12%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #374151;
  font-weight: 500;
}

.col-code,
.code-cell {
  width: 9%;
}

.code-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.col-status,
.status-td {
  width: 10%;
}

.status-cell {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.col-block,
.block-td {
  width: 6%;
}

.col-time,
.time-cell {
  width: 9%;
}

.time-cell {
  white-space: nowrap;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.col-notes,
.notes-cell {
  width: 16%;
}

.notes-cell {
  cursor: pointer;
  color: #374151;
  font-size: 13px;
  line-height: 1.45;
  min-width: 0;
}

.notes-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes-cell:hover {
  background: #eef4ff !important;
  color: var(--primary);
}

.notes-empty {
  color: #9ca3af;
}

.col-actions,
.actions {
  width: 22%;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px !important;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #f9fafb;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: #f9fafb;
  color: var(--text);
}

.btn-telethon {
  background: #1677ff;
  color: #fff;
}

.btn-telethon:hover:not(:disabled) {
  background: #4096ff;
}

.badge-telethon-ready {
  background: rgba(82, 196, 26, 0.15);
  color: #389e0d;
}

.badge-telethon-pending {
  background: rgba(22, 119, 255, 0.15);
  color: #1677ff;
}

.badge-telethon-error {
  background: rgba(255, 77, 79, 0.15);
  color: #cf1322;
}

.badge-telethon-idle {
  background: rgba(0, 0, 0, 0.06);
  color: #8c8c8c;
}

.badge-telethon-ready::before,
.badge-telethon-pending::before,
.badge-telethon-error::before,
.badge-telethon-idle::before {
  display: none;
}

.btn-session {
  background: #52c41a;
  color: #fff;
}

.btn-session:hover:not(:disabled) {
  background: #73d13d;
}

.btn-tdata {
  background: #722ed1;
  color: #fff;
}

.btn-tdata:hover:not(:disabled) {
  background: #9254de;
}

.btn-delete {
  background: #ff4d4f;
  color: #fff;
}

.btn-delete:hover:not(:disabled) {
  background: #ff7875;
}

/* ── Badges & switch ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

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

.badge-online {
  background: #f0fdf4;
  color: var(--success);
}

.badge-online::before {
  background: var(--success);
}

.badge-offline {
  background: #f9fafb;
  color: var(--text-muted);
}

.badge-offline::before {
  background: #9ca3af;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d1d5db;
  border-radius: 22px;
  transition: 0.2s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider:before {
  transform: translateX(18px);
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal.hidden,
.toast.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  width: 440px;
  max-width: 100%;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.modal-content h2 {
  margin: 0 0 20px;
  font-size: 17px;
  font-weight: 600;
}

.form-hint {
  margin: -8px 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.form-hint strong {
  color: var(--text);
  font-weight: 600;
}

.modal-content label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.modal-content input,
.modal-content textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fafbfc;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.modal-content input:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  background: #fff;
}

.checkbox-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: 400 !important;
  color: var(--text) !important;
}

.checkbox-row input {
  width: auto;
  margin: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 4px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--text);
  color: #fff;
  padding: 11px 18px;
  border-radius: 9px;
  font-size: 13px;
  z-index: 1100;
  box-shadow: var(--shadow-md);
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
}

.actions .btn {
  margin-right: 0;
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 5px;
}

/* ── Responsive ── */
@media (max-width: 1280px) {
  .col-time,
  .time-cell {
    display: none;
  }
}

@media (max-width: 1100px) {
  .col-id,
  .id-cell {
    display: none;
  }
}

@media (max-width: 900px) {
  .col-code,
  .code-cell {
    display: none;
  }

  .navbar-inner {
    gap: 12px;
    padding: 0 16px;
  }

  .navbar-actions .btn {
    font-size: 0;
    padding: 8px;
    gap: 0;
  }

  .navbar-actions .btn svg {
    width: 18px;
    height: 18px;
  }

  .admin-main {
    padding: 12px;
  }
}

@media (max-width: 720px) {
  .table-wrap {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .data-table {
    table-layout: auto;
    height: auto;
  }

  .data-table tbody tr {
    height: auto;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody,
  .data-table tr,
  .data-table td,
  .col-id,
  .id-cell,
  .col-code,
  .code-cell,
  .col-time,
  .time-cell {
    display: block;
    width: auto;
  }

  .data-table tr {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
  }

  .data-table tbody tr:hover td {
    background: transparent;
  }

  .data-table td {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
    border-bottom: none;
    align-items: start;
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
  }

  .account-cell,
  .nickname-cell,
  .code-cell {
    white-space: normal;
    text-overflow: unset;
    overflow: visible;
  }

  .col-notes,
  .notes-cell {
    width: auto;
    max-width: none;
    display: grid;
    overflow: visible;
  }

  .notes-text {
    white-space: normal;
    text-overflow: unset;
    overflow: visible;
  }

  .notes-cell {
    cursor: pointer;
  }

  .data-table td.actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    padding-top: 10px;
  }

  .data-table td.actions::before {
    display: none;
  }
}

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

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand .brand-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 12px;
}

.login-brand h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
}

.login-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.login-form label {
  display: block;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.login-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.login-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

