:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2433; --muted: #6b7280; --line: #e5e7eb;
  --primary: #b01e2f; --primary-d: #8e1726; --ok: #15803d; --warn: #b45309; --err: #b91c1c;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  overflow-x: hidden;
  max-width: 100vw;
  box-sizing: border-box;
}
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.topbar .me, .me {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #f1f5f9;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 13px;
}
.user-pill {
  font-weight: 700;
  color: #ffffff;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #334155;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 12.5px;
  border: 1px solid #475569;
}
.btn-logout {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5 !important;
  border: 1px solid rgba(239, 68, 68, 0.35);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: all .15s ease;
}
.btn-logout:hover {
  background: #dc2626;
  color: #ffffff !important;
  border-color: #dc2626;
  text-decoration: none;
}
.dot { display: inline-block; width: 8px; height: 8px; background: #22c55e; border-radius: 50%; margin-left: 4px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.banner { padding: 8px 20px; }
.banner.warn { background: #fef3c7; color: #78350f; }
.container { max-width: 1380px; margin: 0 auto; padding: 16px 20px 60px; box-sizing: border-box; }
.narrow { max-width: 440px; margin: 60px auto; padding: 0 20px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.stat { font-size: 30px; font-weight: 700; }
.stat-label { color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: #dcfce7; color: #14532d; }
.flash.err { background: #fee2e2; color: #7f1d1d; }
.flash.warn { background: #fef3c7; color: #78350f; }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 12.5px; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; color: #475569; background: #f8fafc; border-bottom: 2px solid var(--line); white-space: nowrap; font-weight: 700; }
tr.unseen td { background: #fff7ed; }
tr.unseen td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.04); margin-bottom: 18px; -webkit-overflow-scrolling: touch; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.err { background: #fee2e2; color: var(--err); }
.badge.muted { background: #f3f4f6; color: var(--muted); }
.badge.new { background: var(--primary); color: #fff; }

form.inline { display: inline-block; margin: 0; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=email], input[type=search], input[type=time], input[type=file], select {
  width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 7px; font: inherit; background: #fff;
}
input:focus, select:focus { outline: 2px solid #fecaca; border-color: var(--primary); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { width: 280px; }
.filters select { width: auto; }
.btn { display: inline-block; padding: 6px 12px; border-radius: 6px; border: 1px solid #d1d5db; background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; font-size: 13px; line-height: 1.4; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.btn.danger:hover { background: #fecaca; }
.btn.edit { background: #e0e7ff; border-color: #c7d2fe; color: #3730a3; }
.btn.edit:hover { background: #c7d2fe; }
.btn.success { background: #15803d; border-color: #15803d; color: #fff; }
.btn.success:hover { background: #166534; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.action-btns { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.nowrap { white-space: nowrap; }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.progress { height: 10px; background: #e5e7eb; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .4s ease; }
.progress > div.progress-bar-running {
  background: linear-gradient(45deg, #2563eb 25%, #3b82f6 25%, #3b82f6 50%, #2563eb 50%, #2563eb 75%, #3b82f6 75%, #3b82f6 100%);
  background-size: 28px 28px;
  animation: progressStripe 1s linear infinite;
}
.progress > div.progress-bar-done {
  background: linear-gradient(90deg, #16a34a, #22c55e);
}
@keyframes progressStripe {
  0% { background-position: 0 0; }
  100% { background-position: 28px 0; }
}
.log { background: #0f172a; color: #e2e8f0; font: 12px/1.5 ui-monospace, Menlo, monospace; padding: 12px; border-radius: 8px; height: 320px; overflow-y: auto; white-space: pre-wrap; }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: #fff; padding: 22px; border-radius: 12px; width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-box.large { width: 780px; max-width: 95vw; max-height: 88vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.detail-grid { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; margin: 12px 0; font-size: 13px; }
.detail-label { color: var(--muted); font-weight: 600; }
.detail-val { color: var(--text); word-break: break-word; }
.detail-section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.detail-raw-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap; max-height: 200px; overflow-y: auto; }

.btn.whatsapp { background: #25D366; border-color: #25D366; color: #fff; font-weight: 600; }
.btn.whatsapp:hover { background: #1ebe57; text-decoration: none; }
.qr-box { text-align: center; padding: 24px; background: #fff; border: 2px dashed #cbd5e1; border-radius: 12px; display: inline-block; }
.qr-box img { max-width: 260px; height: auto; border-radius: 8px; margin: 12px 0; border: 1px solid var(--line); }
.wa-preview-msg { background: #eef8f2; border: 1px solid #c7ebd2; border-radius: 8px; padding: 12px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 13px; white-space: pre-wrap; max-height: 260px; overflow-y: auto; }

.modal-box.captcha-box img { display: block; max-width: 100%; margin: 10px 0; border: 1px solid var(--line); border-radius: 6px; image-rendering: pixelated; min-height: 50px; }
.modal-box.captcha-box input, .modal-box.sms-box input { font-size: 20px; letter-spacing: 3px; text-align: center; margin-bottom: 10px; }
.pager { margin-top: 12px; display: flex; gap: 6px; }
.small { font-size: 12px; }
