:root {
  --bg: #0b0f15;
  --bg-2: #0e141c;
  --surface: #161d28;
  --surface-2: #1c2430;
  --surface-3: #232c3a;
  --border: #283242;
  --border-light: #344256;
  --text: #e9eef5;
  --text-soft: #93a1b3;
  --text-dim: #647082;
  --green: #25d366;
  --green-dark: #1faa52;
  --green-glow: rgba(37, 211, 102, 0.25);
  --amber: #f5a623;
  --amber-soft: rgba(245, 166, 35, 0.14);
  --red: #f0506e;
  --red-soft: rgba(240, 80, 110, 0.14);
  --blue: #3aa0ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Heebo', system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 85% -10%, #122033 0%, var(--bg) 55%) fixed;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
h1, h2, h3, .btn, .tab, button { font-family: 'Rubik', system-ui, sans-serif; }

/* ── Top bar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 30px; background: rgba(14, 20, 28, 0.8);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 50px; height: 50px; display: grid; place-items: center; font-size: 26px;
  background: linear-gradient(145deg, var(--green), var(--green-dark));
  border-radius: 14px; box-shadow: 0 6px 20px var(--green-glow);
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .3px; }
.brand-sub { margin: 0; font-size: 12.5px; color: var(--text-soft); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ── View ── */
.view { max-width: 1140px; margin: 0 auto; padding: 30px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h2 { margin: 0 0 3px; font-size: 24px; }
.page-head p { margin: 0; color: var(--text-soft); font-size: 14px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: var(--radius-sm); font-size: 14.5px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent; transition: .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(145deg, var(--green), var(--green-dark)); color: #04140a; font-weight: 600; box-shadow: 0 6px 18px var(--green-glow); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border-light); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: rgba(240,80,110,.3); }
.btn-danger:hover:not(:disabled) { background: rgba(240,80,110,.22); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Instances grid ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }

.inst-card {
  background: linear-gradient(160deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; cursor: pointer; transition: .18s; position: relative; overflow: hidden;
}
.inst-card:hover { border-color: var(--border-light); transform: translateY(-3px); box-shadow: var(--shadow); }
.inst-card .ic-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.inst-card .ic-icon {
  width: 46px; height: 46px; display: grid; place-items: center; font-size: 22px;
  background: var(--surface-3); border-radius: 12px; flex-shrink: 0;
}
.inst-card h3 { margin: 16px 0 4px; font-size: 17px; }
.inst-card .ic-phone { color: var(--text-soft); font-size: 14px; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.inst-card .ic-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--text-dim); }

.create-card {
  border: 2px dashed var(--border-light); border-radius: var(--radius);
  display: grid; place-items: center; min-height: 200px; cursor: pointer;
  color: var(--text-soft); transition: .18s; text-align: center; gap: 6px;
}
.create-card:hover { border-color: var(--green); color: var(--green); background: rgba(37,211,102,.04); }
.create-card .cc-plus {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  font-size: 30px; background: var(--surface-2); margin: 0 auto 8px; transition: .18s;
}
.create-card:hover .cc-plus { background: var(--green); color: #04140a; }

/* ── Status pill ── */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.pill-connected { background: var(--green-glow); color: var(--green); }
.pill-qr, .pill-connecting { background: var(--amber-soft); color: var(--amber); }
.pill-disconnected, .pill-loggedout { background: var(--red-soft); color: var(--red); }
@keyframes pulse { 50% { opacity: .45; } }
.pill-qr::before, .pill-connecting::before { animation: pulse 1.2s infinite; }

/* ── Empty ── */
.empty { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.empty .em-icon { font-size: 46px; opacity: .5; }

/* ── Forms / inputs ── */
label { display: block; font-size: 13.5px; font-weight: 500; margin-bottom: 7px; color: var(--text); }
.field { margin-bottom: 16px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14.5px; color: var(--text); background: var(--bg-2); transition: .15s; resize: vertical;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-glow); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(4, 8, 13, 0.7);
  backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
  width: 100%; max-width: 460px; box-shadow: var(--shadow); animation: rise .2s ease; max-height: 92vh; overflow-y: auto;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-x { background: none; border: none; color: var(--text-soft); font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 22px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ── QR display ── */
.qr-wrap { text-align: center; }
.qr-box { background: #fff; border-radius: 16px; padding: 16px; display: inline-block; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.qr-box img { display: block; width: 280px; height: 280px; }
.qr-hint { margin: 18px 0 6px; font-size: 15px; font-weight: 500; }
.qr-steps { color: var(--text-soft); font-size: 13px; line-height: 1.8; text-align: right; max-width: 340px; margin: 12px auto 0; }
.qr-spinner-line { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--amber); margin-top: 14px; font-size: 14px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Connected detail ── */
.detail-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .dr-key { color: var(--text-soft); }
.detail-row .dr-val { font-weight: 500; direction: ltr; }
.copy-field { display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; direction: ltr; }
.copy-field code { color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.copy-field button { background: none; border: none; color: var(--green); cursor: pointer; font-size: 14px; }

.section-title { font-size: 13px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; margin: 22px 0 10px; }

.msg-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.msg { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.msg .msg-from { color: var(--green); font-weight: 600; font-size: 12px; direction: ltr; }
.msg .msg-text { color: var(--text-soft); margin-top: 2px; }

/* ── Login ── */
.login-wrap { min-height: 70vh; display: grid; place-items: center; }
.login-card { background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius); padding: 32px; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.login-card .login-logo { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; font-size: 32px; margin: 0 auto 10px; background: linear-gradient(145deg, var(--green), var(--green-dark)); box-shadow: 0 8px 24px var(--green-glow); }
.login-card h2 { margin: 6px 0 2px; }
.login-card p { color: var(--text-soft); font-size: 13px; margin: 0 0 20px; }
.login-card .field { text-align: right; }

/* ── account ── */
.account { position: relative; }
.account-btn { background: var(--surface-2); border: 1px solid var(--border-light); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 500; cursor: pointer; color: var(--text); font-family: 'Rubik', sans-serif; }
.account-btn:hover { background: var(--surface-3); }
.account-menu { position: absolute; left: 0; top: calc(100% + 6px); background: var(--surface-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm); box-shadow: var(--shadow); overflow: hidden; z-index: 30; min-width: 170px; }
.account-menu button { display: block; width: 100%; text-align: right; padding: 11px 16px; border: none; background: none; cursor: pointer; font-size: 14px; color: var(--text); font-family: 'Heebo', sans-serif; }
.account-menu button:hover { background: var(--surface-3); }

/* ── status line / error ── */
.statusline { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500; margin-top: 12px; }
.statusline.error { background: var(--red-soft); color: var(--red); }
.statusline.ok { background: var(--green-glow); color: var(--green); }
.hint { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; }

/* ── Toast ── */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--surface-3); color: var(--text); padding: 12px 22px; border: 1px solid var(--border-light); border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); z-index: 200; animation: rise .2s ease; }

/* ── automations: tabs + lists ── */
.auto-tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.auto-tab { background: none; border: none; color: var(--text-soft); padding: 10px 18px; font-size: 14.5px; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; font-family: 'Rubik', sans-serif; }
.auto-tab:hover { color: var(--text); }
.auto-tab.is-active { color: var(--green); border-bottom-color: var(--green); }
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.list-item .li-main { min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: 15px; margin: 0 0 2px; }
.list-item .li-meta { font-size: 12.5px; color: var(--text-soft); margin: 0; }
.li-actions { display: flex; gap: 8px; flex-shrink: 0; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .list-item { flex-direction: column; align-items: stretch; }
  .view { padding: 18px 16px; }
  .grid { grid-template-columns: 1fr; }
  .qr-box img { width: 230px; height: 230px; }
}
