:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8a93a3;
  --primary: #4f7cff;
  --primary-2: #6a92ff;
  --green: #2ecc71;
  --red: #e74c3c;
  --amber: #f39c12;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot-lg { width: 12px; height: 12px; margin-right: 8px; }
.dot.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.dot.amber { background: var(--amber); }

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger-outline { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger-outline:hover { background: rgba(231, 76, 60, .1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ====== Login ====== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 20%, rgba(79,124,255,.12), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(46,204,113,.06), transparent 40%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
}
.login-logo { text-align: center; margin-bottom: 16px; }
.logo-badge {
  width: 54px; height: 54px;
  margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-radius: 14px;
}
.logo-badge.small {
  width: 34px; height: 34px; font-size: 17px; border-radius: 9px; margin: 0;
}
.login-title { text-align: center; font-size: 24px; font-weight: 800; }
.login-subtitle { text-align: center; color: var(--muted); margin: 4px 0 24px; font-size: 13px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field.full { grid-column: 1 / -1; }
.field small { display: block; margin-top: 4px; color: var(--muted); }

.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--primary); }
textarea.input { resize: vertical; min-height: 70px; }

.password-wrapper { position: relative; }
.password-wrapper .input { padding-right: 40px; }
.toggle-eye {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  background: transparent; border: none; cursor: pointer;
  font-size: 15px; color: var(--muted);
}
.error-text { color: var(--red); font-size: 13px; margin: 8px 0; }

/* ====== Dashboard Layout ====== */
.dashboard { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  font-weight: 800; font-size: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-nav { flex: 1; padding: 14px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 3px;
  transition: all .15s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: rgba(79,124,255,.14); color: var(--primary-2); }
.nav-item .icon { font-size: 16px; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.conn-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.logout-btn { width: 100%; }

.main-content {
  flex: 1;
  padding: 28px;
  overflow-x: hidden;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 22px; }
.page-title { font-size: 22px; font-weight: 800; }
.page-desc { color: var(--muted); font-size: 13px; margin-top: 3px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Status banner */
.status-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 20px;
}
.status-inline { display: flex; align-items: center; font-weight: 600; }

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; flex-shrink: 0;
}
.stat-icon.shipped { background: rgba(79,124,255,.15); }
.stat-icon.success { background: rgba(46,204,113,.15); }
.stat-icon.danger { background: rgba(231,76,60,.15); }
.stat-icon.today { background: rgba(243,156,18,.15); }
.stat-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 24px; font-weight: 800; line-height: 1.1; }

.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.card h3:last-child { margin-bottom: 0; }

.bar-container { display: flex; flex-direction: column; gap: 10px; }
.chart-item .chart-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.chart-item .chart-label .muted { color: var(--muted); }
.chart-bar { height: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.chart-bar > div { height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s ease; }
.chart-bar > div.green { background: var(--green); }
.chart-bar > div.amber { background: var(--amber); }
.chart-bar > div.red { background: var(--red); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 10px 12px;
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--panel-2); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge.sent, .badge.success { background: rgba(46,204,113,.15); color: var(--green); }
.badge.failed { background: rgba(231,76,60,.15); color: var(--red); }
.badge.waiting { background: rgba(243,156,18,.15); color: var(--amber); }
.badge.default { background: rgba(79,124,255,.15); color: var(--primary-2); }

.msg-cell { max-width: 260px; }
.msg-cell .msg-text {
  display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; color: var(--muted);
}
.country-tag { white-space: nowrap; }

/* Filter bar */
.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.filter-bar .select { padding: 8px 10px; }

/* Pagination */
.pagination { margin-top: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Action buttons in table */
.action-cell { display: flex; gap: 6px; white-space: nowrap; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal {
  width: 100%; max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  animation: fadeIn .2s ease;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-close { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer { margin-top: 16px; }

/* Two-col layout */
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.two-col > .card { margin-bottom: 0; }
.two-col-inner { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-stack { margin-top: 4px; }

/* Result box */
.result-box {
  margin-top: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  max-height: 260px;
  overflow: auto;
}
.result-box pre { font-family: 'Consolas', monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.result-item { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); }
.result-item:last-child { border-bottom: none; }
.result-item .k { color: var(--muted); }
.result-item .v { font-weight: 600; text-align: right; margin-left: 12px; }
.result-success { color: var(--green); }
.result-fail { color: var(--red); }

/* Message detail modal */
.detail-modal { max-width: 720px; max-height: 88vh; display: flex; flex-direction: column; }
.detail-modal .modal-body { overflow: auto; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.detail-item { display: flex; flex-direction: column; gap: 3px; }
.detail-item.full { grid-column: 1 / -1; }
.detail-item .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.detail-item span:last-child { font-size: 13px; }
.prewrap { white-space: pre-wrap; word-break: break-word; }
.api-debug { margin-top: 4px; }
.resp-json {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: 'Consolas', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 320px;
  overflow: auto;
}
.detail-notice { font-size: 13px; padding: 8px 0; }

/* Failure reason in table */
.err-reason { color: var(--red); font-size: 12px; display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-msg { color: var(--green); font-size: 12px; white-space: nowrap; }

/* Toasts */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 240px;
  max-width: 360px;
  font-size: 13px;
  animation: slideIn .25s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

.right-align { text-align: right; }

/* Responsive */
@media (max-width: 760px) {
  .sidebar { width: 64px; }
  .sidebar-brand span { display: none; }
  .nav-item span:last-child { display: none; }
  .nav-item { justify-content: center; }
  .sidebar-footer .conn-status { display: none; }
  .main-content { padding: 16px; }
  .two-col-inner { grid-template-columns: 1fr; }
}