:root {
  --bg: #0f1117;
  --bg-elev: #161922;
  --bg-soft: #1d2230;
  --fg: #e6e8ee;
  --muted: #8a93a6;
  --accent: #7c5cff;
  --accent-hover: #9070ff;
  --accent-soft: #2a2348;
  --danger: #ff5d6c;
  --danger-soft: #3a1a22;
  --ok: #38d39f;
  --ok-soft: #14352b;
  --warn: #ffb347;
  --tg-blue: #2ea6ff;
  --tg-blue-hover: #1e96e8;
  --border: #232838;
  --radius: 10px;
  --radius-lg: 14px;
  --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  margin: 0; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- topbar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.4rem;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar .brand {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: .2rem; }
.topbar nav a {
  padding: .35rem .7rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: .9rem;
  transition: all .15s ease;
}
.topbar nav a:hover { background: var(--bg-soft); color: var(--fg); text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.topbar nav a.logout { color: var(--danger); }
.topbar nav a.logout:hover { background: var(--danger-soft); }

.container { max-width: 1080px; margin: 1.5rem auto; padding: 0 1.2rem; }
h1 { font-weight: 700; font-size: 1.6rem; letter-spacing: -0.02em; margin: 0 0 0.1rem; }
h2 { font-weight: 600; letter-spacing: -0.01em; }

/* --- cards --- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .8rem; margin: 1rem 0 1.6rem; }
.card { background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; transition: border-color .15s; }
.card:hover { border-color: var(--accent-soft); }
.card-label { color: var(--muted); font-size: .8rem; text-transform: uppercase;
  letter-spacing: .08em; margin-bottom: .4rem; }
.card-value { font-size: 1.4rem; font-weight: 600; }
.card .value { margin-top: .6rem; }

code {
  background: var(--bg-soft);
  padding: .1em .35em;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: .88em;
  color: var(--accent);
}
pre code { background: none; padding: 0; border-radius: 0; color: inherit; }

/* --- quick actions --- */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .6rem;
  margin: 1rem 0 1.6rem;
}
.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem .8rem;
  color: var(--fg);
  font-size: .85rem;
  font-weight: 500;
  transition: all .15s ease;
  cursor: pointer;
  text-decoration: none;
}
.quick-action:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
  transform: translateY(-2px);
}
.quick-action .icon { font-size: 1.6rem; }

/* --- table --- */
.table { width: 100%; border-collapse: collapse; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .6rem .9rem;
  border-bottom: 1px solid var(--border); }
.table th { background: var(--bg-soft); color: var(--muted); font-weight: 500;
  font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }

/* --- badge --- */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; background: var(--accent-soft); color: var(--accent); }
.badge.builtin { background: #1f2a38; color: #6fa8ff; }
.badge.custom  { background: #1f2e22; color: #6fde9b; }
.badge.url     { background: #2a2520; color: #e8b86f; }

/* --- button --- */
button, .button {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--accent); color: white; border: 0;
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  font-weight: 500; font-size: .85rem;
  transition: all .15s ease;
}
button:hover, .button:hover { filter: brightness(1.12); text-decoration: none;
  transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.danger { background: var(--danger); }
button.outline { background: transparent; border: 1px solid var(--border); color: var(--fg); }
button.outline:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
button.small { padding: .3rem .6rem; font-size: .8rem; }
button + button, button + form { margin-left: .4rem; }

/* --- input --- */
input[type=text], input[type=password], input[type=url], input[type=tel] {
  background: var(--bg-soft); color: var(--fg); border: 1px solid var(--border);
  padding: .5rem .7rem; border-radius: 8px; min-width: 16rem; font-size: .9rem;
  transition: border-color .15s;
}
input:focus { outline: none; border-color: var(--accent); }

.row-form { display: flex; gap: .6rem; flex-wrap: wrap; }

/* --- flash --- */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.flash.info { background: #1a2740; color: #6fa8ff; border: 1px solid #2a3f60; }

/* --- misc --- */
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .9rem; }

/* --- db --- */
details.db-module { background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: .6rem;
  transition: border-color .15s; }
details.db-module[open] { border-color: var(--accent-soft); }
details.db-module summary { cursor: pointer; padding: .3rem 0; font-size: .95rem; }
.value { background: var(--bg-soft); padding: .5rem .7rem; border-radius: 6px;
  font-family: var(--mono); font-size: .85rem; white-space: pre-wrap;
  word-break: break-word; max-height: 240px; overflow: auto; margin: 0; }

/* --- page header --- */
.page-header { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.2rem; flex-wrap: wrap; gap: .5rem; }
.page-header h1 { margin: 0; }
.page-header .hint { color: var(--muted); font-size: .85rem; }

/* --- stats row on dashboard --- */
.stat-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.stat-item { background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .7rem 1rem; flex: 1; min-width: 120px; }
.stat-item .label { color: var(--muted); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .06em; }
.stat-item .value { font-size: 1.2rem; font-weight: 600; padding: 0; background: none; max-height: none; }

/* ====================================================================
   Telegram-style auth
   ==================================================================== */

/* --- animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%      { opacity: .4; }
}

.fade-in { animation: fadeIn .35s ease both; }
.shake   { animation: shake .4s ease both; }

/* --- centering --- */
.auth-centered {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

/* --- auth card --- */
.auth-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 2rem 2rem 1.8rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 380px;
  box-sizing: border-box;
  overflow-x: hidden;
  box-shadow: var(--shadow-lg);
  animation: fadeIn .35s ease both;
  text-align: center;
}
.auth-card .icon-plane {
  display: block;
  margin: 0 auto .4rem;
  color: var(--accent);
}
.auth-card h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 .1rem;
  color: var(--fg);
}
.auth-card .subtitle {
  color: var(--muted);
  font-size: .85rem;
  margin: 0 0 1.2rem;
}
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: .8rem;
  text-align: left;
}
.auth-card .error-msg,
.auth-card .ok-msg {
  padding: .45rem .7rem;
  border-radius: 8px;
  font-size: .85rem;
  animation: slideUp .25s ease both;
  margin-bottom: .2rem;
}
.auth-card .error-msg {
  background: var(--danger-soft);
  color: var(--danger);
}
.auth-card .ok-msg {
  background: rgba(56, 211, 159, .15);
  color: var(--ok);
}

/* --- Telegram-style input --- */
.tg-input {
  width: 100%;
  background: var(--bg-soft);
  color: var(--fg);
  border: 2px solid var(--border);
  padding: 0 14px;
  height: 40px;
  border-radius: 10px;
  font-size: .9rem;
  line-height: 1;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.tg-input:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px rgba(46, 166, 255, .15);
}
.tg-input.valid {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(56, 211, 159, .15);
}
.tg-input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 93, 108, .15);
  animation: shake .4s ease both;
}
.tg-input::placeholder { color: var(--muted); font-size: .95rem; }

/* --- Telegram-style button --- */
.tg-btn {
  width: 100%;
  height: 40px;
  background: var(--tg-blue);
  color: white;
  border: 0;
  padding: 0 14px;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s ease, transform .1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
}
.tg-btn:hover { background: var(--tg-blue-hover); transform: translateY(-1px); }
.tg-btn:active { transform: translateY(0); }
.tg-btn:disabled { opacity: .5; cursor: default; transform: none; }
.tg-btn .arrow { font-size: 1.1rem; }

/* --- phone row --- */
.phone-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
}
.country-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  height: 40px;
  cursor: pointer;
  transition: border-color .2s ease;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 68px;
  line-height: 1;
}
.country-picker:hover { border-color: var(--tg-blue); }
.country-picker .flag {
  display: flex;
  align-items: center;
  line-height: 1;
}
.country-picker .code { font-size: .85rem; color: var(--fg); font-weight: 500; }
.country-picker .chevron { font-size: .65rem; color: var(--muted); margin-left: 2px; }
.phone-input {
  width: 100%;
  height: 40px;
  background: var(--bg-soft);
  color: var(--fg);
  border: 2px solid var(--border);
  padding: 0 14px;
  border-radius: 10px;
  font-size: .9rem;
  line-height: 1;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.phone-input:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px rgba(46, 166, 255, .15);
}

/* --- country modal --- */
.country-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease both;
}
.country-modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  max-height: min(70vh, 480px);
  display: flex;
  flex-direction: column;
  padding: .75rem 0;
  animation: slideUp .25s ease both;
}
.country-modal-header {
  padding: 0 1rem .8rem;
  border-bottom: 1px solid var(--border);
}
.country-search {
  width: 100%;
  background: var(--bg-soft);
  color: var(--fg);
  border: 2px solid var(--border);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: .85rem;
  transition: border-color .2s ease;
}
.country-search:focus { border-color: var(--tg-blue); outline: none; }
.country-search::placeholder { color: var(--muted); }
.country-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  margin: 0;
  list-style: none;
}
.country-list::-webkit-scrollbar { width: 4px; }
.country-list::-webkit-scrollbar-track { background: transparent; }
.country-list::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 4px; }
.country-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 1rem;
  cursor: pointer;
  transition: background .1s ease;
}
.country-item:hover { background: var(--bg-soft); }
.country-item .flag {
  display: flex;
  align-items: center;
  line-height: 1;
}
.flag-img {
  width: 28px;
  height: 21px;
  border-radius: 3px;
  display: block;
  object-fit: cover;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.country-item .name  { flex: 1; font-size: .95rem; color: var(--fg); }
.country-item .code  { color: var(--muted); font-size: .9rem; font-weight: 500; }
.country-item.hidden { display: none; }

/* --- step indicator --- */
.steps {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  margin-bottom: 1.5rem;
}
.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}
.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  transition: all .3s ease;
  position: relative;
  z-index: 2;
}
.step-dot.active  { background: var(--tg-blue); color: #fff; }
.step-dot.done    { background: var(--ok); color: #fff; }
.step-dot.pending { background: var(--bg-soft); color: var(--muted); }
.step-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-top: 2px;
}
.step-label.active { color: var(--tg-blue); }
.step-label.done   { color: var(--ok); }
.step-line {
  width: 40px;
  height: 2px;
  background: var(--bg-soft);
  margin: 0 4px;
  margin-top: -10px;
  transition: background .3s ease;
}
.step-line.done { background: var(--ok); }

/* --- code boxes --- */
.code-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: .6rem 0;
  flex-wrap: wrap;
}
.code-box {
  width: 40px;
  max-width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
  cursor: text;
  user-select: none;
  transition: border-color .2s ease, box-shadow .2s ease;
  box-sizing: border-box;
  flex-shrink: 0;
}
@media (max-width: 400px) {
  .code-row { gap: 6px; }
  .code-box { width: 36px; height: 36px; font-size: .9rem; }
}
@media (max-width: 340px) {
  .code-row { gap: 4px; }
  .code-box { width: 32px; height: 32px; font-size: .85rem; }
}
.code-box:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px rgba(46, 166, 255, .15);
  outline: none;
}
.code-box.filled {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(56, 211, 159, .15);
}
.code-box.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 93, 108, .15);
  animation: shake .4s ease both;
}

/* --- links --- */
.back-link {
  display: inline-block;
  color: var(--muted);
  font-size: .85rem;
  margin-top: .8rem;
  cursor: pointer;
  transition: color .15s;
}
.back-link:hover { color: var(--tg-blue); text-decoration: none; }
.resend-btn.tg-btn {
  width: auto;
  min-width: 140px;
  height: 36px;
  padding: 0 1rem;
  font-size: .82rem;
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  align-self: center;
}
.resend-btn.tg-btn:not(:disabled):hover {
  background: var(--bg-soft);
  color: var(--tg-blue);
  border-color: var(--tg-blue);
  transform: none;
}
.resend-btn.tg-btn:disabled {
  opacity: .5;
  cursor: default;
  transform: none;
}
.resend-btn.tg-btn:disabled:hover {
  background: var(--bg-soft);
  color: var(--muted);
  border-color: var(--border);
}
.resend-timer {
  display: inline-block;
  min-width: 1.2em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.resend-msg {
  font-size: .75rem;
  color: var(--muted);
  text-align: center;
  margin-top: -.2rem;
  min-height: 1em;
}
