*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --card: #1a1a1a;
  --card2: #222;
  --border: #2a2a2a;
  --accent: #00d4aa;
  --accent-dim: #00a882;
  --danger: #ff4757;
  --warning: #ffa502;
  --text: #e0e0e0;
  --text-dim: #888;
  --sidebar-w: 240px;
}

body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; min-height: 100vh; }

a { color: var(--accent); text-decoration: none; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: var(--text-dim);
  transition: all .15s;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { color: var(--text); background: rgba(0,212,170,.06); }
.sidebar-nav a.active { color: var(--text); background: rgba(0,212,170,.1); border-left-color: var(--accent); }

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-user .username { font-weight: 600; color: var(--text); font-size: 14px; }
.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0,212,170,.15);
  color: var(--accent);
  margin-top: 4px;
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-badge.role-admin { background: rgba(255,71,87,.15); color: var(--danger); }

.main { margin-left: var(--sidebar-w); flex: 1; padding: 28px; min-width: 0; }

/* ── Page header ── */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p { color: var(--text-dim); margin-top: 4px; font-size: 13px; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.stat-card .label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-card .value { font-size: 30px; font-weight: 700; color: var(--accent); margin-top: 6px; }

/* ── Card ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.card-header h2 { font-size: 15px; font-weight: 600; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; background: rgba(255,255,255,.02); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
td.wrap { white-space: normal; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn-secondary { background: rgba(255,255,255,.07); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,.12); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #e0404f; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover:not(:disabled) { background: #e09500; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 5px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 4px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--text-dim); font-weight: 500; letter-spacing: .02em; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text-dim); }
textarea.form-control { resize: vertical; min-height: 90px; line-height: 1.5; }
select.form-control { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
select[multiple].form-control { background-image: none; padding-right: 12px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text); }
.checkbox-label input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }

/* ── Range slider ── */
.slider-wrap { display: flex; align-items: center; gap: 12px; }
input[type=range] { flex: 1; accent-color: var(--accent); cursor: pointer; }
.slider-value {
  min-width: 70px;
  text-align: center;
  background: #111;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Status badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-connected, .badge-completed { background: rgba(0,212,170,.15); color: #00d4aa; }
.badge-disconnected, .badge-failed { background: rgba(255,71,87,.15); color: #ff4757; }
.badge-connecting, .badge-paused { background: rgba(255,165,2,.15); color: #ffa502; }
.badge-running { background: rgba(30,144,255,.15); color: #1e90ff; animation: pulse 1.5s ease-in-out infinite; }
.badge-stopped, .badge-interrupted { background: rgba(136,136,136,.15); color: #888; }

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

/* ── Progress bar ── */
.progress-wrap { margin: 12px 0; }
.progress-track { background: #111; border-radius: 999px; height: 8px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-dim)); border-radius: 999px; transition: width .4s ease; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-top: 6px; }

/* ── Stats row ── */
.stats-row { display: flex; gap: 20px; flex-wrap: wrap; margin: 12px 0; }
.stat-pill { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.stat-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-sent { background: var(--accent); }
.dot-failed { background: var(--danger); }
.dot-remaining { background: var(--text-dim); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}
.modal-lg { max-width: 820px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

/* ── Toast ── */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  max-width: 340px;
  animation: slideIn .2s ease forwards;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  pointer-events: all;
}
.toast-success { background: #00a882; }
.toast-error { background: var(--danger); }
.toast-info { background: #2196f3; }
.toast-warning { background: var(--warning); color: #000; }
@keyframes slideIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(110%); opacity: 0; } }

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  color: var(--text-dim);
  font-size: 13px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(0,212,170,.04);
  color: var(--accent);
}
.drop-zone input[type=file] { display: none; }
.drop-zone .dz-icon { font-size: 28px; margin-bottom: 8px; display: block; }
.drop-zone .dz-hint { font-size: 11px; margin-top: 4px; }

/* ── Login ── */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-icon { font-size: 40px; }
.login-logo h1 { font-size: 22px; color: var(--accent); margin-top: 8px; }
.login-logo p { color: var(--text-dim); margin-top: 4px; font-size: 13px; }
.login-error {
  background: rgba(255,71,87,.1);
  border: 1px solid rgba(255,71,87,.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 7px;
  margin-bottom: 16px;
  font-size: 13px;
  display: none;
}

/* ── Live log ── */
.live-log { max-height: 260px; overflow-y: auto; }
.live-log::-webkit-scrollbar { width: 4px; }
.live-log::-webkit-scrollbar-track { background: transparent; }
.live-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.live-log table th, .live-log table td { font-size: 12px; padding: 6px 10px; }
.status-sent { color: var(--accent); }
.status-failed { color: var(--danger); }

/* ── QR ── */
.qr-container { text-align: center; }
.qr-img { width: 220px; height: 220px; border-radius: 8px; background: #fff; padding: 8px; }
.qr-countdown { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

/* ── Quick links ── */
.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.quick-link {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .2s, background .2s;
  display: block;
}
.quick-link:hover { border-color: var(--accent); background: rgba(0,212,170,.05); }
.quick-link .ql-icon { font-size: 26px; margin-bottom: 10px; display: block; }
.quick-link .ql-label { font-weight: 600; font-size: 14px; }
.quick-link .ql-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

/* ── Contacts badge ── */
.contacts-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,212,170,.12);
  color: var(--accent);
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 10px;
}

/* ── Char counter ── */
.char-counter { text-align: right; font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Media preview ── */
.media-preview { margin-top: 10px; }
.media-preview img { max-width: 100%; max-height: 180px; border-radius: 8px; border: 1px solid var(--border); }

/* ── Section divider ── */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Actions bar ── */
.actions-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ── Responsive ── */
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 16px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── Warning banner ── */
.warn-banner {
  background: rgba(255,165,2,.1);
  border: 1px solid rgba(255,165,2,.3);
  color: var(--warning);
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Instance assigned users list ── */
.user-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.user-pill { background: rgba(0,212,170,.1); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-size: 11px; }
