/* ============================================================
   Wafid app — design system
   Layout: fixed sidebar (desktop) / drawer (mobile) + content
   ============================================================ */
:root {
  --navy: #0b1220;
  --navy-2: #131c2e;
  --navy-3: #1b2740;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e5e9f0;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #b45309;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .04);
  --sidebar-w: 252px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }

/* ---------------- app shell ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #cbd5e1;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.brand-name { color: #fff; font-weight: 800; font-size: 17px; letter-spacing: .02em; }
.brand-tag {
  font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  border: 1px solid #334155; color: #94a3b8; border-radius: 999px; padding: 2px 7px;
}

.side-section {
  padding: 16px 18px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: #64748b;
}
.side-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 18px; margin: 1px 0;
  color: #cbd5e1; text-decoration: none; font-size: 13.5px; font-weight: 500;
  border-left: 3px solid transparent; cursor: pointer;
}
.side-link svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.side-link:hover { background: var(--navy-2); color: #fff; }
.side-link.active { background: var(--navy-2); color: #fff; border-left-color: var(--primary); }
.side-link.active svg { opacity: 1; }

.side-foot { margin-top: auto; padding: 16px 18px 20px; border-top: 1px solid #1e293b; }
.side-user { color: #e2e8f0; font-size: 12.5px; word-break: break-all; margin-bottom: 10px; }
.side-role { color: #64748b; font-size: 11px; }

/* ---------------- main ---------------- */
.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  display: none; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.menu-btn {
  background: #fff; color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px; cursor: pointer; display: inline-flex;
}
.topbar-title { font-weight: 700; font-size: 15px; }

.container { max-width: 1500px; width: 100%; margin: 0 auto; padding: 28px 32px 64px; }

/* ---------------- page header ---------------- */
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.title { font-size: 27px; font-weight: 800; margin: 5px 0 6px; letter-spacing: -.01em; }
.subtitle { color: var(--muted); font-size: 14px; margin: 0; max-width: 720px; }
.page-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------- cards ---------------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; font-weight: 700; margin: 0 0 14px; color: var(--text); }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }

/* ---------------- tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  background: none; color: var(--muted); border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 14px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.tab:hover { background: none; color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------------- template chips ---------------- */
.tpl-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tpl-item {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 7px 14px; font-size: 13px; cursor: pointer; color: var(--text-2);
}
.tpl-item:hover { border-color: var(--primary); color: var(--primary); }
.tpl-item.active { background: #eff6ff; border-color: var(--primary); color: var(--primary); font-weight: 600; }

/* ---------------- toolbar ---------------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

/* ---------------- filters ---------------- */
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filters label { flex: 1 1 150px; min-width: 130px; }
.filters .f-search { flex: 1.6 1 220px; }
.filters button { height: 41px; flex: 0 0 auto; padding-left: 26px; padding-right: 26px; }

/* ---------------- pager ---------------- */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.pager .spacer { flex: 1; }
.pager-rows { flex-direction: row; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.pager-rows select { width: auto; padding: 7px 10px; font-size: 13px; }
.pager button:disabled { opacity: .5; cursor: default; }

/* ---------------- forms ---------------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
label > .lbl { display: block; }
.opt { color: inherit; font-weight: 600; font-size: 12px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #d3dae5; border-radius: var(--radius-sm);
  font-size: 14px; background: #fff; color: var(--text); font-family: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
input.bad, select.bad { border-color: var(--danger); }
input[readonly], input:disabled { background: #f8fafc; color: var(--muted); }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 16px; }
.grid:last-child { margin-bottom: 0; }

/* ---------------- buttons ---------------- */
button, .btn {
  background: var(--primary); color: #fff; border: 0; border-radius: var(--radius-sm);
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--primary-d); }
button:disabled { background: #cbd5e1; cursor: default; }
.ghost {
  background: #fff; color: var(--text-2); border: 1px solid var(--border); font-weight: 600;
}
.ghost:hover { background: #f3f6fb; color: var(--text); }
.rowbtn { background: #fee2e2; color: #b91c1c; padding: 7px 11px; }
.rowbtn:hover { background: #fecaca; }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.link-btn { background: none; color: var(--primary); padding: 0; font-weight: 600; }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 11px 14px; color: var(--muted); font-size: 10.5px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: #fbfcfe;
}
td { padding: 14px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text-2); }
tr:last-child td { border-bottom: 0; }
td.url { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.rowactions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.dots { background: none; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-weight: 800; cursor: pointer; line-height: 1; }
.dots:hover { background: #f3f6fb; color: var(--text); }
.rowmenu { position: absolute; z-index: 60; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 150px; }
.rowmenu button { display: block; width: 100%; text-align: left; background: none; color: var(--text); border: 0; padding: 9px 12px; border-radius: 7px; font-weight: 600; font-size: 13px; }
.rowmenu button:hover { background: #f3f6fb; }
.rowmenu button.danger { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 28px 0; }

/* ---------------- badges / pills ---------------- */
.badge {
  display: inline-block; padding: 4px 11px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: #dbeafe; color: #1d4ed8;
}
.badge.delay { background: #ffedd5; color: #c2410c; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.pill.pending { background: #eef2f7; color: #475569; }
.pill.url_ready { background: #dbeafe; color: #1d4ed8; }
.pill.otp_ready { background: #ede9fe; color: #6d28d9; }
.pill.processing { background: #ffedd5; color: #c2410c; }
.pill.paid { background: #d1fae5; color: #047857; }
.pill.failed { background: #fee2e2; color: #b91c1c; }
.pill.cancelled { background: #e5e7eb; color: #374151; }
.pill.passport_exist { background: #fce7f3; color: #9d174d; }
.pill.url_exist { background: #fef3c7; color: #92400e; }
.pill.error { background: #fee2e2; color: #b91c1c; }
.tip { position: fixed; z-index: 130; background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; padding: 7px 11px; border-radius: 8px; font-size: 12px; font-weight: 600; max-width: 380px; box-shadow: 0 8px 20px rgba(0,0,0,.16); pointer-events: none; }
.otp-clock { font-family: ui-monospace, Consolas, monospace; font-size: 11px; font-weight: 700; color: #6d28d9; background: #ede9fe; border-radius: 6px; padding: 2px 6px; white-space: nowrap; }
.pill.rate_limited { background: #fef9c3; color: #854d0e; }
a.pill { text-decoration: none; cursor: pointer; }
a.pill.paid:hover { background: #a7f3d0; }
.pill.done { background: #d1fae5; color: #047857; }
.pill.running { background: #dbeafe; color: #1d4ed8; }
.pill.queued { background: #eef2f7; color: #475569; }

/* ---------------- messages ---------------- */
.msg { color: var(--ok); font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.errline { color: var(--danger); font-size: 11px; margin-top: 4px; max-width: 240px; }
.field-err { color: var(--danger); font-size: 11.5px; margin-top: 1px; }
.errors {
  background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 14px; font-size: 14px;
}
.errors ul { margin: 0; padding-left: 18px; }
.ok-msg {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: var(--ok);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 14px; font-size: 14px;
}
.notice {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 14px; font-size: 13.5px;
}

/* ---------------- workspace live run ---------------- */
body.ws-focus .page-head,
body.ws-focus #wsTabs,
body.ws-focus #groupsCard { display: none !important; }
body.ws-focus .container { max-width: 1280px; padding-top: 20px; }

.live-hero {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.live-hero h2 { font-size: 22px; font-weight: 800; margin: 4px 0 6px; letter-spacing: -.02em; }
.pill.stopped { background: #fee2e2; color: #b91c1c; }
.pill.complete { background: #d1fae5; color: #047857; }
.pill.paying { background: #ffedd5; color: #c2410c; }

.live-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px;
}
.live-stat {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.live-stat b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.live-stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.live-stat.ok b { color: var(--ok); }
.live-stat.danger b { color: var(--danger); }
.live-stat.warn b { color: var(--warn); }

.live-now {
  background: linear-gradient(135deg, #0b1220, #1b2740);
  color: #e2e8f0; border-radius: 16px; padding: 18px 20px; margin-bottom: 14px;
}
.live-now .k {
  font-size: 11px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: #94a3b8;
}
.live-now .v { font-size: 18px; font-weight: 800; color: #fff; margin: 4px 0 0; }
.live-now .row { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 14px; }
.live-now .row div { min-width: 140px; }
.live-now .target { color: #fdba74; }

.live-event {
  border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; font-size: 14.5px; font-weight: 600;
}
.live-event.hit { background: #ecfdf5; border: 1px solid #6ee7b7; color: #047857; }
.live-event.miss { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.live-event.start { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }
.live-event.stop { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; }
.live-event.flash { animation: event-pop .45s ease; }
@keyframes event-pop {
  from { transform: scale(.985); box-shadow: 0 0 0 6px rgba(37, 99, 235, .08); }
  to { transform: none; box-shadow: none; }
}

.live-track-label {
  font-size: 11px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin: 4px 0 8px;
}
.live-track {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 14px;
  scroll-snap-type: x proximity;
}
.track-chip {
  flex: none; scroll-snap-align: center;
  border: 1px solid var(--border); background: #fff; color: var(--text-2);
  border-radius: 999px; padding: 7px 12px; font-size: 12px; font-weight: 600;
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.track-chip.is-done { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.track-chip.is-window { background: #0b1220; border-color: #0b1220; color: #fff; }
.track-chip.is-expected {
  background: #fff7ed; border-color: #fdba74; color: #c2410c;
  box-shadow: 0 0 0 3px rgba(234, 88, 12, .16);
  animation: pulse-exp 1.4s ease-in-out infinite;
}
@keyframes pulse-exp { 50% { box-shadow: 0 0 0 6px rgba(234, 88, 12, .08); } }
tr.live-current td { background: #fff7ed; }
tr.live-hit td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
tr.live-miss td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

@media (max-width: 720px) {
  .live-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------- toggle switch ---------------- */
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); flex-direction: row; }
.toggle { position: relative; width: 44px; height: 24px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; cursor: pointer; transition: .18s; }
.toggle .slider::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .18s;
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ---------------- actions row ---------------- */
.actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

/* ---------------- login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card button { width: 100%; }

/* ---------------- backdrop (mobile) ---------------- */
.backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 39;
}
.backdrop.show { display: block; }

/* ---------------- responsive ---------------- */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .container { padding: 20px 16px 56px; }
  .title { font-size: 22px; }
  .page-actions { margin-left: 0; width: 100%; }
  .page-actions > button, .page-actions > .btn { flex: 1; }
  th, td { padding: 11px 12px; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}
