body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  background: #f5f5fa;
  color: #111827;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #111827;
  color: white;
}

.logo {
  font-weight: 600;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  object-fit: cover;
  background: #e5e7eb;
}

.user-name {
  font-size: 14px;
}

.btn {
  border-radius: 999px;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  background: #e5e7eb;
}

.btn.primary {
  background: #16a34a;
  color: white;
}

.btn.secondary {
  background: #e5e7eb;
}

.btn.small {
  padding: 4px 10px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

main {
  padding: 16px 24px 40px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: none;
  background: #e5e7eb;
  cursor: pointer;
}

.tab.active {
  background: #111827;
  color: white;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.panel {
  background: white;
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.panel h2 {
  margin: 0 0 8px;
}

.muted {
  color: #6b7280;
  font-size: 13px;
}

.muted.small {
  font-size: 12px;
}

.list {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

/* entities & accounts – один столбик */
.list.list-small,
.list.list-modal {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  max-height: 320px;
  overflow-y: auto;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  font-size: 12px;
  background: #f9fafb;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  justify-content: space-between;
}

.badge input {
  margin-right: 6px;
}

.badge.active {
  border-color: #22c55e;
  background: #dcfce7;
}

.badge:hover {
  box-shadow: 0 0 0 1px #d1d5db;
}

.badge .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #6b7280;
}

.badge .status-dot.active {
  background: #16a34a;
}

.rule-header-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.level-row {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.apply-level-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.actions-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

input[type="text"],
input[type="number"],
select,
input[type="date"],
input[type="time"] {
  width: 100%;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  font-size: 14px;
  box-sizing: border-box;
}

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

.table th,
.table td {
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 8px;
}

.table th {
  text-align: left;
  font-weight: 600;
  color: #4b5563;
}

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

.chip {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  background: #e5e7eb;
}

.chip.green {
  background: #dcfce7;
  color: #166534;
}

.chip.red {
  background: #fee2e2;
  color: #b91c1c;
}

/* Tasks */

.task-card {
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  padding: 12px 12px 10px;
  margin-bottom: 10px;
  background: #f9fafb;
}

.task-header {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) repeat(3, minmax(0, 1fr)) auto;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}

.task-header-title {
  font-weight: 600;
  font-size: 14px;
}

.task-conditions-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.condition-row {
  display: grid;
  grid-template-columns: 80px 140px 110px 1fr 60px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.condition-row select,
.condition-row input {
  font-size: 13px;
  padding: 6px 8px;
}

/* Builder as popup */

.builder {
  position: relative;
  z-index: 1;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 10;
  display: none;
}

.overlay.active {
  display: block;
}

.builder.as-modal {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(1100px, 100% - 40px);
  max-height: calc(100% - 80px);
  overflow-y: auto;
  z-index: 20;
}

.account-select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selected-accounts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selected-accounts-pill {
  border-radius: 999px;
  padding: 2px 10px;
  background: #e5e7eb;
  font-size: 12px;
}

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
}

.modal-window {
  position: relative;
  background: white;
  border-radius: 16px;
  padding: 14px 16px 12px;
  width: min(700px, 100% - 40px);
  max-height: calc(100% - 80px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.35);
}

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

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.save-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.once-fields {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.hidden {
  display: none;
}
