:root {
  --bg: #12141a;
  --card: #1b1f29;
  --border: #2c3344;
  --text: #e8ecf4;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --ok: #3ecf8e;
  --err: #ff6b6b;
  --warn: #f0b429;
  --shell: 1120px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% -10%, #1e2740, var(--bg));
  padding: 24px 20px 40px;
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3.sub {
  margin: 18px 0 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.muted { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.err-text {
  color: var(--err);
  font-size: 12px;
  min-height: 1.2em;
  white-space: pre-wrap;
  margin-top: 8px;
  word-break: break-word;
}
.hidden { display: none !important; }

#appView {
  width: 100%;
  max-width: var(--shell);
  margin: 0 auto;
}

.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 14px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  margin: 12vh auto;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.row.between {
  justify-content: space-between;
  width: 100%;
  margin-bottom: 10px;
}
.row.between h2 { flex: 1; min-width: 0; }

label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #12161f;
  color: var(--text);
  margin-bottom: 10px;
  font: inherit;
}

button {
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled { opacity: 0.5; cursor: wait; }
.primary { background: var(--accent); color: #fff; }
.ghost { background: #2a3142; color: var(--text); }
.danger { background: #4a2430; color: #ffb4b4; }

.status-line { font-size: 14px; margin: 4px 0 10px; }

.bar-wrap {
  height: 12px;
  width: 100%;
  background: #10141d;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 0 0 8px;
}

.bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3d6df0, #5b8cff);
  transition: width 0.35s ease;
}

.sessions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.slot {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: #151a24;
  min-width: 0;
}
.slot.expired {
  border-color: #7a3038;
  background: #2a1518;
}

.slot .id { font-weight: 700; margin-bottom: 2px; }
.slot .proxy {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge.ok { background: #1d3b2e; color: var(--ok); }
.badge.err { background: #3b1f24; color: var(--err); }
.badge.warn { background: #3a3018; color: var(--warn); }
.badge.muted { background: #2a2f3a; color: var(--muted); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  word-break: break-word;
}
th { color: var(--muted); font-weight: 600; }
th:nth-child(1), td:nth-child(1) { width: 48px; }
th:nth-child(2), td:nth-child(2) { width: 90px; }
th:nth-child(3), td:nth-child(3) { width: 70px; }

.webhook-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px auto;
  gap: 8px;
  align-items: center;
  margin: 10px 0 14px;
}
.webhook-form input { margin: 0; min-width: 0; }

.hooks { display: flex; flex-direction: column; gap: 8px; }
.hook {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #151a24;
}
.hook .url {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.hook .meta { margin-top: 6px; }
.hook .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

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

@media (max-width: 700px) {
  body { padding: 16px 12px 28px; }
  .webhook-form { grid-template-columns: 1fr; }
  .hook { grid-template-columns: 1fr; }
  .hook .actions { justify-content: flex-start; }
  .row.between {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .top { align-items: flex-start; }
}
