.domain-dashboard {
  padding: 24px;
  padding-top: 0;
  background: var(--bg-page);
  min-height: 100%;
  box-sizing: border-box;
  font-family: var(--app-font-family);
}

// ── Header ────────────────────────────────────────────────────────
.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;

  h2 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
  }
}

.dash-subtitle {
  font-size: 13px;
  color: var(--text-tertiary);
}

.btn-add-domain {
  background: var(--button-primary-bg-default);
  color: var(--button-primary-text-default);
  border: 1px solid var(--button-primary-border-default);
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;

  &:hover {
    background: var(--button-primary-bg-hover);
  }

  &:active {
    background: var(--button-primary-bg-active);
  }
}

// ── Body layout (list + chart side-by-side) ───────────────────────
.domain-body {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.domain-list-section {
  flex: 1;
  min-width: 0;
}

.domain-chart-section {
  width: 360px;
  flex-shrink: 0;

  @media (max-width: 1100px) {
    width: 300px;
  }
}

// ── Filters ───────────────────────────────────────────────────────
.dash-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.search-input {
  flex: 1 1 260px;
  max-width: 400px;
  padding: 8px 12px;
  border: 1px solid var(--field-border-default);
  border-radius: 6px;
  font-size: 13px;
  background: var(--field-bg-default);
  color: var(--field-text-default);
  outline: none;
  box-sizing: border-box;

  &::placeholder {
    color: var(--field-text-placeholder);
  }

  &:focus {
    border-color: var(--field-border-focus);
  }
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--field-border-default);
  border-radius: 6px;
  font-size: 13px;
  background: var(--field-bg-default);
  color: var(--field-text-default);
  outline: none;
  cursor: pointer;
  flex-shrink: 0;

  &:focus {
    border-color: var(--field-border-focus);
  }
}

// ── Table ─────────────────────────────────────────────────────────
.domain-table-wrap {
  background: var(--bg-surface);
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  min-height: 200px;
}

.domain-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;

  thead tr {
    border-bottom: 1px solid var(--table-border);
  }

  th {
    padding: 12px 14px;
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--table-text-header);
    background: var(--table-header-bg);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
  }

  tbody tr {
    border-bottom: 1px solid var(--table-border);
    transition: background 0.15s;

    &:last-child {
      border-bottom: none;
    }

    &:hover {
      background: var(--bg-hover);
    }

    &.row-custom {
      outline: 1px dashed var(--category-text-delta);
      outline-offset: -1px;
    }
  }

  td {
    padding: 11px 14px;
    vertical-align: middle;
    color: var(--table-text-body);
  }
}

.th-drag {
  width: 28px;
}

.td-drag {
  color: var(--text-disabled);
  font-size: 11px;
  letter-spacing: -1px;
  cursor: grab;
  user-select: none;
}

.td-code {
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.td-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  color: var(--text-primary);
  flex-wrap: nowrap;
  max-width: 220px;
  overflow: hidden;

  >span:not(.domain-dot) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }
}

.domain-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;

  &.dot-red {
    background: var(--status-error-text);
  }

  &.dot-green {
    background: var(--status-success-text);
  }

  &.dot-purple {
    background: var(--category-text-beta);
  }

  &.dot-blue {
    background: var(--category-text-alpha);
  }

  &.dot-orange {
    background: var(--category-text-delta);
  }

  &.dot-teal {
    background: var(--category-text-gamma);
  }
}

.custom-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(249, 115, 22, 0.12);
  color: var(--category-text-delta);
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.td-needs {
  font-weight: 700;
  font-size: 14px;
  color: var(--category-text-gamma);
}

.source-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;

  &.source-system {
    background: var(--category-bg-alpha);
    color: var(--category-text-alpha);
  }

  &.source-custom {
    background: rgba(249, 115, 22, 0.1);
    color: var(--category-text-delta);
  }
}

.status-badge {
  font-size: 12px;
  font-weight: 600;

  &.status-active {
    color: var(--status-success-text);
  }

  &.status-inactive {
    color: var(--state-disabled-text);
  }
}

.td-actions {
  white-space: nowrap;
  display: flex;
  gap: 8px;
  align-items: center;
}

.empty-state {
  text-align: center;
  padding: 40px 0;
  color: var(--text-disabled);
  font-size: 14px;
}

.table-footer {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--table-border);
}

// ── Domain Usage Summary ──────────────────────────────────────────
.usage-summary {
  background: var(--bg-surface);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.usage-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
}

.usage-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.usage-row {
  display: grid;
  grid-template-columns: 140px 1fr 36px;
  align-items: center;
  gap: 12px;
}

.usage-label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.usage-bar-wrap {
  background: var(--bg-page);
  border-radius: 4px;
  height: 18px;
  overflow: hidden;
}

.usage-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 4px;

  &.bar-red {
    background: var(--status-error-text);
  }

  &.bar-green {
    background: var(--status-success-text);
  }

  &.bar-orange {
    background: var(--category-text-delta);
  }

  &.bar-blue {
    background: var(--category-text-alpha);
  }

  &.bar-teal {
    background: var(--category-text-gamma);
  }

  &.bar-purple {
    background: var(--category-text-beta);
  }

  &.bar-yellow {
    background: var(--status-warning-text);
  }

  &.bar-pink {
    background: var(--status-info-text);
  }
}

.usage-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
}

// ── RTL ───────────────────────────────────────────────────────────
[dir="rtl"] {
  .dash-header {
    flex-direction: row-reverse;
  }

  .td-name {
    flex-direction: row-reverse;
    justify-content: flex-end;
  }
}

// ── Modal ──────────────────────────────────────────────
.modal {
  display: none;
  position: fixed;
  z-index: 999;
  padding-top: 60px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}

.modal-content-wrapper {
  display: flex;
  justify-content: center;
}

.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  border: 1px solid #888;
  width: 800px;
  min-height: 320px;
  border-radius: 8px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  box-sizing: border-box;
}

.titlecontainer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 21px;
  margin-bottom: 0;
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fefefe;
  border-bottom: 1px solid #e5e5e5;
}

.buttfilter {
  font-weight: 700;
  font-size: 18px;
  margin: 0;
  color: #333333;
}

.icons {
  display: flex;
  gap: 24px;
  align-items: center;
}

.action {
  display: flex;
  gap: 16px;
  align-items: center;
}

.save {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 40px;
  border-radius: 8px;
  background: #1EAE8A;
  cursor: pointer;
  transition: all 0.3s ease;

  mat-icon {
    color: #fff;
    font-size: 20px;
    width: 22px;
    height: 22px;
  }

  &:hover {
    background: #189b7a;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(30, 174, 138, 0.3);
  }
}

.delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #E63946;
  background: transparent;
  cursor: pointer;
  transition: all 0.3s ease;

  mat-icon {
    color: #E63946;
    font-size: 20px;
    width: 20px;
    height: 20px;
  }

  &:hover {
    background: rgba(230, 57, 70, 0.1);
    transform: translateY(-1px);
  }
}

.add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #818181;
  background: transparent;
  cursor: pointer;
  transition: all 0.3s ease;

  mat-icon {
    color: #818181;
    font-size: 20px;
    width: 20px;
    height: 20px;
  }

  &:hover {
    background: rgba(129, 129, 129, 0.1);
    border-color: #666;
    transform: translateY(-1px);
  }
}

.closeicon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.3s ease;

  mat-icon {
    width: 27px;
    height: 27px;
    font-size: 27px;
    color: #666666;
  }

  &:hover {
    transform: scale(1.1);

    mat-icon {
      color: #333333;
    }
  }
}

.modal-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px 21px 21px;
}

.modal-form>div {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.modal-form .adjacentField {
  width: 100%;
  margin-right: 0;
  display: block;
}

.btn-edit,
.btn-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;

  &:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  }
}

.btn-edit {
  color: var(--action-primary-default);
  border-color: var(--action-primary-disabled);

  &:hover {
    background: var(--bg-selected);
    border-color: var(--action-primary-default);
  }
}

.btn-delete {
  color: var(--status-error-text);
  border-color: var(--status-error-border);

  &:hover {
    background: var(--status-error-bg);
    border-color: var(--status-error-text);
  }
}