:root {
  --bg: #f5f5f5;
  --text: #333;
  --muted: #777;
  --border: #ddd;
  --border-soft: #e5e5e5;
  --panel: #fff;
  --panel-head: #f7f7f7;
  --primary: #337ab7;
  --primary-hover: #286090;
  --danger: #d9534f;
  --danger-hover: #c9302c;
  --success-bg: #dff0d8;
  --success-text: #3c763d;
  --success-border: #d6e9c6;
  --error-bg: #f2dede;
  --error-text: #a94442;
  --error-border: #ebccd1;
  --warning-bg: #fcf8e3;
  --warning-text: #8a6d3b;
  --warning-border: #faebcc;
  --info-bg: #d9edf7;
  --info-text: #31708f;
  --info-border: #bce8f1;
  --sidebar-bg: #222d32;
  --sidebar-active: #1e282c;
  --sidebar-hover: #2c3b41;
  --sidebar-text: #c2c7d0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.42857143;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
}

.brand {
  min-height: 50px;
  padding: 10px 16px 9px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  display: grid;
  gap: 1px;
}

.brand b {
  font-size: 17px;
  line-height: 1.15;
  font-weight: 600;
}

.brand span,
.side-user span {
  color: #9aa4af;
  font-size: 12px;
}

.sidebar nav {
  display: grid;
  gap: 0;
  padding: 10px 0;
}

.sidebar nav a,
.side-user a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 0;
  border-left: 3px solid transparent;
}

.sidebar nav a.active,
.sidebar nav a:hover,
.side-user a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar nav a.active {
  background: var(--sidebar-active);
  border-left-color: var(--primary);
}

.side-user {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, .08);
  padding: 12px 0 10px;
  display: grid;
  gap: 1px;
}

.side-user b,
.side-user span {
  padding: 0 16px;
}

.side-user a {
  margin-top: 4px;
}

.workarea {
  min-width: 0;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 6px 22px;
  min-height: 42px;
  display: flex;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  font-weight: 500;
  color: #222;
}

.topbar .muted {
  margin-top: 1px;
  font-size: 11px;
}

main {
  padding: 16px 24px;
  max-width: none;
  margin: 0;
}

h1,
h2,
h3 {
  margin-top: 0;
  color: #222;
  font-weight: 500;
}

h2 {
  margin-bottom: 15px;
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 10px;
  font-size: 18px;
}

p {
  margin: 0 0 10px;
}

.box {
  max-width: 420px;
  margin: 10vh auto;
  background: #fff;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}

.install-box {
  max-width: 620px;
}

.manual-config {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}

.manual-config textarea {
  width: 100%;
  min-height: 220px;
  box-sizing: border-box;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
}

.panel,
section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 17px 16px 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}

.head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.head h2,
.head p {
  margin-bottom: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 15px;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 15px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}

.num {
  font-size: 28px;
  line-height: 1.1;
  font-weight: 500;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.flash,
.error,
.err,
.secret-box {
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 15px;
  border: 1px solid transparent;
}

.flash {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

.error,
.err {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-border);
}

.secret-box {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-color: var(--warning-border);
}

.copy,
.token-view {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.42857143;
  font-weight: 400;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.btn:hover {
  background: var(--primary-hover);
  border-color: #204d74;
  color: #fff;
}

.secondary,
.mini {
  background: #fff;
  color: #333;
  border: 1px solid #ccc;
}

.secondary:hover,
.mini:hover {
  background: #e6e6e6;
  border-color: #adadad;
  color: #333;
}

.danger {
  background: var(--danger);
  border-color: var(--danger);
}

.danger:hover {
  background: var(--danger-hover);
  border-color: #ac2925;
}

.mini {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #fff;
  color: #555;
  font: inherit;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

input,
select {
  height: 34px;
  padding: 6px 12px;
}

textarea {
  padding: 6px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #66afe9;
  outline: 0;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  height: auto;
  padding: 0;
  margin: 0 6px 0 0;
  box-shadow: none;
}

label {
  display: grid;
  gap: 6px;
  margin: 0;
  font-weight: 700;
  font-size: 13px;
  color: #333;
}

.box label {
  margin-bottom: 10px;
}

.box input,
.box button {
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px 18px;
  align-items: start;
}

.grid .wide {
  grid-column: 1 / -1;
}

.grid p.wide {
  margin: 0;
}

.grid p.wide.muted {
  margin-top: 2px;
  padding-top: 2px;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 12px;
}

.perm-grid label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 400;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-list > div {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.settings-list b {
  font-weight: 700;
}

code {
  display: inline-block;
  width: 100%;
  min-height: 28px;
  background: #f5f5f5;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 7px;
  color: #333;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.wide {
  grid-column: 1 / -1;
}

.hidden {
  display: none;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 10px 0 12px;
}

.filters input,
.filters select {
  width: auto;
  min-width: 145px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  margin: 0;
}

.table th,
.table td {
  border-top: 1px solid var(--border);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.table tr:first-child th,
.table tr:first-child td {
  border-top: 0;
}

.table th {
  background: var(--panel-head);
  font-weight: 700;
}

.table tr:hover td {
  background: #f9f9f9;
}

.wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.bot-chip {
  display: inline-grid;
  grid-template-columns: 10px auto;
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
}

.bot-chip i {
  grid-row: 1 / 3;
  width: 10px;
  height: 100%;
  min-height: 22px;
  border-radius: 8px;
  background: var(--c);
}

.bot-chip small {
  color: var(--muted);
}

.st,
.http {
  border-radius: 4px;
  padding: 3px 7px;
  font-weight: 700;
  font-size: 12px;
  display: inline-block;
  border: 1px solid transparent;
}

.st-sent,
.ok {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

.st-failed,
.bad {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-border);
}

.st-pending,
.warn {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-color: var(--warning-border);
}

.st-processing {
  background: var(--info-bg);
  color: var(--info-text);
  border-color: var(--info-border);
}

.m-sendmessage {
  background: #f5fff5;
}

.m-forwardupdate,
.m-enqueue {
  background: #f7fffc;
}

.m-sendphoto,
.m-senddocument,
.m-sendvideo {
  background: #f7fbff;
}

.m-deletemessage {
  background: #fff7f7;
}

.pages {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.pages a,
.pages b,
.pages span {
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: #333;
}

.pages b {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 400;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.modal.open {
  display: flex;
}

.modal-card {
  background: #fff;
  border-radius: 4px;
  max-width: 1100px;
  width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
}

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

.modal-head h3,
.modal-head p {
  margin: 0;
}

.modal pre {
  padding: 14px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
}

.jk {
  color: #6d28d9;
}

.js {
  color: #166534;
}

.jn {
  color: #b45309;
}

.jb {
  color: #be123c;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats,
  .grid,
  .dash-grid,
  .perm-grid {
    grid-template-columns: 1fr;
  }

  .settings-list > div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .head {
    display: block;
  }

  .filters input,
  .filters select,
  .filters button,
  .filters .btn {
    width: 100%;
  }
}


/* Install/settings clarity */
.hint-box,
.setup-notice {
  display: grid;
  gap: 3px;
}

.hint-box {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid var(--info-border);
  border-radius: 4px;
}

.req {
  color: var(--danger);
  font-weight: 700;
}

label.required input,
label.required select,
label.required textarea {
  border-left: 3px solid var(--primary);
}

.help {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
}

.help code,
.muted code {
  width: auto;
  min-height: 0;
  padding: 1px 4px;
  display: inline-block;
}

.settings-form {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
}

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


/* Bot list redesign */
.bot-table th:last-child,
.bot-table td:last-child {
  min-width: 560px;
}

.bot-actions-cell {
  vertical-align: middle;
}

.bot-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.bot-actions-edit {
  margin-top: 10px;
}

.bot-actions-spacer {
  flex: 1 1 28px;
  min-width: 18px;
}

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

.btn-xs {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.4;
}

.icon-btn {
  width: 30px;
  padding-left: 0;
  padding-right: 0;
}

.success {
  background: #5cb85c;
  border-color: #4cae4c;
  color: #fff;
}

.success:hover {
  background: #449d44;
  border-color: #398439;
  color: #fff;
}

.info {
  background: #5bc0de;
  border-color: #46b8da;
  color: #fff;
}

.info:hover {
  background: #31b0d5;
  border-color: #269abc;
  color: #fff;
}

.warning {
  background: #f0ad4e;
  border-color: #eea236;
  color: #fff;
}

.warning:hover {
  background: #ec971f;
  border-color: #d58512;
  color: #fff;
}

.quick-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.quick-stats span {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 4px;
  min-height: 24px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.quick-stats b {
  font-weight: 700;
  font-size: 13px;
}

.quick-stats small {
  color: var(--muted);
  font-size: 11px;
}

.quick-stats-large span {
  min-height: 30px;
  padding: 4px 9px;
}

.ok-text b,
.ok-text small {
  color: var(--success-text);
}

.bad-text b,
.bad-text small {
  color: var(--error-text);
}

.webhook-state {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-label {
  display: inline-block;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #f5f5f5;
  color: #555;
  font-size: 12px;
}

.bot-info-list {
  display: grid;
  gap: 9px;
  padding: 4px 0;
}

.bot-info-list > div {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.bot-info-list b {
  font-size: 13px;
}

.bot-info-list code,
.token-view code {
  width: auto;
  min-width: min(360px, 100%);
  max-width: 100%;
}

.ajax-result {
  display: none;
  margin-top: 7px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid transparent;
}

.ajax-result:not(:empty) {
  display: block;
}

.ajax-result-ok {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

.ajax-result-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-border);
}

button.is-loading,
.btn.is-loading {
  position: relative;
  pointer-events: none;
  opacity: .82;
}

button.is-loading::before,
.btn.is-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btnSpin .65s linear infinite;
}

@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1200px) {
  .bot-table th:last-child,
  .bot-table td:last-child {
    min-width: 420px;
  }

  .bot-actions-spacer {
    flex-basis: 100%;
  }
}

@media (max-width: 700px) {
  .bot-info-list > div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* Bot table order / compact actions */
.bot-table {
  min-width: 1080px;
}

.bot-table th,
.bot-table td {
  vertical-align: middle;
}

.bot-table .id-col,
.bot-table th:first-child {
  width: 58px;
  white-space: nowrap;
}

.bot-table th:nth-child(2),
.bot-table td:nth-child(2) {
  width: 115px;
  white-space: nowrap;
}

.bot-table th:nth-child(3),
.bot-table td:nth-child(3) {
  min-width: 220px;
}

.bot-table th:nth-child(4),
.bot-table td:nth-child(4) {
  width: 150px;
  white-space: nowrap;
}

.bot-table .stats-col {
  min-width: 270px;
  width: 270px;
}

.bot-table th:nth-child(6),
.bot-table td:nth-child(6) {
  width: 210px;
  min-width: 210px;
}

.bot-table th:last-child,
.bot-table td:last-child {
  min-width: 158px;
  width: 158px;
}

.bot-chip-name b {
  font-size: 13px;
}

.webhook-cell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  gap: 6px;
}

.webhook-cell .inline-form {
  justify-self: end;
}

.webhook-cell .ajax-result {
  grid-column: 1 / -1;
  margin-top: 2px;
}

.webhook-state-compact {
  display: grid;
  gap: 2px;
  align-items: start;
}

.webhook-state-compact .st,
.webhook-state-compact .muted,
.webhook-state-compact .webhook-error {
  justify-self: start;
}

.webhook-error {
  color: var(--danger);
  font-size: 12px;
  cursor: help;
}

.actions-icons .bot-actions {
  flex-wrap: nowrap;
  gap: 5px;
}

.actions-icons .icon-btn {
  width: 30px;
  min-width: 30px;
  height: 28px;
  padding-left: 0;
  padding-right: 0;
  font-size: 14px;
}

.actions-icons svg {
  display: block;
}

.compact-table th,
.compact-table td {
  padding-top: 6px;
  padding-bottom: 6px;
}

@media (max-width: 1200px) {
  .bot-table th:last-child,
  .bot-table td:last-child {
    min-width: 158px;
    width: 158px;
  }

  .bot-actions-spacer {
    flex-basis: auto;
  }
}

.webhook-cell {
  display: table-cell;
}

.webhook-cell-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  gap: 6px;
}

.webhook-cell-inner .inline-form {
  justify-self: end;
}

.webhook-cell-inner .ajax-result {
  grid-column: 1 / -1;
}
