:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #697586;
  --line: #d8dee8;
  --accent: rgb(145, 35, 30);
  --accent-dark: rgb(145, 35, 30);
  --danger: #b42318;
  --field: #fbfcfe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px;
}

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

.topbar h1,
.topbar p,
h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 26px;
  line-height: 1.15;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.selection-panel,
.result-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.result-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 18px;
}

.section-head,
.row-header,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.items-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.calculation-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 0.8fr) minmax(180px, 1fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.calculation-row:has(.multi-select[open]),
.calculation-row:has(.blogger-options:not([hidden])),
.calculation-row.has-open-blogger-options,
.calculation-row.has-open-select,
.modifiers-section:has(.multi-select[open]) {
  z-index: 20;
}

.row-header {
  grid-column: 1 / -1;
}

.row-title {
  font-size: 14px;
}

.field {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
}

input,
select {
  min-height: 42px;
  padding: 0 10px;
}

textarea {
  min-height: 360px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

.remove-button {
  min-height: 34px;
  border-color: #f0b8b2;
  background: #ffffff;
  color: var(--danger);
}

.remove-button:hover {
  background: #fff1f0;
}

.modifiers-section {
  margin-top: 18px;
}

.add-blogger-button {
  width: 100%;
  margin-top: 18px;
}

.option-list {
  position: absolute;
  z-index: 30;
  top: 100%;
  right: 0;
  left: 0;
  display: grid;
  gap: 8px;
  max-height: min(320px, 45vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 6px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  background: var(--field);
  padding: 10px;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.14);
}

.blogger-field {
  position: relative;
}

.blogger-options {
  top: calc(100% - 1px);
  gap: 0;
  padding: 6px;
  max-height: min(260px, 35vh);
}

.blogger-options[hidden] {
  display: none;
}

.blogger-option,
.blogger-empty-option {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 8px;
  color: var(--text);
  text-align: left;
}

.blogger-option:hover,
.blogger-option:focus {
  background: #eaf1ef;
  color: var(--text);
}

.blogger-empty-option {
  color: var(--muted);
}

.multi-select {
  position: relative;
  min-width: 0;
}

.multi-select summary {
  display: block;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  padding: 10px 34px 10px 10px;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-select summary::-webkit-details-marker {
  display: none;
}

.multi-select summary::after {
  position: absolute;
  top: 11px;
  right: 12px;
  content: "▾";
  color: var(--muted);
}

.multi-select[open] summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.multi-select[open] summary::after {
  content: "▴";
}

.multi-select.muted summary {
  color: var(--muted);
}

.checkbox-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--text);
  line-height: 1.3;
  cursor: pointer;
}

.checkbox-option input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.checkbox-option span {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.format-group {
  display: grid;
  gap: 8px;
}

.format-group + .format-group {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.format-group strong {
  font-size: 13px;
}

.modifiers-list {
  margin-top: 10px;
}

.actions {
  justify-content: flex-start;
  margin-top: 18px;
}

.preview-output {
  min-height: 180px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--field);
  line-height: 1.45;
  white-space: pre-wrap;
}

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

.error {
  color: var(--danger);
}

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .workspace {
    display: grid;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: static;
  }

  .calculation-row {
    grid-template-columns: 1fr;
  }

  .option-list {
    max-height: 38vh;
  }

  .section-head,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }
}
