:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --yellow: #d97706;
  --yellow-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --gray-soft: #e2e8f0;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius: 24px;
}

#bynod-crm-root,
#bynod-crm-root * {
  box-sizing: border-box;
}

#bynod-crm-root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
}

body.bynod-crm-print,
@media print {
  body { background: #fff !important; }
}

.loading-screen {
  min-height: 70vh;
  display: grid;
  place-items: center;
  gap: 16px;
  color: var(--muted);
}

.loader {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  background: #0f172a;
  color: #fff;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.sidebar-brand strong {
  display: block;
  font-size: 1.2rem;
}

.sidebar-brand span {
  display: block;
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
}

.sidebar-logo,
.avatar,
.avatar.large,
.avatar.soft,
.avatar.tiny {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  font-weight: 800;
}

.sidebar-logo {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-right: 4px;
}

.nav-group small,
small,
label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sidebar .nav-group small {
  color: rgba(255,255,255,0.58);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.nav-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: transparent;
  color: rgba(255,255,255,0.78);
  padding: 12px 14px;
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-btn.mini { padding: 10px 12px; font-size: 0.9rem; }
.nav-btn .grow { flex: 1; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}
.dot.green { background: #22c55e; }
.dot.yellow { background: #f59e0b; }
.dot.red { background: #ef4444; }

.content {
  padding: 32px;
}

.content.home-mode {
  padding: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.page-head h1,
.home-panel h2,
.home-aside h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 1.05;
  font-weight: 900;
}

.page-head p,
.home-panel p,
.home-aside p,
.muted {
  color: var(--muted);
  margin: 8px 0 0;
}

.muted.light { color: rgba(255,255,255,0.75); }
.muted.small { font-size: 0.9rem; }
.accent, .accent-text { color: var(--blue); }
.italic { font-style: italic; }
.pre { white-space: pre-wrap; }
.center { text-align: center; }

.grid {
  display: grid;
}

.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.four-col { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-one { grid-template-columns: 1.4fr 1fr; }
.top-align { align-items: start; }
.gap-16 { gap: 16px; }
.gap-12 { gap: 12px; }
.gap-8 { gap: 8px; }
.span-2 { grid-column: span 2; }
.expense-grid { grid-template-columns: 180px 1fr 180px auto; }

.stack-16 > * + * { margin-top: 16px; }
.stack-12 > * + * { margin-top: 12px; }
.stack-8 > * + * { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-12 { margin-top: 12px; }
.mt-8 { margin-top: 8px; }
.actions-end {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.inline-row.start { justify-content: flex-start; }

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

.card {
  padding: 22px;
}

.subcard,
.callout,
.row-item,
.calendar-day,
.field,
.code-pill,
.pill,
.chip-static,
.service-row {
  border-radius: 18px;
}

.row-item,
.subcard,
.callout,
.calendar-day,
.service-row {
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}
.row-item.wrap { flex-wrap: wrap; }
.row-item.start-col { align-items: flex-start; }

.service-row {
  display: grid;
  grid-template-columns: 28px 1fr 90px 42px;
  gap: 10px;
  padding: 10px;
}

.drag-handle {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.stat-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card strong {
  font-size: clamp(2rem, 2.8vw, 2.7rem);
  line-height: 1;
}

.stat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
}

.dark-card {
  background: #0f172a;
  color: #fff;
  border-color: #1e293b;
}
.dark-card small,
.dark-card p,
.badge.inverse { color: rgba(255,255,255,0.9); }
.dark-card .badge.inverse { background: rgba(255,255,255,0.1); }

.shell-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.shell-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.shell-card-title h2,
.card h3,
.card h4,
.modal-header h3,
.receipt-main h3 {
  margin: 0;
  font-size: 1.2rem;
}

.icon-chip,
.avatar.soft {
  width: 38px;
  height: 38px;
  background: var(--blue-soft);
  color: var(--blue);
}

.avatar {
  width: 52px;
  height: 52px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 1.2rem;
}

.avatar.large { width: 64px; height: 64px; font-size: 1.5rem; }
.avatar.tiny { width: 28px; height: 28px; border-radius: 10px; background: rgba(255,255,255,0.12); color: #fff; font-size: 0.8rem; }

.field {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  color: var(--text);
  outline: none;
}

.field:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.textarea {
  min-height: 110px;
  resize: vertical;
}

.field.danger,
.callout.error,
.callout.danger,
.icon-btn.danger,
.btn.btn-danger.ghost,
.danger-text {
  border-color: #fecaca;
  background: var(--red-soft);
  color: #991b1b;
}

.small-field { max-width: 90px; }

.btn,
.link-btn,
.icon-btn,
.chip-btn,
.code-pill {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
}

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

.btn-soft {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #bfdbfe;
}

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

.btn-danger.ghost {
  background: var(--red-soft);
  color: #991b1b;
}

.btn-block { width: 100%; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0;
  text-align: left;
  font-weight: 700;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
}

.icon-btn.inside {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.password-row { position: relative; }
.password-row .field { padding-right: 54px; }

.role-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #eef2ff;
  border-radius: 999px;
  padding: 6px;
  gap: 6px;
}

.role-switch button,
.chip-btn {
  border-radius: 999px;
  padding: 10px 12px;
  font-weight: 700;
  background: #fff;
}

.role-switch button.active,
.chip-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-static,
.pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.78rem;
}

.pill,
.code-pill,
.chip-static { background: #fff; border: 1px solid var(--line); }
.code-pill { padding: 7px 10px; border-radius: 12px; }

.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.gray { background: var(--gray-soft); color: #334155; }

.money.positive { color: var(--green); }
.money.negative { color: var(--red); }

.callout {
  padding: 14px 16px;
}

.callout.error strong { display: block; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
}

.calendar-weekdays {
  margin-bottom: 12px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
}

.calendar-day {
  min-height: 140px;
  padding: 12px;
  text-align: left;
}

.calendar-day.today {
  background: var(--blue-soft);
  border-color: #93c5fd;
}

.calendar-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.calendar-event-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.calendar-pill {
  display: block;
  border-radius: 999px;
  padding: 6px 8px;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-pill.payment { background: var(--green); }
.calendar-pill.due { background: var(--red); }
.calendar-pill.service { background: #334155; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 10000;
}

.modal-panel {
  width: min(100%, 1024px);
  padding: 24px;
  max-height: 90vh;
  overflow: auto;
}
.max-w-2xl { max-width: 760px; }
.max-w-3xl { max-width: 980px; }
.max-w-4xl { max-width: 1100px; }

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

.receipt-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
}

.receipt-side {
  border-radius: 24px;
  padding: 24px;
  background: linear-gradient(180deg, #eff6ff, #f8fafc);
  border: 1px solid var(--line);
}

.receipt-icon {
  width: 80px;
  height: 80px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
  margin-bottom: 16px;
}

.receipt-amount {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  margin-top: 18px;
}

.receipt-amount strong { font-size: 2rem; display: block; margin-top: 6px; }

.toast-stack {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 11000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 280px;
  max-width: 360px;
  border-radius: 18px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  background: #fff;
  border: 1px solid var(--line);
}

.toast.success { border-color: #bbf7d0; background: #f0fdf4; }
.toast.error { border-color: #fecaca; background: #fef2f2; }
.toast.info { border-color: #bfdbfe; background: #eff6ff; }
.toast p { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.toast button { border: 0; background: transparent; cursor: pointer; color: var(--muted); }

.home-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  background: var(--bg);
}

.home-aside {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #fff;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.home-brand {
  display: inline-flex;
  width: fit-content;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  margin-bottom: 22px;
  font-weight: 700;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.home-item {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.home-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 42px;
}

.logout-btn {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
  color: #fff;
}

.option-card {
  text-align: left;
}
.option-card strong { font-size: 1.3rem; }

.receipt-main small,
.card small,
.info-line small { text-transform: uppercase; }

.print-hide { }

@media (max-width: 1200px) {
  .three-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .four-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-one, .receipt-grid, .expense-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; min-height: auto; }
  .home-layout { grid-template-columns: 1fr; }
  .home-aside { display: none; }
  .two-col, .three-col, .four-col { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .content { padding: 20px; }
  .calendar-weekdays, .calendar-grid { gap: 8px; }
  .calendar-day { min-height: 110px; }
}

@media print {
  .print-hide,
  .sidebar,
  .toast-stack,
  .modal-backdrop .modal-header,
  .btn,
  .icon-btn,
  .logout-btn {
    display: none !important;
  }
  .app-shell,
  .content,
  .card,
  .modal-panel {
    background: #fff !important;
    box-shadow: none !important;
    border: 0 !important;
    padding: 0 !important;
  }
  .modal-backdrop {
    position: static;
    background: transparent;
    padding: 0;
  }
}
