/* ============================================================
   WhatsApp Bulk Messenger - UI
   ============================================================ */

:root {
  --brand: #128c7e;
  --brand-2: #25d366;
  --brand-dark: #075e54;

  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e3e8ee;
  --text: #16202a;
  --muted: #6b7a8c;

  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --info: #2563eb;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .06);
  --sidebar-w: 244px;
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------- layout ---- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--brand-dark), #0a4f47);
  color: #e9f5f2;
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0;
  z-index: 40;
  transition: transform .25s ease;
}

.sidebar .brand {
  padding: 18px 18px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.09);
}
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--brand-2); color: #06382f;
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
}
.sidebar .brand b { font-size: 15px; letter-spacing: .2px; display: block; }
.sidebar .brand small { color: #a9d5cc; font-size: 11px; }

.nav { padding: 10px 10px 20px; overflow-y: auto; flex: 1; }
.nav .group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .9px;
  color: #8fc4b9; margin: 14px 10px 6px;
}
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin-bottom: 3px;
  border-radius: 9px; color: #d6ece6; font-size: 14px; text-decoration: none;
  transition: background .15s, color .15s;
}
.nav a .ico { width: 20px; text-align: center; font-size: 15px; opacity: .95; }
.nav a:hover { background: rgba(255,255,255,.10); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand-2); color: #06382f; font-weight: 600; }
.nav a .badge-dot {
  margin-left: auto; background: rgba(255,255,255,.18); color: #fff;
  border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 600;
}
.nav a.active .badge-dot { background: rgba(0,0,0,.15); color: #06382f; }

.sidebar-foot {
  padding: 12px; border-top: 1px solid rgba(255,255,255,.09);
  font-size: 12px; color: #a9d5cc;
}

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; max-width: 100%; display: flex; flex-direction: column; }
.page > *, .grid > * { min-width: 0; }

.topbar {
  height: 58px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.topbar .hamburger { display: none; font-size: 20px; background: none; border: 0; cursor: pointer; }

.page { padding: 18px; flex: 1; }
.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .title h2 { margin: 0 0 3px; font-size: 19px; }
.page-head .title p { margin: 0; color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------ card ---- */

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px;
}
.card > .card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card > .card-head h3 { margin: 0; font-size: 15px; font-weight: 620; }
.card > .card-head .spacer { flex: 1 1 auto; min-width: 0; }
.card > .card-head input, .card > .card-head select { min-width: 0; flex: 1 1 140px; }
.card > .card-body { padding: 16px; }
.card > .card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.c6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }

/* ------------------------------------------------------------ stat ---- */

.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 25px; font-weight: 700; margin-top: 5px; line-height: 1.1; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat .ico {
  position: absolute; right: 12px; top: 12px; font-size: 20px; opacity: .22;
}
.stat.ok .value { color: var(--ok); }
.stat.danger .value { color: var(--danger); }
.stat.warn .value { color: var(--warn); }
.stat.info .value { color: var(--info); }

/* ------------------------------------------------------------- form --- */

label.fl { display: block; font-size: 12.5px; font-weight: 600; color: #33475b; margin-bottom: 5px; }
label.fl .req { color: var(--danger); }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; background: #fff; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18,140,126,.13);
}
textarea { resize: vertical; min-height: 92px; line-height: 1.5; }
input[type=file] { font-size: 13px; }
.field { margin-bottom: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 150px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

.seg { display: inline-flex; background: #eef2f5; border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button {
  border: 0; background: none; padding: 7px 13px; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 13px; color: #46586b; font-weight: 550;
}
.seg button.on { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.09); }

/* ------------------------------------------------------------- btn ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: #fff; color: var(--text); font-family: inherit; font-size: 13.5px; font-weight: 570;
  cursor: pointer; transition: .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f2f5f8; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0f7c70; }
.btn.green { background: var(--brand-2); border-color: var(--brand-2); color: #06382f; }
.btn.green:hover { background: #1fbe5b; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef2f5; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }

/* ----------------------------------------------------------- table ---- */

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl th {
  background: var(--panel-2); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); font-weight: 650; white-space: nowrap;
}
table.tbl tbody tr:hover { background: #f8fafb; }
table.tbl td.actions { white-space: nowrap; text-align: right; }
table.tbl input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.tbl .num { font-variant-numeric: tabular-nums; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 34px; opacity: .35; margin-bottom: 8px; }

/* ------------------------------------------------------------ pill ---- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  background: #eef2f5; color: #45566a; white-space: nowrap;
}
.pill.ok { background: #dcfce7; color: #14532d; }
.pill.warn { background: #fef3c7; color: #78350f; }
.pill.danger { background: #fee2e2; color: #7f1d1d; }
.pill.info { background: #dbeafe; color: #1e3a8a; }
.pill.muted { background: #eef2f5; color: #64748b; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ----------------------------------------------------------- modal ---- */

.modal-back {
  position: fixed; inset: 0; background: rgba(15, 27, 38, .55);
  display: none; align-items: flex-start; justify-content: center; z-index: 100;
  padding: 28px 14px; overflow-y: auto; backdrop-filter: blur(2px);
}
.modal-back.open { display: flex; }
.modal {
  background: var(--panel); border-radius: 14px; width: 100%; max-width: 620px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; animation: pop .16s ease;
}
.modal.wide { max-width: 900px; }
.modal.slim { max-width: 440px; }
@keyframes pop { from { transform: translateY(-8px); opacity: .5; } }
.modal .m-head {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal .m-head h3 { margin: 0; font-size: 16px; }
.modal .m-head .x { margin-left: auto; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal .m-body { padding: 18px; max-height: 70vh; overflow-y: auto; }
.modal .m-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 9px; justify-content: flex-end; background: var(--panel-2);
}

/* ----------------------------------------------------------- toast ---- */

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #16202a; color: #fff; padding: 11px 15px; border-radius: 10px;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.28); max-width: 360px;
  animation: slidein .2s ease; display: flex; gap: 9px; align-items: flex-start;
}
.toast.ok { background: #14532d; }
.toast.err { background: #7f1d1d; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

/* --------------------------------------------------------- devices ---- */

.device-card {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
  padding: 15px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 11px;
}
.device-card .dc-top { display: flex; align-items: flex-start; gap: 11px; }
.device-card .avatar {
  width: 42px; height: 42px; border-radius: 11px; background: #e8f5f2; color: var(--brand);
  display: grid; place-items: center; font-size: 19px; flex-shrink: 0;
}
.device-card .dc-name { font-weight: 650; font-size: 14.5px; }
.device-card .dc-phone { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.qr-box {
  background: #fff; border: 1px dashed var(--border); border-radius: 10px;
  padding: 12px; text-align: center;
}
.qr-box img { width: 100%; max-width: 240px; border-radius: 6px; }
.pair-code {
  font-size: 26px; letter-spacing: 5px; font-weight: 700; color: var(--brand-dark);
  background: #e8f5f2; border-radius: 10px; padding: 13px; text-align: center;
  font-family: 'Consolas', monospace;
}

/* ------------------------------------------------------------ misc ---- */

.bulkbar {
  display: none; align-items: center; gap: 9px; padding: 9px 14px;
  background: #e8f5f2; border: 1px solid #bfe3db; border-radius: 10px; margin-bottom: 12px;
  flex-wrap: wrap;
}
.bulkbar.on { display: flex; }
.bulkbar b { color: var(--brand-dark); }

.code {
  background: #0f172a; color: #e2e8f0; padding: 13px 15px; border-radius: 10px;
  font-family: 'Consolas', 'Courier New', monospace; font-size: 12.5px;
  overflow-x: auto; white-space: pre; line-height: 1.55; margin: 0;
}
.inline-code {
  background: #eef2f5; padding: 1px 6px; border-radius: 5px;
  font-family: 'Consolas', monospace; font-size: 12.5px; color: #b91c1c;
}

.divider { height: 1px; background: var(--border); margin: 15px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.mt8 { margin-top: 8px; } .mt14 { margin-top: 14px; }
.flexline { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.bar-chart .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.bar-chart .b .fill { width: 100%; max-width: 42px; background: var(--brand-2); border-radius: 5px 5px 0 0; min-height: 3px; transition: height .3s; }
.bar-chart .b .fill.f2 { background: #fca5a5; }
.bar-chart .b .lbl { font-size: 11px; color: var(--muted); }
.bar-chart .b .val { font-size: 11.5px; font-weight: 650; }
.bar-stack { display: flex; flex-direction: column; justify-content: flex-end; width: 100%; max-width: 42px; height: 100%; gap: 2px; }

.loading { display: grid; place-items: center; padding: 50px; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; margin-bottom: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 15px; flex-wrap: wrap; }
.tabs button {
  border: 0; background: none; padding: 10px 15px; cursor: pointer; font-family: inherit;
  font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 550;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 650; }

.paging { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 11px 14px; }

/* ----------------------------------------------------------- login ---- */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #075e54, #128c7e 55%, #25d366);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 32px 30px; width: 100%; max-width: 390px;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
.login-card .lg-logo {
  width: 56px; height: 56px; border-radius: 15px; background: var(--brand-2); color: #06382f;
  display: grid; place-items: center; font-size: 27px; margin: 0 auto 14px;
}
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-err {
  background: #fee2e2; color: #7f1d1d; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 13px; display: none;
}

/* ------------------------------------------------------ responsive ---- */

@media (max-width: 1100px) {
  .grid.c6 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.side { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .topbar .hamburger { display: block; }
  .grid.c3, .grid.c2, .grid.c4, .grid.c6 { grid-template-columns: 1fr; }
  .page { padding: 13px; }
  .truncate { max-width: 170px; }
}

/* -------------------------------------------------------- dark mode --- */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720; --panel: #16202b; --panel-2: #1b2733; --border: #27374a;
    --text: #e6edf3; --muted: #93a4b8;
  }
  input, select, textarea { background: #0f1720 !important; color: var(--text) !important; }
  .seg { background: #1b2733; }
  .seg button { color: #b6c4d4; }
  .seg button.on { background: #0f1720; }
  .btn { background: #1b2733; color: var(--text); }
  .btn:hover { background: #22303f; }
  .btn.ghost:hover { background: #22303f; }
  table.tbl tbody tr:hover { background: #1b2733; }
  .inline-code { background: #1b2733; color: #fca5a5; }
  .bulkbar { background: #10362f; border-color: #1d5a4d; }
  .bulkbar b { color: #6ee7b7; }
  .device-card .avatar { background: #10362f; color: #6ee7b7; }
  .pair-code { background: #10362f; color: #6ee7b7; }
  .qr-box { background: #0f1720; }
  .login-card { background: var(--panel); }
}
