* {
  box-sizing: border-box;
}

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

.tnum {
  font-variant-numeric: tabular-nums;
}

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  background: var(--c-neutral-soft);
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--c-text-2);
}

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

.sidebar {
  width: 248px;
  background: var(--c-sidebar);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 14px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4355e8 0%, #6d5dfc 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(67, 85, 232, 0.28);
}

.brand-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1.25;
}

.brand-sub {
  font-size: 11.5px;
  color: var(--c-text-3);
  margin-top: 1px;
}

.nav-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 2px;
}

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--c-sidebar-muted);
  padding: 0 10px 5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--c-sidebar-text);
  padding: 9px 11px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn-left {
  display: flex;
  align-items: center;
  gap: 9px;
}

.nav-btn svg {
  opacity: 0.72;
  flex-shrink: 0;
}

.nav-btn:hover {
  background: var(--c-sidebar-hover);
  color: var(--c-text);
}

.nav-btn.active {
  background: var(--c-sidebar-active-bg);
  color: var(--c-sidebar-active-text);
  font-weight: 600;
}

.nav-btn.active svg {
  opacity: 1;
  color: var(--c-sidebar-active-text);
}

.nav-badge {
  background: var(--c-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  line-height: 1.4;
}

.nav-badge-soft {
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

.nav-sub-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 4px 16px;
  padding-left: 10px;
  border-left: 1.5px solid var(--c-border);
}

.nav-sub-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--c-text-2);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-sub-btn:hover {
  background: var(--c-sidebar-hover);
  color: var(--c-text);
}

.nav-sub-btn.active {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 600;
}

.nav-sub-count {
  font-size: 11px;
  color: var(--c-text-3);
  font-variant-numeric: tabular-nums;
}

.nav-sub-btn.active .nav-sub-count {
  color: var(--c-primary);
}

.user-card {
  margin-top: 12px;
  border: 1px solid var(--c-border);
  background: var(--c-surface-muted);
  border-radius: var(--radius);
  padding: 11px 12px;
  font-size: 12.5px;
}

.user-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.user-card strong {
  color: var(--c-text);
  font-size: 13.5px;
}

.user-card .muted {
  color: var(--c-text-2);
  margin-top: 3px;
  font-size: 12px;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar-sub {
  font-size: 12.5px;
  color: var(--c-text-2);
  margin-left: 8px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.role-switch-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--c-primary-soft);
  border: 1px solid rgba(67, 85, 232, 0.18);
  padding: 3px 6px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--c-primary);
  font-weight: 600;
}

.role-switch-wrap select {
  border: 0;
  background: transparent;
  color: var(--c-text);
  font-size: 12.5px;
  font-weight: 600;
  padding: 2px 4px;
  outline: none;
  cursor: pointer;
}

.content {
  padding: 22px 28px 48px;
  max-width: 1420px;
  width: 100%;
  margin: 0 auto;
}

/* ==================== Popover / Notification Bell ==================== */
.popover-anchor {
  position: relative;
}

.popover-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(390px, 92vw);
  max-height: 440px;
  overflow-y: auto;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 60;
}

.notif-item {
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: var(--c-surface-muted);
  margin-bottom: 8px;
}

.notif-item:last-child {
  margin-bottom: 0;
}

/* ==================== Cards & Stats ==================== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-box {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 15px 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.kpi-box.clickable {
  cursor: pointer;
}
.kpi-box.clickable:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(67, 85, 232, 0.25);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--c-text-2);
  font-weight: 500;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--c-text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 12px;
  color: var(--c-text-3);
}

/* ==================== Todo Action Cards on Home ==================== */
.todo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.todo-card {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--c-surface-muted);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.todo-card.urgent {
  background: #fffdf7;
  border-color: rgba(217, 119, 6, 0.28);
}

.todo-card-meta {
  font-size: 12px;
  color: var(--c-text-2);
}

/* ==================== Buttons & Pills ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--c-neutral-soft);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--c-primary-hover);
  color: #fff;
}

.btn-soft {
  background: var(--c-primary-soft);
  border-color: transparent;
  color: var(--c-primary);
}
.btn-soft:hover {
  background: #dfe4ff;
}

.btn-success {
  background: var(--c-success);
  border-color: var(--c-success);
  color: #fff;
}
.btn-success:hover {
  background: #0b7a70;
  color: #fff;
}

.btn-danger {
  background: var(--c-danger);
  border-color: var(--c-danger);
  color: #fff;
}
.btn-danger:hover {
  background: #be123c;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--c-text-2);
}
.btn-ghost:hover {
  background: var(--c-neutral-soft);
  color: var(--c-text);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--c-neutral-soft);
  color: var(--c-text-2);
  white-space: nowrap;
}
.pill-blue { background: var(--c-primary-soft); color: var(--c-primary); }
.pill-green { background: var(--c-success-soft); color: var(--c-success); }
.pill-amber { background: var(--c-warning-soft); color: var(--c-warning); }
.pill-red { background: var(--c-danger-soft); color: var(--c-danger); }

/* ==================== Subtabs & Funnel Stage Bar ==================== */
.subtabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--c-neutral-soft);
  border-radius: var(--radius);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.subtab-btn {
  border: 0;
  background: transparent;
  color: var(--c-text-2);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.14s ease;
}

.subtab-btn:hover {
  color: var(--c-text);
}

.subtab-btn.active {
  background: var(--c-surface);
  color: var(--c-text);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

.stage-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.stage-pill {
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-2);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.14s ease;
}

.stage-pill:hover {
  border-color: var(--c-border-strong);
  color: var(--c-text);
}

.stage-pill.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}

.stage-pill .count {
  font-size: 11px;
  opacity: 0.85;
  background: rgba(15, 23, 42, 0.08);
  padding: 0 6px;
  border-radius: 999px;
}

.stage-pill.active .count {
  background: rgba(255, 255, 255, 0.22);
}

/* ==================== Batch Action Bar ==================== */
.batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--c-primary-soft);
  border: 1px solid rgba(67, 85, 232, 0.22);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
}

/* ==================== Tables & Forms ==================== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #f8fafc;
}

th {
  font-weight: 600;
  color: var(--c-text-2);
  background: var(--c-surface-muted);
  white-space: nowrap;
  font-size: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--c-text-2);
}

input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-xs);
  background: #fff;
  color: var(--c-text);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-ring);
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.notice-box {
  border-left: 3px solid var(--c-primary);
  background: var(--c-primary-soft);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
}
.notice-warn {
  border-left-color: var(--c-warning);
  background: var(--c-warning-soft);
}
.notice-danger {
  border-left-color: var(--c-danger);
  background: var(--c-danger-soft);
}
.notice-success {
  border-left-color: var(--c-success);
  background: var(--c-success-soft);
}

/* ==================== Micro Progress & Full Stepper ==================== */
.mini-steps {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.mini-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
}
.mini-dot.done { background: var(--c-success); }
.mini-dot.active { background: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-ring); }
.mini-dot.warn { background: var(--c-danger); }

.stepper {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  padding: 10px 12px;
  background: var(--c-surface-muted);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.step-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--c-text-3);
}
.step-item .step-bar {
  height: 4px;
  border-radius: 999px;
  background: #e2e8f0;
}
.step-item.done { color: var(--c-success); font-weight: 600; }
.step-item.done .step-bar { background: var(--c-success); }
.step-item.active { color: var(--c-primary); font-weight: 700; }
.step-item.active .step-bar { background: var(--c-primary); }
.step-item.warn { color: var(--c-danger); font-weight: 600; }
.step-item.warn .step-bar { background: var(--c-danger); }

/* ==================== Rule Studio & Weight Meter ==================== */
.rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.rule-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.rule-card:hover {
  border-color: rgba(67, 85, 232, 0.28);
  box-shadow: var(--shadow-sm);
}

.weight-meter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--c-surface-muted);
  border: 1px solid var(--c-border);
  margin-bottom: 10px;
}

.weight-bar {
  flex: 1;
  max-width: 240px;
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.weight-bar > span {
  display: block;
  height: 100%;
  background: var(--c-primary);
  transition: width 0.2s ease, background 0.2s ease;
}

.crm-bento {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.crm-stat {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}
.crm-stat-label { font-size: 11.5px; color: var(--c-text-2); }
.crm-stat-val { font-size: 16px; font-weight: 700; color: var(--c-text); margin-top: 2px; }

/* ==================== Slide-Over Drawer ==================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--c-overlay);
  z-index: 900;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: min(1140px, 96vw);
  height: 100vh;
  background: var(--c-surface);
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.18s ease-out;
}

@keyframes slideInRight {
  from { transform: translateX(24px); opacity: 0.92; }
  to { transform: translateX(0); opacity: 1; }
}

.drawer-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: var(--c-surface);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 28px;
}

.drawer-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==================== Modal ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--c-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal {
  background: var(--c-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-wide {
  max-width: 960px;
}

.modal-head {
  padding: 15px 20px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-foot {
  padding: 13px 20px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-muted);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==================== Signature Pad ==================== */
.sign-pad-wrap {
  border: 1.5px dashed var(--c-border-strong);
  border-radius: var(--radius);
  background: #fff;
  position: relative;
  touch-action: none;
  overflow: hidden;
  height: 220px;
}

.sign-pad-guide {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 34px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.4);
  pointer-events: none;
  z-index: 0;
}

.sign-pad-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 220px;
  display: block;
  pointer-events: none;
  z-index: 1;
}

.sign-pad-placeholder {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 8px;
  text-align: center;
  color: var(--c-text-3);
  font-size: 12px;
  pointer-events: none;
  z-index: 1;
}

canvas.sign-pad {
  width: 100%;
  height: 220px;
  display: block;
  cursor: crosshair;
  touch-action: none;
  position: relative;
  z-index: 2;
}

.sign-pad-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.sign-quality-alert {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--c-danger-soft);
  color: var(--c-danger);
  border: 1px solid rgba(225, 29, 72, 0.35);
  font-size: 13px;
  font-weight: 600;
}

/* ==================== Toast ==================== */
#toastHost {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
  max-width: 380px;
  animation: fadeUp 0.16s ease-out;
}
.toast-success { background: #0f766e; }
.toast-error { background: #be123c; }

@keyframes fadeUp {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==================== Rich Text Editor & Signing Templates ==================== */
.rte-wrap {
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface);
  overflow: hidden;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.rte-wrap:focus-within {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(67, 85, 232, 0.12);
}

.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--c-surface-muted);
  border-bottom: 1px solid var(--c-border);
}

.rte-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding-right: 8px;
  border-right: 1px solid var(--c-border);
}

.rte-group:last-child {
  border-right: none;
  padding-right: 0;
}

.rte-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.3;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.rte-btn:hover {
  background: var(--c-surface);
  border-color: var(--c-border-strong);
  color: var(--c-primary);
}

.rte-vars {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: #f8faff;
  border-bottom: 1px solid var(--c-border);
  font-size: 12px;
  color: var(--c-text-2);
}

.rte-var-chip {
  appearance: none;
  border: 1px solid rgba(67, 85, 232, 0.25);
  background: rgba(67, 85, 232, 0.08);
  color: var(--c-primary);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s ease;
}

.rte-var-chip:hover {
  background: rgba(67, 85, 232, 0.16);
}

.rte-editor {
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
  padding: 14px 16px;
  outline: none;
  font-size: 13.8px;
  line-height: 1.7;
  color: var(--c-text);
}

.rte-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--c-text-3);
  pointer-events: none;
}

.rte-editor h1,
.rte-editor h2,
.rte-editor h3,
.rte-editor h4,
.rich-doc-content h1,
.rich-doc-content h2,
.rich-doc-content h3,
.rich-doc-content h4 {
  margin: 12px 0 6px;
  color: #0f172a;
  line-height: 1.4;
}

.rte-editor h2,
.rich-doc-content h2 {
  font-size: 16px;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 4px;
}

.rte-editor h3,
.rich-doc-content h3 {
  font-size: 14.5px;
}

.rte-editor p,
.rich-doc-content p {
  margin: 6px 0;
}

.rte-editor ul,
.rte-editor ol,
.rich-doc-content ul,
.rich-doc-content ol {
  margin: 6px 0 8px 20px;
  padding: 0;
}

.rte-editor li,
.rich-doc-content li {
  margin: 3px 0;
}

.rte-editor blockquote,
.rich-doc-content blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--c-primary);
  background: #f8fafc;
  color: var(--c-text-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.rte-editor table,
.rich-doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.rte-editor th,
.rte-editor td,
.rich-doc-content th,
.rich-doc-content td {
  border: 1px solid var(--c-border-strong);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}

.rte-editor th,
.rich-doc-content th {
  background: var(--c-surface-muted);
  font-weight: 600;
}

.rte-editor hr,
.rich-doc-content hr {
  border: none;
  border-top: 1px solid var(--c-border-strong);
  margin: 12px 0;
}

.rich-doc-content {
  margin-top: 14px;
  padding: 16px 20px;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.72;
  color: var(--c-text);
}

.emp-picker-box {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface-muted);
  padding: 10px 12px;
}

.emp-picker-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 6px;
  max-height: 170px;
  overflow-y: auto;
  margin-top: 8px;
}

.emp-picker-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
}

.emp-picker-item:hover {
  border-color: var(--c-primary);
}

.tpl-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 12px;
}

.tpl-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.tpl-card:hover {
  border-color: rgba(67, 85, 232, 0.35);
}

.mode-switch {
  display: inline-flex;
  background: var(--c-surface-muted);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 4px;
}

.mode-switch-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--c-text-2);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mode-switch-btn.active {
  background: var(--c-surface);
  color: var(--c-primary);
  box-shadow: var(--shadow-xs);
}

/* ==================== Responsive ==================== */
.mobile-menu-btn {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -270px;
    top: 0;
    bottom: 0;
    transition: left 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .topbar {
    padding: 10px 14px;
  }
  .topbar-sub {
    display: none;
  }
  .content {
    padding: 14px 14px 36px;
  }
  .stepper {
    grid-template-columns: repeat(8, minmax(72px, 1fr));
    overflow-x: auto;
    font-size: 11px;
  }
}
