:root {
  --brand: #C0392B;
  --brand-dark: #922B21;
  --brand-soft: #FEF2F2;
  --accent: #E74C3C;
  --bg: #F3F4F6;
  --card: #FFFFFF;
  --text: #1A1A2E;
  --muted: #6B7280;
  --line: #E5E7EB;
  --ok: #059669;
  --warn: #D97706;
  --danger: #DC2626;
  --shadow: 0 6px 20px rgba(26, 26, 46, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Cairo", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}
body.nav-open { overflow: hidden; }
img, svg, video { max-width: 100%; height: auto; }
button, input, select, textarea { max-width: 100%; font: inherit; }
:focus-visible {
  outline: 2px solid rgba(192, 57, 43, 0.45);
  outline-offset: 2px;
}

.view[hidden] { display: none !important; }
.boot-view[hidden] { display: none !important; }
body[data-view="boot"] #loginView,
body[data-view="boot"] #appView { display: none !important; }
body[data-view="login"] #bootView,
body[data-view="login"] #appView { display: none !important; }
body[data-view="admin"] #bootView,
body[data-view="admin"] #loginView { display: none !important; }
body[data-view="admin"] #appView { display: flex !important; }

.boot-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #FEF2F2 0%, #F3F4F6 45%, #fff 100%);
}
.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.boot-card strong {
  letter-spacing: 0.06em;
  font-size: 0.95rem;
}
.boot-card span {
  color: var(--muted);
  font-size: 0.84rem;
}
.boot-spinner {
  width: 28px;
  height: 28px;
  margin-top: 6px;
  border-radius: 50%;
  border: 3px solid #F5B7B1;
  border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== LOGIN ===== */
.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(200px, 30vh) 1fr;
  background: var(--bg);
}

.login-hero {
  position: relative;
  background: linear-gradient(145deg, var(--brand) 0%, var(--brand-dark) 60%, #7B241C 100%);
  color: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0 0 28px 28px;
  box-shadow: 0 12px 28px rgba(192, 57, 43, 0.22);
}

.login-hero-glow {
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.2), transparent 70%);
  top: -40px;
  left: -20px;
}

.brand-mark { text-align: center; z-index: 1; padding: 16px; }
.brand-mark h1 {
  margin: 10px 0 4px;
  letter-spacing: 0.08em;
  font-size: clamp(1.3rem, 3vw, 1.75rem);
}
.brand-mark p { margin: 0; opacity: 0.92; font-size: 0.9rem; }

.logo-disc {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--brand);
  background: #fff;
  box-shadow: 0 8px 16px rgba(0,0,0,0.14);
}
.logo-disc.sm {
  width: 38px;
  height: 38px;
  margin: 0;
  border-radius: 11px;
  font-size: 0.78rem;
  color: #fff;
  background: linear-gradient(145deg, var(--brand), var(--brand-dark));
  box-shadow: none;
}

.login-sheet {
  width: min(400px, calc(100% - 32px));
  margin: -36px auto 36px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  position: relative;
  z-index: 2;
}

.login-sheet h2 { margin: 0 0 4px; font-size: 1.2rem; text-align: center; }
.login-sheet .sub { margin: 0 0 18px; color: var(--muted); font-size: 0.88rem; text-align: center; }

.stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 0.86rem; font-weight: 600; }
label > span { color: var(--text); }

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap input {
  padding-left: 44px;
}
.password-toggle {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}
.password-toggle:hover { color: var(--brand); background: var(--brand-soft); }

.remember-row {
  display: flex !important;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  cursor: pointer;
}
.remember-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--brand);
  margin: 0;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #F9FAFB;
  border-radius: 11px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #F5B7B1;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
  background: #fff;
}

.btn-primary, .btn-ghost, .btn-warn, .btn-ok, .btn-danger, .btn-logout {
  border: 0;
  border-radius: 11px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  box-shadow: 0 5px 14px rgba(192, 57, 43, 0.2);
}
.btn-block { width: 100%; }
.btn-ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn-ghost.sm { padding: 4px 9px; font-size: 0.76rem; }
.btn-ok.sm,
.btn-warn.sm { padding: 4px 9px; font-size: 0.76rem; }
.btn-warn {
  background: #FFFBEB;
  color: #B45309;
  border: 1px solid #FDE68A;
  min-width: 110px;
}
.btn-ok {
  background: #ECFDF5;
  color: #047857;
  border: 1px solid #A7F3D0;
  min-width: 110px;
}
.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #FECACA;
  min-width: 110px;
}
.error { color: var(--danger); margin: 0; font-size: 0.86rem; }

/* ===== ADMIN: top bar instead of sidebar ===== */
.admin-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px rgba(192, 57, 43, 0.06);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-brand strong { display: block; font-size: 0.88rem; letter-spacing: 0.04em; }
.app-brand small { color: var(--muted); font-size: 0.72rem; }

.top-tabs {
  display: inline-flex;
  justify-self: center;
  background: #F3F4F6;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.top-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.top-tab.active {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.25);
}

.nav-badge {
  background: var(--brand);
  color: #fff;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  font-size: 0.7rem;
  padding: 0 5px;
}

.btn-logout {
  background: var(--brand-soft);
  color: var(--danger);
  border: 1px solid #FECACA;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

.admin-notif-wrap {
  position: relative;
}

.btn-admin-notif {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
}

.btn-admin-notif:hover {
  border-color: #FECACA;
  background: #FFF7F7;
}

.admin-notif-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.68rem;
}

.admin-notif-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: min(360px, 88vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
  overflow: hidden;
  z-index: 40;
}

.admin-notif-panel > header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #FAFAFA;
}

.admin-notif-panel > header strong {
  font-size: 0.9rem;
}

.admin-notif-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-notif-clear {
  border: 1px solid #FECACA;
  border-radius: 999px;
  padding: 5px 9px;
  background: #FFF1F2;
  color: #BE123C;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-notif-enable {
  border: 0;
  border-radius: 999px;
  padding: 5px 9px;
  background: #FFF7ED;
  color: #B45309;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-notif-enable.enabled {
  background: #ECFDF5;
  color: #047857;
}

.btn-notif-enable:disabled {
  cursor: default;
  opacity: 0.65;
}

.admin-notif-list {
  max-height: 340px;
  overflow: auto;
}

.admin-notif-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.admin-notif-item {
  width: 100%;
  display: flex;
  align-items: center;
  border: 0;
  border-bottom: 1px solid #F1F5F9;
  background: #fff;
  text-align: right;
}

.admin-notif-open {
  min-width: 0;
  flex: 1;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 0;
  background: transparent;
  padding: 12px 14px;
  text-align: right;
  cursor: pointer;
}

.admin-notif-item:hover {
  background: #FFF7F7;
}

.admin-notif-delete {
  width: 30px;
  height: 30px;
  margin-left: 10px;
  flex: 0 0 30px;
  border: 1px solid #FECACA;
  border-radius: 50%;
  background: #FFF1F2;
  color: #BE123C;
  font: inherit;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.admin-notif-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
  background: #C0392B;
}
.admin-notif-dot.device { background: #D97706; }
.admin-notif-dot.renewal { background: #C0392B; }

.admin-notif-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.admin-notif-copy strong {
  font-size: 0.88rem;
  color: var(--ink, #111);
}
.admin-notif-copy em {
  font-style: normal;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-push-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

.admin-push-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 4px 4px;
}

.admin-push-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
  font-size: 0.85rem;
}

.admin-push-form input,
.admin-push-form select,
.admin-push-form textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}

.admin-push-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.admin-push-status {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
}
.admin-push-status.ok { color: #059669; }
.admin-push-status.err { color: #C0392B; }

.telegram-settings-panel {
  margin-bottom: 18px;
  overflow: hidden;
}
.telegram-icon {
  background: linear-gradient(135deg, #229ED9, #0F6F9E) !important;
  color: #fff !important;
}
.telegram-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.telegram-conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.telegram-conn-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.telegram-conn-badge.is-on {
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}
.telegram-conn-badge.is-off {
  color: #64748b;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}
.telegram-enable-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #fff5f5;
  border: 1px solid #fecaca;
  font-size: 0.86rem;
  font-weight: 700;
  color: #9f1239;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.telegram-enable-switch input {
  accent-color: #c0392b;
  width: 16px;
  height: 16px;
}
.telegram-settings-body {
  display: grid;
  gap: 14px;
  padding: 4px 2px 2px;
}
.telegram-creds-card,
.telegram-events-card {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 14px;
  background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.telegram-creds-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: #475569;
  letter-spacing: 0.04em;
}
.telegram-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.telegram-grid label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  color: #334155;
}
.telegram-grid input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #dbe3ee;
  background: #fff;
  color: inherit;
  padding: 11px 13px;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.telegram-grid input:focus {
  outline: none;
  border-color: #229ED9;
  box-shadow: 0 0 0 3px rgba(34, 158, 217, 0.15);
}
.telegram-hint {
  margin: 0;
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.55;
}
.telegram-events {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}
.telegram-event-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #e2e8f0;
  font-size: 0.86rem;
  font-weight: 600;
  color: #1e293b;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.telegram-event-item:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}
.telegram-event-item:has(input:checked) {
  border-color: #86efac;
  background: #f0fdf4;
}
.telegram-event-item input {
  accent-color: #16a34a;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.telegram-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 2px;
}
@media (max-width: 800px) {
  .telegram-grid {
    grid-template-columns: 1fr;
  }
  .telegram-head-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

.admin-sent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding: 4px;
}

.admin-sent-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
}

.admin-sent-card-head,
.admin-history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-sent-delete {
  border: 1px solid #FECACA;
  border-radius: 9px;
  background: #FFF1F2;
  color: #BE123C;
  padding: 4px 8px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-sent-delete:hover {
  background: #FFE4E6;
}

.admin-sent-card strong {
  display: block;
  margin-bottom: 4px;
}
.admin-sent-card p {
  margin: 0 0 8px;
  color: #475569;
  font-size: 0.88rem;
  line-height: 1.5;
}
.admin-sent-card .meta {
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 960px) {
  .admin-push-layout {
    grid-template-columns: 1fr;
  }
}

.admin-main {
  flex: 1;
  min-width: 0;
  padding: 14px 18px 20px;
}

.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.page-toolbar h2 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 0.8rem; }
#btnNewClient {
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 0.86rem;
  white-space: nowrap;
}

.page[hidden] { display: none !important; }

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.list-pane, .detail-pane {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list-pane {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 100px);
}

.clients-search-box {
  display: grid;
  gap: 8px;
}
.clients-search-box input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
.clients-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.clients-filters label {
  display: grid;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
}
.clients-filters select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 8px;
  font: inherit;
  background: #fff;
  color: inherit;
}
.clients-list-meta {
  font-size: 0.78rem;
  padding: 0 2px;
}
.clients-clear-filters {
  justify-self: start;
}
.client-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.client-item .company {
  margin-top: 2px;
  font-size: 0.78rem;
  color: #64748b;
}
.client-item .presence {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.client-item .presence.online {
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}
.client-item .presence.offline {
  color: #64748b;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.list {
  display: grid;
  gap: 7px;
  overflow: auto;
}

.client-item {
  display: block;
  width: 100%;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 11px;
  cursor: pointer;
  background: #fff;
  font: inherit;
  color: inherit;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.client-item:hover {
  border-color: #F5B7B1;
  box-shadow: 0 4px 12px rgba(192, 57, 43, 0.08);
}
.client-item.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 var(--brand);
}
.client-form[hidden] { display: none !important; }
.client-form.is-visible { display: block; }
.client-item .code { font-weight: 800; color: var(--brand); font-size: 0.88rem; }
.client-item .name { margin-top: 2px; font-size: 0.86rem; }
.client-item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.client-item-badges .badge {
  font-size: 0.72rem;
}
.badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.badge.Active { background: #ECFDF5; color: #047857; }
.badge.Suspended { background: #FFFBEB; color: #B45309; }
.badge.Expired { background: var(--brand-soft); color: var(--danger); }

.detail-pane { padding: 0; overflow: hidden; min-height: 120px; }

.empty-state {
  padding: 14px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  background: #FAFAFA;
  border-bottom: 1px solid var(--line);
}
.empty-state p { margin: 0; }
.empty-state[hidden] { display: none !important; }

.client-form { padding: 14px 16px 16px; }
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.detail-header h3 { margin: 0 0 6px; font-size: 1.05rem; }
.activation-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.82rem;
}
.activation-row code {
  background: #1A1A2E;
  color: #fff;
  padding: 3px 9px;
  border-radius: 7px;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.stat-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.stat-mini {
  font-size: 0.8rem;
  color: var(--muted);
  background: #F9FAFB;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}
.stat-mini strong { color: var(--brand); }

.status-pill {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: #ECFDF5;
  color: #047857;
}
.status-pill.Suspended { background: #FFFBEB; color: #B45309; }
.status-pill.Expired { background: var(--brand-soft); color: var(--danger); }

.form-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}
.form-section h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sec-num {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.section-hint {
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.form-grid .field-hint {
  font-weight: 600;
  color: #64748b;
  font-size: 0.75rem;
}

.period-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}
.period-grid > label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 0.85rem;
}
.period-duration-field {
  align-content: start;
}
.duration-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.duration-chips button {
  border: 1px solid var(--line);
  background: #F9FAFB;
  color: var(--text);
  border-radius: 999px;
  padding: 5px 11px;
  font: inherit;
  font-weight: 700;
  font-size: 0.74rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.duration-chips button:hover {
  border-color: #F5B7B1;
}
.duration-chips button.active {
  background: var(--brand-soft);
  border-color: #F5B7B1;
  color: var(--brand);
}

.extend-panel {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border: 1px solid #fed7aa;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.extend-panel[hidden] { display: none !important; }
.extend-copy {
  min-width: 200px;
  flex: 1;
}
.extend-title {
  font-weight: 800;
  color: #9a3412;
  margin: 0 0 4px;
  font-size: 0.88rem;
}
.extend-hint {
  margin: 0;
  color: #c2410c;
  font-size: 0.78rem;
  line-height: 1.45;
}
.extend-controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.extend-controls label {
  display: grid;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #9a3412;
}
.extend-controls input {
  width: 110px;
  border-radius: 10px;
  border: 1px solid #fdba74;
  background: #fff;
  padding: 9px 10px;
  font: inherit;
}
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }

@media (max-width: 1200px) {
  .period-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .period-duration-field { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .period-grid { grid-template-columns: 1fr; }
  .period-duration-field { grid-column: auto; }
  .extend-panel {
    align-items: stretch;
  }
  .extend-controls {
    width: 100%;
  }
  .extend-controls input {
    flex: 1;
    width: auto;
  }
  .extend-controls .btn-primary {
    flex: 1;
  }
}

.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 -4px 16px rgba(26, 26, 46, 0.04);
}
.action-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.devices-list, .pending-grid { display: grid; gap: 12px; }
.device-item, .pending-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #F9FAFB;
}
.device-item .meta, .pending-card .meta { color: var(--muted); font-size: 0.78rem; }
.device-actions, .pending-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.device-mgmt-hint {
  margin: -4px 0 10px;
  font-size: 0.85rem;
}
.device-mgmt-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.device-mgmt-card.is-active { border-color: #bbf7d0; }
.device-mgmt-card.is-pending { border-color: #fde68a; }
.device-mgmt-card.is-blocked { border-color: #fecaca; }
.device-mgmt-card.is-disabled { border-color: #e2e8f0; }

.device-mgmt-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
}
.device-mgmt-identity { min-width: 0; }
.device-mgmt-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.device-mgmt-name {
  font-size: 1rem;
  color: #0f172a;
}
.device-mgmt-sub {
  margin-top: 4px;
  color: #64748b;
  font-size: 0.8rem;
}
.device-mgmt-sub code {
  font-size: 0.78rem;
  direction: ltr;
  display: inline-block;
}

.device-mgmt-body {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border-bottom: 1px solid #f1f5f9;
}
.device-mgmt-group {
  padding: 12px 14px;
  border-left: 1px solid #f1f5f9;
  min-width: 0;
}
.device-mgmt-group:last-child { border-left: 0; }
.device-mgmt-group h5 {
  margin: 0 0 10px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.04em;
}
.device-mgmt-list {
  margin: 0;
  display: grid;
  gap: 8px;
}
.device-mgmt-list > div {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  align-items: start;
}
.device-mgmt-list dt {
  margin: 0;
  color: #94a3b8;
  font-size: 0.72rem;
  font-weight: 700;
}
.device-mgmt-list dd {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 600;
  color: #1e293b;
  word-break: break-word;
}
.device-mgmt-list dd.is-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  direction: ltr;
  text-align: right;
  font-weight: 500;
}
.device-mgmt-list dd.device-reinstall-count {
  color: #9a3412;
  font-weight: 800;
}
.device-reinstall-badge {
  margin-top: 6px;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #9a3412;
  background: #ffedd5;
  border: 1px solid #fdba74;
}
.device-mgmt-card .device-actions {
  padding: 12px 14px 14px;
}
.device-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.device-status {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}
.device-status-active {
  background: #f6ffed;
  color: #389e0d;
  border: 1px solid #b7eb8f;
}
.device-status-pending {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}
.device-status-blocked {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.device-status-disabled {
  background: #fff7e6;
  color: #ad6800;
  border: 1px solid #ffd591;
}
@media (max-width: 980px) {
  .device-mgmt-body {
    grid-template-columns: 1fr;
  }
  .device-mgmt-group {
    border-left: 0;
    border-bottom: 1px solid #f1f5f9;
  }
  .device-mgmt-group:last-child {
    border-bottom: 0;
  }
}

.pending-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.pending-card {
  flex-direction: column;
  align-items: stretch;
  background: #fff;
  box-shadow: var(--shadow);
}
.pending-card h4 { margin: 0 0 6px; }

.btn-primary:disabled,
.btn-ghost:disabled,
.btn-warn:disabled,
.btn-ok:disabled,
.btn-danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  filter: grayscale(0.25);
}

#btnSaveClient[hidden],
.btn-save-client[hidden],
#btnSavePackages[hidden],
#btnSaveBilling[hidden] {
  display: none !important;
}

/* ===== Confirm dialog ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(26, 26, 46, 0.48);
  backdrop-filter: blur(4px);
  animation: fadeIn .16s ease;
}
.confirm-overlay[hidden] { display: none !important; }

.confirm-dialog {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 22px 20px 18px;
  box-shadow: 0 24px 48px rgba(26, 26, 46, 0.22);
  text-align: center;
  border: 1px solid var(--line);
  animation: dialogIn .18s ease;
}
.confirm-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  font-weight: 800;
  background: var(--brand-soft);
  color: var(--brand);
}
.confirm-dialog.tone-warn .confirm-icon {
  background: #FFFBEB;
  color: #B45309;
}
.confirm-dialog.tone-danger .confirm-icon {
  background: #FEF2F2;
  color: var(--danger);
}
.confirm-dialog.tone-ok .confirm-icon {
  background: #ECFDF5;
  color: #047857;
}
.confirm-dialog h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}
.confirm-dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-actions .btn-ghost,
.confirm-actions .btn-primary,
.confirm-actions .btn-danger,
.confirm-actions .btn-warn,
.confirm-actions .btn-ok {
  min-width: 120px;
  flex: 1;
}
.confirm-dialog.tone-danger #confirmOk.btn-danger {
  background: var(--danger);
  color: #fff;
  border: 0;
  box-shadow: 0 5px 14px rgba(220, 38, 38, 0.22);
}
.confirm-dialog.tone-warn #confirmOk {
  background: linear-gradient(135deg, #D97706, #B45309);
  box-shadow: 0 5px 14px rgba(180, 83, 9, 0.22);
  color: #fff;
  border: 0;
}
.confirm-dialog.tone-ok #confirmOk {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 5px 14px rgba(5, 150, 105, 0.22);
  color: #fff;
  border: 0;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes dialogIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-chips button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}
.filter-chips button.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-color: #F5B7B1;
  font-weight: 700;
}

.device-activation-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  margin-top: 12px;
}

.device-activation-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.device-activation-table th,
.device-activation-table td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.device-activation-table th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
  background: #fafafa;
  white-space: nowrap;
}

.device-activation-table tbody tr:last-child td {
  border-bottom: none;
}

.device-activation-table .meta {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.device-activation-table .empty-state-cell {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
}

.device-activation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.device-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.device-status-pending,
.device-status-pendingapproval {
  background: #fff7e6;
  color: #ad6800;
}

.device-status-approved {
  background: #f6ffed;
  color: #389e0d;
}

.device-status-rejected {
  background: #fff1f0;
  color: #cf1322;
}

.device-status-blocked {
  background: #f5f5f5;
  color: #434343;
}

.renewals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  padding: 4px 2px 24px;
}
.renewal-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.renewal-card > header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.renewal-body {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 12px;
  align-items: start;
}
.renewal-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
}
.renewal-info span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}
.reject-note {
  background: #FEF2F2;
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
}
.proof-thumb {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  padding: 0;
  background: #fff;
  cursor: pointer;
  width: 96px;
  height: 96px;
}
.proof-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.proof-missing {
  width: 96px;
  height: 96px;
  border-radius: 10px;
  background: #F9FAFB;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.78rem;
}
.renewal-actions {
  display: flex;
  gap: 8px;
}
.renewal-actions .btn-ok,
.renewal-actions .btn-danger {
  flex: 1;
}

.payments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.payment-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #FAFAFA;
}
.payment-item .meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.payment-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.badge.Approved { background: #ECFDF5; color: var(--ok); }
.badge.Rejected { background: #FEF2F2; color: var(--danger); }
.badge.Pending { background: #FFFBEB; color: var(--warn); }

.billing-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 18px;
  padding: 22px 22px 20px;
  border-radius: 18px;
  color: #fff;
  background:
    radial-gradient(circle at 12% 20%, rgba(255,255,255,0.18), transparent 42%),
    linear-gradient(135deg, #1A1A2E 0%, #2C3E50 48%, #922B21 100%);
  box-shadow: 0 14px 34px rgba(26, 26, 46, 0.18);
}
.billing-kicker {
  display: inline-block;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0.72;
  margin-bottom: 8px;
}
.billing-hero h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 800;
}
.billing-hero p {
  margin: 0;
  max-width: 540px;
  line-height: 1.7;
  color: rgba(255,255,255,0.82);
  font-size: 0.9rem;
}
.billing-save-btn {
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.billing-layout {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 16px;
  padding-bottom: 32px;
  align-items: start;
}
.billing-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}
.billing-panel-packages {
  grid-column: 1 / -1;
}
.billing-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #FBFBFB 0%, #fff 100%);
}
.billing-panel-head h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}
.billing-panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}
.billing-panel-head-row {
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.billing-panel-head-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}
.billing-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.05rem;
  flex-shrink: 0;
}
.billing-icon-warn {
  background: #FFF7ED;
  color: #C2410C;
  border: 1px solid #FED7AA;
}
.billing-icon-pay {
  background: #ECFDF5;
  color: #047857;
  border: 1px solid #A7F3D0;
}
.billing-icon-pkg {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border: 1px solid #FECACA;
}

.billing-alert-body,
.billing-pay-body {
  padding: 16px 18px 18px;
  display: grid;
  gap: 12px;
}
.billing-days-field {
  display: grid;
  gap: 8px;
}
.billing-days-control {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #F9FAFB;
}
.billing-days-control input {
  width: 100%;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  font-size: 1.35rem !important;
  font-weight: 800;
  padding: 4px 0 !important;
  color: var(--text);
}
.billing-days-control em {
  font-style: normal;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}
.billing-hint-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 999px;
  background: #FFFBEB;
  color: #92400E;
  border: 1px solid #FDE68A;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.5;
}

.package-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.package-save-hint {
  margin: 0;
  padding: 10px 18px 0;
}
.packages-editor {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 16px 18px 18px;
}
.package-card {
  position: relative;
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(26, 26, 46, 0.04);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.package-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), #F59E0B);
}
.package-card:hover {
  border-color: #F5B7B1;
  box-shadow: 0 10px 24px rgba(192, 57, 43, 0.1);
}
.package-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid #F1F5F9;
  background: linear-gradient(180deg, #FBFBFB 0%, #fff 100%);
}
.package-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.package-card-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.package-card-heading strong {
  font-size: 1rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.package-card-price-chip {
  display: inline-flex;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  background: #FFF5F4;
  color: var(--brand-dark);
  border: 1px solid #FECACA;
  font-size: 0.75rem;
  font-weight: 800;
}
.package-remove-btn {
  flex-shrink: 0;
}
.package-drag-handle {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #F8FAFC;
  color: #64748B;
  font: 800 1rem/1 sans-serif;
  letter-spacing: -3px;
  cursor: grab;
  user-select: none;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.package-drag-handle:hover {
  color: var(--brand);
  border-color: #F5B7B1;
  background: #FFF5F4;
}
.package-drag-handle:active {
  cursor: grabbing;
}
.package-card.is-dragging {
  opacity: .45;
  transform: scale(.98);
}
.package-card.is-drag-over {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, .12);
}
.package-card-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}
.package-basics {
  display: grid;
  gap: 10px;
}
.package-basics > label,
.package-metrics label,
.package-features-field {
  display: grid;
  gap: 6px;
  margin: 0;
}
.package-basics > label > span,
.package-metrics label > span,
.package-features-field > span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}
.package-features-field > span em {
  font-style: normal;
  font-weight: 600;
  opacity: 0.85;
}
.package-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.package-metrics input {
  text-align: center;
  font-weight: 700;
}
.package-features-field textarea {
  min-height: 96px;
  resize: vertical;
  font: inherit;
  line-height: 1.55;
}
.package-active-field {
  margin: 0;
}
.package-active-row {
  display: inline-flex !important;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #A7F3D0;
  border-radius: 10px;
  background: #ECFDF5;
  box-sizing: border-box;
}
.package-active-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: #059669;
  cursor: pointer;
}
.package-active-text {
  flex: 0 1 auto;
  color: #065F46 !important;
  font-weight: 700;
  font-size: 0.84rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1200px) {
  .packages-editor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 780px) {
  .packages-editor {
    grid-template-columns: 1fr;
  }
}
.features-custom-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-weight: 700;
  font-size: 0.9rem;
}
.features-custom-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}
.features-editor {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.features-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.feature-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.feature-row input {
  width: 100%;
}
.billing-panel-head-row {
  flex-wrap: wrap;
  gap: 8px;
}
.section-save-bar {
  display: flex;
  justify-content: flex-start;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.section-save-bar:not(:has(button:not([hidden]))) {
  display: none;
  margin: 0;
  padding: 0;
  border: 0;
}
.client-form .action-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: #fff;
  border-top: 1px solid var(--line);
  margin: 12px -4px 0;
  padding: 12px 4px;
  box-shadow: 0 -6px 16px rgba(15, 23, 42, 0.06);
}
.btn-save-client:not([hidden]) {
  animation: savePulse 1.2s ease-in-out 2;
}
@keyframes savePulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.25); }
}

@media (max-width: 980px) {
  .billing-layout {
    grid-template-columns: 1fr;
  }
  .billing-panel-packages {
    grid-column: auto;
  }
}

#rejectMessageInput {
  width: 100%;
  margin: 8px 0 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
}
.proof-dialog {
  background: #111;
  border-radius: 14px;
  padding: 12px;
  max-width: min(92vw, 720px);
  width: 100%;
  position: relative;
}
.proof-dialog img {
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
  border-radius: 8px;
}
.proof-dialog .btn-ghost {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
  background: rgba(255,255,255,0.92);
}

.app-update-layout {
  display: grid;
  grid-template-columns: minmax(330px, 0.8fr) minmax(420px, 1.2fr);
  gap: 16px;
  align-items: start;
}
.distribution-section {
  display: grid;
  gap: 14px;
  margin-bottom: 28px;
}
.page-toolbar.compact {
  margin-bottom: 4px;
}
.page-toolbar.compact h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.qr-dialog {
  width: min(420px, 92vw);
  background: #fff;
  border-radius: 18px;
  padding: 22px 20px 18px;
  display: grid;
  gap: 14px;
  justify-items: center;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}
.qr-dialog h3 {
  margin: 0;
  text-align: center;
}
.qr-dialog canvas,
.qr-dialog .qr-image {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  object-fit: contain;
}
.qr-error {
  margin: 0;
  color: #b91c1c;
  font-size: 0.85rem;
  text-align: center;
}
.qr-url {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.75rem;
  color: #475569;
  background: #f8fafc;
  border-radius: 10px;
  padding: 10px 12px;
  direction: ltr;
  text-align: left;
}
.update-icon {
  color: #fff;
  background: linear-gradient(145deg, #e84b37, #bd2f24);
}
.update-form {
  display: grid;
  gap: 14px;
}
.update-form > label,
.update-form-grid label {
  display: grid;
  gap: 7px;
  font-size: .84rem;
  font-weight: 700;
}
.update-form input,
.update-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  background: var(--card);
  color: var(--text);
  font: inherit;
}
.update-form textarea { resize: vertical; }
.update-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.update-file-drop {
  border: 1px dashed color-mix(in srgb, var(--brand) 58%, var(--line));
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  background: color-mix(in srgb, var(--brand) 5%, var(--card));
}
.update-file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.update-file-drop strong,
.update-file-drop span { display: block; }
.update-file-drop strong { color: var(--brand); font-size: 1rem; }
.update-file-drop span { color: var(--muted); margin-top: 4px; font-weight: 600; }
.update-options {
  display: grid;
  gap: 8px;
}
.update-options label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
}
.update-options input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--brand);
}
.update-options span { display: grid; gap: 2px; }
.update-options small { color: var(--muted); font-weight: 500; line-height: 1.5; }
.app-releases-list {
  display: grid;
  gap: 11px;
}
.app-release-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--card);
  display: grid;
  gap: 10px;
}
.app-release-card.is-active {
  border-color: color-mix(in srgb, #22a06b 58%, var(--line));
  box-shadow: inset 3px 0 0 #22a06b;
}
.app-release-version {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-release-version > div { display: grid; gap: 2px; }
.app-release-version small { color: var(--muted); }
.app-release-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--brand) 10%, var(--card));
  color: var(--brand);
  font-weight: 900;
  font-size: .72rem;
}
.is-active .app-release-mark {
  background: #e8f8f0;
  color: #16784f;
}
.app-release-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .76rem;
}
.release-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--muted);
  font-weight: 800;
}
.release-badge.mandatory { background: #fff0ed; color: #b62f20; }
.release-badge.active { background: #e8f8f0; color: #16784f; }
.app-release-notes {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.65;
}
.app-release-hash {
  direction: ltr;
  text-align: left;
  color: var(--muted);
  font-size: .68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-release-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 2px;
}

@media (max-width: 1200px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-header {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "tabs tabs";
  }
  .app-brand { grid-area: brand; }
  .header-actions { grid-area: actions; }
  .btn-logout { grid-area: unset; }
  .top-tabs {
    grid-area: tabs;
    justify-self: stretch;
    width: 100%;
    overflow-x: auto;
  }
  .top-tab { flex: 1; justify-content: center; white-space: nowrap; }
  .workspace { grid-template-columns: 1fr; }
  .list-pane { position: static; max-height: 240px; }
  .form-grid { grid-template-columns: 1fr; }
  .action-bar { flex-direction: column; align-items: stretch; }
  .action-group { width: 100%; }
  .action-group .btn-primary,
  .action-group .btn-danger,
  .action-group .btn-warn,
  .action-group .btn-ok { flex: 1; }
  .renewal-body {
    grid-template-columns: 1fr;
  }
  .app-update-layout,
  .update-form-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== PWA + Responsive polish ===== */
.brand-caption {
  display: none;
  color: var(--muted);
  font-size: 0.7rem;
}

.btn-nav-menu {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 9px;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-nav-menu span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

.btn-install-pwa {
  border: 1px solid #FECACA;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.btn-install-pwa:hover { background: #FFE4E6; }
.btn-primary.sm,
.btn-ghost.sm {
  min-height: 36px;
}

.nav-drawer {
  position: fixed;
  inset: 0;
  z-index: 1200;
}
.nav-drawer[hidden] { display: none !important; }
.nav-drawer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
}
.nav-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(320px, 88vw);
  height: 100%;
  background: #fff;
  box-shadow: -12px 0 40px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  animation: drawerIn .2s ease;
}
@keyframes drawerIn {
  from { transform: translateX(18px); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}
.nav-drawer-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.nav-drawer-panel .app-brand small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}
.nav-drawer-list {
  display: grid;
  gap: 6px;
  padding: 12px;
  overflow: auto;
}
.nav-drawer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  background: #F8FAFC;
  color: var(--text);
  border-radius: 14px;
  padding: 14px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  text-align: right;
  cursor: pointer;
  min-height: 48px;
}
.nav-drawer-item.active {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  box-shadow: 0 8px 18px rgba(192, 57, 43, 0.22);
}
.nav-drawer-item.active .nav-badge {
  background: rgba(255,255,255,0.22);
}

.pwa-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px;
  border-radius: 18px;
  background: #111827;
  color: #fff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.28);
}
.pwa-install-banner[hidden] { display: none !important; }
.pwa-install-banner strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 2px;
}
.pwa-install-banner span {
  display: block;
  color: #CBD5E1;
  font-size: 0.78rem;
  line-height: 1.45;
}
.pwa-install-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.pwa-install-actions .btn-ghost {
  background: rgba(255,255,255,0.08);
  color: #E2E8F0;
  border-color: rgba(255,255,255,0.14);
}
body.is-standalone .pwa-install-banner,
body.is-standalone .btn-install-pwa {
  display: none !important;
}

@media (max-width: 1100px) {
  .top-tab {
    padding: 8px 12px;
    font-size: 0.8rem;
  }
  .app-update-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .btn-nav-menu { display: inline-flex; }
  .brand-caption { display: block; }
  .top-tabs { display: none !important; }
  .app-header {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand actions";
    padding: 10px 12px;
    gap: 10px;
  }
  .admin-main { padding: 12px 12px 88px; }
  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .page-toolbar > div:last-child,
  #btnNewClient {
    width: 100%;
  }
  .billing-hero {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 18px 16px;
  }
  .billing-hero h2 { font-size: 1.15rem; }
  .billing-save-btn { width: 100%; }
  .billing-panel-head,
  .billing-panel-head-row {
    flex-direction: column;
    align-items: stretch;
  }
  .packages-editor {
    grid-template-columns: 1fr !important;
  }
  .admin-notif-panel {
    position: fixed;
    top: calc(64px + env(safe-area-inset-top, 0px));
    left: 10px;
    right: 10px;
    width: auto;
    max-height: min(70vh, 520px);
  }
  .admin-notif-list { max-height: min(52vh, 380px); }
  .admin-notif-header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .confirm-overlay { padding: 12px; align-items: end; }
  .confirm-dialog {
    width: 100%;
    border-radius: 18px 18px 14px 14px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .confirm-actions {
    flex-direction: column-reverse;
  }
  .confirm-actions .btn-ghost,
  .confirm-actions .btn-primary,
  .confirm-actions .btn-danger,
  .confirm-actions .btn-warn,
  .confirm-actions .btn-ok {
    width: 100%;
    min-width: 0;
  }
  .pending-grid {
    grid-template-columns: 1fr;
  }
  .renewal-actions {
    flex-direction: column;
  }
  .renewal-actions .btn-ok,
  .renewal-actions .btn-danger {
    width: 100%;
  }
  .pwa-install-banner {
    flex-direction: column;
    align-items: stretch;
  }
  .pwa-install-actions { width: 100%; }
  .pwa-install-actions .btn-primary,
  .pwa-install-actions .btn-ghost {
    flex: 1;
  }
  .app-release-actions {
    flex-direction: column;
  }
  .app-release-actions .btn-ghost,
  .app-release-actions .btn-ok,
  .app-release-actions .btn-danger {
    width: 100%;
    justify-content: center;
  }
  .update-options label {
    align-items: flex-start;
  }
  .btn-logout {
    padding-inline: 12px;
  }
}

@media (max-width: 640px) {
  .login-view {
    grid-template-rows: minmax(160px, 26vh) 1fr;
  }
  .login-sheet {
    width: calc(100% - 20px);
    margin: -28px auto 24px;
    padding: 20px 16px;
  }
  .logo-disc.sm {
    width: 34px;
    height: 34px;
  }
  .app-brand strong {
    font-size: 0.8rem;
  }
  .header-actions {
    gap: 6px;
  }
  .btn-install-pwa {
    padding: 7px 10px;
    font-size: 0.72rem;
  }
  .list-pane { max-height: 200px; }
  .admin-push-layout,
  .form-grid,
  .workspace {
    gap: 10px;
  }
  .device-actions,
  .pending-actions,
  .action-group {
    width: 100%;
  }
  .device-actions button,
  .pending-actions button {
    flex: 1;
  }
}

@media (min-width: 901px) {
  .nav-drawer { display: none !important; }
  .btn-nav-menu { display: none !important; }
}

@media (display-mode: standalone) {
  .app-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .admin-main {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
}

@media (hover: none) and (pointer: coarse) {
  .top-tab,
  .btn-primary,
  .btn-ghost,
  .btn-ok,
  .btn-warn,
  .btn-danger,
  .nav-drawer-item,
  .btn-admin-notif,
  .btn-nav-menu {
    min-height: 44px;
  }
}

/* ===== Dashboard ===== */
.dash-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.dash-kpi {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 14px;
  text-align: start;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  font-family: inherit;
}
.dash-kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .08);
}
.dash-kpi-value {
  display: block;
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 6px;
  color: var(--text, #111);
}
.dash-kpi-label {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
}
.dash-kpi-ok .dash-kpi-value { color: #16a34a; }
.dash-kpi-warn .dash-kpi-value { color: #d97706; }
.dash-kpi-danger .dash-kpi-value { color: #dc2626; }
.dash-kpi-info .dash-kpi-value { color: #2563eb; }
.dash-kpi-muted .dash-kpi-value { color: #64748b; }
.dash-kpi-neutral .dash-kpi-value { color: var(--brand); }

.dash-charts-grid,
.dash-lists-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.dash-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}
.dash-panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #FBFBFB 0%, #fff 100%);
}
.dash-panel-head h3 {
  margin: 0;
  font-size: .98rem;
}
.dash-panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .78rem;
}
.dash-panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.dash-chart-wrap {
  height: 240px;
  padding: 12px 14px 18px;
}
.dash-versions-list {
  padding: 0 16px 16px;
  display: grid;
  gap: 10px;
}
.dash-version-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .82rem;
  margin-bottom: 4px;
}
.dash-version-head span { color: var(--muted); }
.dash-version-bar {
  height: 8px;
  border-radius: 999px;
  background: #f1f5f9;
  overflow: hidden;
}
.dash-version-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #C0392B, #e74c3c);
  border-radius: inherit;
}
.dash-feed {
  padding: 8px 10px 12px;
  display: grid;
  gap: 6px;
  max-height: 420px;
  overflow: auto;
}
.dash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 12px;
}
.dash-row:hover { background: #f8fafc; }
.dash-row strong {
  display: block;
  font-size: .9rem;
}
.dash-row small {
  display: block;
  color: var(--muted);
  font-size: .75rem;
  margin-top: 2px;
}
.dash-row-meta {
  display: grid;
  justify-items: end;
  gap: 4px;
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
}
.dash-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: .7rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
}
.dash-pill.online { background: #dcfce7; color: #166534; }
.dash-pill.offline { background: #f1f5f9; color: #64748b; }
.dash-pill.warn { background: #ffedd5; color: #c2410c; }
.dash-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
}

@media (max-width: 1100px) {
  .dash-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .dash-charts-grid,
  .dash-lists-grid { grid-template-columns: 1fr; }
  .dash-kpi-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .dash-kpi-grid { grid-template-columns: 1fr; }
}
