:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #102a4c;
  --muted: #71839f;
  --line: #dbe4f0;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --orange: #f97316;
  --violet: #7c3aed;
  --shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a {
  color: var(--blue);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  align-items: center;
  background: #101b31;
  color: #fff;
  display: flex;
  height: 58px;
  justify-content: space-between;
  padding: 0 28px;
}

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

.brand strong {
  font-size: 18px;
}

.icon-button {
  align-items: center;
  background: var(--blue);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.version {
  background: rgba(255,255,255,0.12);
  border-radius: 6px;
  color: #d6e2f3;
  font-size: 12px;
  padding: 5px 10px;
}

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

.user-chip span {
  align-items: center;
  background: var(--blue);
  border-radius: 50%;
  display: inline-flex;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.topbar-link {
  background: transparent;
  border: 0;
  color: #d6e2f3;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 190px);
  place-items: center;
}

.login-panel {
  display: grid;
  gap: 14px;
  max-width: 420px;
  width: min(420px, 100%);
}

.login-panel h1 {
  margin: 0;
}

.login-panel label {
  color: var(--muted);
  display: grid;
  font-weight: 700;
  gap: 7px;
}

.login-panel input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
}

.admin-login-details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.admin-login-details summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.admin-login-details form {
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

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

.login-hint {
  color: var(--muted);
  display: grid;
  gap: 6px;
  padding-top: 6px;
}

.login-hint code {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
}

.tabs {
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 6px;
  height: 52px;
  padding: 0 28px;
}

.tabs a {
  align-items: center;
  border-bottom: 2px solid transparent;
  color: #8292ad;
  display: flex;
  font-weight: 700;
  gap: 8px;
  padding: 0 16px;
}

.tabs a.active {
  border-bottom-color: var(--blue);
  color: var(--blue);
}

.shell {
  margin: 0 auto;
  max-width: min(1680px, calc(100vw - 56px));
  padding: 28px;
}

.app-state {
  color: var(--muted);
}

.stats-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 22px;
}

.stat-card,
.panel,
.list-card,
.supplier-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  align-items: center;
  display: flex;
  gap: 16px;
  min-height: 98px;
  padding: 20px;
}

.stat-icon {
  align-items: center;
  background: var(--blue-soft);
  border-radius: 8px;
  color: var(--blue);
  display: inline-flex;
  font-size: 22px;
  height: 46px;
  justify-content: center;
  width: 46px;
}

.stat-value {
  display: block;
  font-size: 30px;
  font-weight: 800;
}

.stat-label,
.muted {
  color: var(--muted);
}

.search-row {
  display: flex;
  gap: 10px;
  margin: 18px 0 24px;
}

.search-input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  color: var(--text);
  min-height: 42px;
  padding: 0 14px;
  width: 100%;
}

.button,
.chip,
.back-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  min-height: 38px;
  padding: 0 14px;
}

.panel-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.row-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

.button.danger {
  border-color: var(--red);
  color: var(--red);
}

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

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

.chip-stack {
  display: grid;
  gap: 8px;
}

.section-title {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: 24px 0 12px;
}

.section-title h1,
.section-title h2 {
  margin: 0;
}

.section-title h1 {
  font-size: 25px;
}

.section-title h2 {
  font-size: 19px;
}

.breadcrumb {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.breadcrumb a {
  font-weight: 700;
}

.category-grid,
.supplier-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.list-card {
  overflow: hidden;
}

.list-head {
  align-items: center;
  color: #fff;
  display: flex;
  font-weight: 800;
  justify-content: space-between;
  min-height: 52px;
  padding: 0 18px;
}

.list-head.blue { background: var(--blue); }
.list-head.violet { background: var(--violet); }
.list-head.green { background: var(--green); }
.list-head.orange { background: var(--orange); }

.count-pill {
  background: rgba(255,255,255,0.22);
  border-radius: 7px;
  padding: 4px 8px;
}

.list-body {
  display: grid;
  gap: 2px;
  padding: 12px;
}

.row-link {
  align-items: center;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 10px;
}

.row-link:hover {
  background: var(--surface-soft);
}

.row-link small {
  background: var(--surface-soft);
  border-radius: 6px;
  color: var(--muted);
  padding: 4px 8px;
}

.service-block-title {
  align-items: center;
  border-bottom: 2px solid #cfe0f7;
  color: var(--text);
  display: flex;
  font-size: 15px;
  font-weight: 800;
  gap: 12px;
  justify-content: space-between;
  margin: 24px 0 10px;
  min-height: 38px;
  padding: 0 2px 8px;
  text-transform: uppercase;
}

.service-block-title small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
}

.block-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.mini-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  height: 28px;
  justify-content: center;
  min-width: 28px;
}

.mini-button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.mini-button.danger:hover {
  border-color: var(--red);
  color: var(--red);
}

.service-block-title.blue { border-bottom-color: #bfdbfe; }
.service-block-title.violet { border-bottom-color: #ddd6fe; }
.service-block-title.green { border-bottom-color: #bbf7d0; }
.service-block-title.orange { border-bottom-color: #fed7aa; }

.service-block-list {
  box-shadow: none;
}

.supplier-group-title {
  margin-top: 26px;
}

.supplier-block {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.compact-title {
  margin: 12px 0 6px;
}

.supplier-service-panel {
  box-shadow: none;
}

.supplier-service-panel.inactive-link {
  opacity: 0.72;
}

.service-panel-header {
  padding: 14px 16px;
}

.service-panel-header h2 {
  font-size: 17px;
}

.service-link {
  border-left: 4px solid var(--blue);
  margin: 0;
}

.editable-service {
  cursor: default;
}

.editable-service a {
  color: var(--text);
  font-weight: 700;
}

.service-edit-controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.service-edit-controls select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  min-height: 34px;
  padding: 0 8px;
}

.editor-note {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #9a3412;
  font-weight: 700;
  margin-bottom: 14px;
  padding: 12px 14px;
}

.editor-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1fr) minmax(420px, 1.7fr);
}

.editor-column {
  align-self: start;
  box-shadow: none;
  min-height: 220px;
  padding: 12px;
}

.editor-column-wide {
  min-height: 520px;
}

.editor-column-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: -12px -12px 8px;
  min-height: 58px;
  padding: 12px;
}

.editor-column-head h2 {
  font-size: 17px;
  margin: 0;
}

.editor-row {
  align-items: center;
  border-radius: 6px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.editor-row > a {
  color: var(--text);
  display: grid;
  flex: 1;
  gap: 3px;
  min-height: 46px;
  padding: 8px 10px;
}

.editor-row small {
  color: var(--muted);
}

.editor-row.active,
.editor-row:hover {
  background: var(--surface-soft);
}

.editor-row.active {
  box-shadow: inset 3px 0 0 var(--blue);
}

.editor-block {
  padding: 0 10px 10px;
}

.editor-service-list {
  display: grid;
  gap: 2px;
}

.empty-state.compact {
  border: 0;
  border-radius: 0;
  padding: 16px;
  text-align: left;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 50;
}

.modal-panel {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  max-height: calc(100vh - 48px);
  max-width: 720px;
  overflow: auto;
  width: min(720px, 100%);
}

.modal-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 18px 20px;
}

.modal-header h2 {
  font-size: 20px;
  margin: 0;
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 8px;
}

.inline-actions {
  justify-content: flex-start;
  padding-top: 0;
}

.entity-form {
  display: grid;
  gap: 14px;
}

.backup-settings-form {
  gap: 14px;
}

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

.entity-form label {
  color: var(--muted);
  display: grid;
  font-weight: 700;
  gap: 7px;
}

.entity-form input,
.entity-form textarea,
.entity-form select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
}

.entity-form textarea {
  min-height: 88px;
  resize: vertical;
}

.entity-form select[size] {
  min-height: 240px;
}

.checkbox-line {
  align-items: center;
  display: flex !important;
  gap: 8px !important;
}

.checkbox-line input {
  width: auto;
}

.checkbox-fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
}

.checkbox-fieldset legend {
  color: var(--muted);
  font-weight: 700;
  padding: 0 4px;
}

.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.field-editor {
  display: grid;
  gap: 10px;
}

.field-editor-head {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-weight: 700;
  justify-content: space-between;
}

.condition-field-list {
  display: grid;
  gap: 8px;
}

.condition-field-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 1fr) 120px 92px 92px 88px 32px;
}

.condition-field-row input,
.condition-field-row select {
  min-height: 38px;
}

.mini-check {
  align-items: center !important;
  color: var(--muted);
  display: flex !important;
  font-size: 12px;
  gap: 5px !important;
  white-space: nowrap;
}

.mini-check input {
  width: auto;
}

.service-block-title.green + .service-block-list .service-link {
  border-left-color: var(--green);
}

.service-block-title.orange + .service-block-list .service-link {
  border-left-color: var(--orange);
}

.service-block-title.violet + .service-block-list .service-link {
  border-left-color: var(--violet);
}

.supplier-card {
  min-height: 158px;
  padding: 18px;
}

.supplier-card h3 {
  margin: 0 0 16px;
}

.supplier-meta {
  border-bottom: 1px solid #edf2f7;
  color: var(--muted);
  display: grid;
  gap: 8px;
  min-height: 56px;
  padding-bottom: 14px;
}

.supplier-footer {
  color: #5c78ad;
  margin-top: 14px;
}

.badge {
  border-radius: 7px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 9px;
}

.badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.badge.no {
  background: var(--red-soft);
  color: var(--red);
}

.badge.empty {
  background: #fff7ed;
  color: #c2410c;
}

.panel {
  overflow-x: auto;
  overflow-y: hidden;
}

.panel-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 20px 24px;
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
}

.conditions-table {
  border-collapse: collapse;
  min-width: 100%;
  table-layout: fixed;
  width: 100%;
}

.conditions-table th,
.conditions-table td {
  border-bottom: 1px solid #e9eef5;
  padding: 14px 16px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.conditions-table th:first-child,
.conditions-table td:first-child {
  width: 13%;
}

.conditions-table th {
  background: var(--surface-soft);
  color: #8292ad;
  font-size: 12px;
  text-transform: uppercase;
}

.conditions-table tr:hover td {
  background: #fbfdff;
}

.conditions-table .actions-column {
  background: var(--surface);
  box-shadow: -8px 0 14px rgba(15, 23, 42, 0.06);
  position: sticky;
  right: 0;
  width: 112px;
  z-index: 2;
}

.conditions-table th.actions-column {
  background: var(--surface-soft);
  z-index: 3;
}

.conditions-table tr:hover td.actions-column {
  background: #fbfdff;
}

.wide-text {
  max-width: 360px;
  white-space: pre-line;
}

.cost-text {
  font-weight: 700;
  max-width: 260px;
  white-space: pre-line;
}

.details,
.text-button {
  background: transparent;
  border: 0;
  color: var(--blue);
  cursor: pointer;
  display: inline-block;
  font-weight: 700;
  margin-top: 8px;
  padding: 0;
}

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

.changes-table th:nth-child(1),
.changes-table td:nth-child(1) {
  width: 120px;
}

.changes-table th:nth-child(2),
.changes-table td:nth-child(2) {
  width: 150px;
}

.changes-table th:nth-child(3),
.changes-table td:nth-child(3),
.changes-table th:nth-child(4),
.changes-table td:nth-child(4) {
  width: 130px;
}

.change-diff-table {
  margin-top: 14px;
}

.change-diff-table td {
  vertical-align: top;
}

.condition-card-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  white-space: pre-line;
}

.condition-card-item strong {
  display: block;
  margin-bottom: 5px;
}

.condition-card-item span {
  color: #52698d;
}

.result-group {
  margin-bottom: 22px;
}

.result-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  margin-bottom: 8px;
  padding: 14px 16px;
}

.result-item mark {
  background: #fef3c7;
  border-radius: 3px;
  padding: 0 2px;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

@media (max-width: 980px) {
  .stats-grid,
  .category-grid,
  .supplier-grid,
  .editor-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-column-wide {
    grid-column: 1 / -1;
  }

  .conditions-table {
    min-width: 860px;
    table-layout: auto;
  }

  .panel {
    overflow-x: auto;
  }
}

@media (max-width: 640px) {
  .topbar,
  .tabs {
    padding-left: 14px;
    padding-right: 14px;
  }

  .tabs {
    overflow-x: auto;
  }

  .shell {
    padding: 16px;
  }

  .stats-grid,
  .category-grid,
  .supplier-grid,
  .condition-card-grid,
  .editor-layout,
  .condition-field-row {
    grid-template-columns: 1fr;
  }

  .editor-column-wide {
    grid-column: auto;
  }
}
