:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f0f4f7;
  --border: #d9e0e7;
  --text: #17202a;
  --muted: #657484;
  --primary: #167364;
  --primary-strong: #10584c;
  --accent: #b45029;
  --danger: #b42318;
  --warning: #925f00;
  --success: #247a42;
  --focus: #2f80ed;
  --shadow: 0 8px 22px rgba(18, 28, 38, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button,
.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  color: #ffffff;
  background: var(--primary);
  cursor: pointer;
  font-weight: 700;
  touch-action: manipulation;
}

button:hover,
.button:hover {
  background: var(--primary-strong);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

button.secondary {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}

button.secondary:hover {
  background: var(--surface-soft);
}

button.danger {
  background: var(--danger);
}

a {
  color: var(--primary);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 76px;
  padding: 16px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid var(--border);
  background: rgba(246, 247, 249, 0.94);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.status-line {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px) 40px;
}

.split {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 18px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-body {
  padding: 18px;
}

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

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

label small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.35;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--text);
  background: #ffffff;
  font-size: 16px;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.setup-note {
  border: 1px solid #b9d7cf;
  border-radius: 8px;
  color: #24594f;
  background: #eef8f5;
  font-weight: 700;
  margin-bottom: 18px;
  padding: 14px 16px;
}

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

.danger-text {
  color: var(--danger);
  font-weight: 700;
}

.compact {
  font-size: 0.88rem;
}

.hidden {
  display: none !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 2px 9px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.sent {
  color: #ffffff;
  background: var(--success);
}

.badge.accepted {
  color: #ffffff;
  background: var(--warning);
}

.badge.failed {
  color: #ffffff;
  background: var(--danger);
}

.app-list,
.history-list {
  display: grid;
  gap: 10px;
}

.row-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.preview {
  min-height: 320px;
  max-height: 620px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  color: #dbeafe;
  background: #16202b;
  font-size: 0.83rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: var(--surface-soft);
}

.empty-action {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.connection-error {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 30px 18px;
  border: 1px solid #f2b8b5;
  border-radius: 8px;
  padding: 16px 18px;
  color: #7a1d17;
  background: #fff3f1;
}

.connection-error p {
  margin: 6px 0 0;
  color: #7a1d17;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 13px 15px;
  color: #ffffff;
  background: #17202a;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

.applications-page {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.applications-title {
  background: #0799bd;
  color: #ffffff;
  font-size: 2.4rem;
  font-weight: 300;
  line-height: 1;
  padding: 24px 18px 30px;
  text-align: center;
}

.applications-toolbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: flex-end;
  padding: 20px 30px 12px;
}

.applications-count {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
  margin-right: auto;
}

.applications-filter {
  background: #f2f2f2;
  border: 1px solid #e5e5e5;
  border-radius: 7px;
  color: #555555;
  font-size: 1.4rem;
  min-height: 58px;
  width: min(560px, 100%);
}

.applications-list {
  padding: 0 30px 30px;
}

.application-row {
  align-items: center;
  border-top: 1px solid #dddddd;
  display: grid;
  gap: 18px;
  grid-template-columns: 114px minmax(240px, 1fr) auto;
  min-height: 132px;
  padding: 18px 0;
}

.application-row:last-child {
  border-bottom: 1px solid #dddddd;
}

.application-icon {
  border-radius: 4px;
  height: 114px;
  object-fit: cover;
  width: 114px;
}

.application-icon.placeholder {
  align-items: center;
  background: #0799bd;
  color: #ffffff;
  display: flex;
  font-size: 2.5rem;
  justify-content: center;
  text-transform: uppercase;
}

.application-main h2 {
  color: #333333;
  font-size: 2.15rem;
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 14px;
}

.status-dot {
  background: #49ad48;
  border-radius: 4px;
  display: inline-block;
  height: 20px;
  width: 20px;
}

.application-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.recipe-results {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.selected-recipe {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.image-preview {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-soft);
}

.image-preview img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
}

.image-preview-broken img {
  display: none;
}

.image-preview-message {
  padding: 16px;
  color: var(--danger);
  background: #fff3f1;
  font-size: 0.84rem;
  font-weight: 800;
}

.candidate-box {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.bulk-list {
  display: grid;
  gap: 10px;
}

.bulk-app-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 190px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.bulk-check {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  font-size: 0.9rem;
}

.bulk-check input {
  flex: 0 0 auto;
  width: 22px;
  min-height: 22px;
}

.bulk-check span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.bulk-check strong,
.bulk-check small {
  overflow-wrap: anywhere;
}

.bulk-check small {
  color: var(--muted);
  font-weight: 700;
}

.bulk-module-select {
  min-height: 38px;
}

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

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

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 12px 14px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .status-line {
    font-size: 0.78rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .panel-body {
    padding: 14px;
  }

  .actions {
    justify-content: stretch;
    margin-top: 10px;
  }

  .actions button,
  .topbar-actions button {
    flex: 1 1 145px;
    min-height: 46px;
  }

  .applications-toolbar {
    align-items: stretch;
    flex-direction: column;
    justify-content: stretch;
    padding: 16px;
  }

  .applications-count {
    margin-right: 0;
  }

  .applications-title {
    font-size: clamp(1.7rem, 9vw, 2.1rem);
    padding: 20px 12px 22px;
  }

  .applications-filter {
    font-size: 1.05rem;
    min-height: 50px;
  }

  .applications-list {
    padding: 0 16px 20px;
  }

  .connection-error {
    align-items: stretch;
    flex-direction: column;
    margin: 0 16px 16px;
  }

  .empty-action {
    align-items: stretch;
    flex-direction: column;
  }

  .selected-recipe {
    align-items: flex-start;
    flex-direction: column;
  }

  .application-row {
    gap: 12px;
    grid-template-columns: 74px minmax(0, 1fr);
    min-height: 0;
    padding: 14px 0;
  }

  .application-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .application-actions button,
  .row-actions button {
    min-height: 42px;
  }

  .application-icon {
    height: 74px;
    width: 74px;
  }

  .application-main h2 {
    font-size: 1.28rem;
    line-height: 1.2;
    margin-bottom: 8px;
  }

  .row-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .selected-recipe {
    align-items: stretch;
  }

  .preview {
    max-height: 360px;
    min-height: 220px;
  }

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

@media (max-width: 520px) {
  .app-shell {
    padding: 10px 8px 28px;
  }

  .panel,
  .applications-page {
    border-radius: 7px;
  }

  .applications-toolbar {
    padding: 14px 12px 10px;
  }

  .applications-list {
    padding: 0 12px 16px;
  }

  .application-row {
    grid-template-columns: 58px minmax(0, 1fr);
    padding: 12px 0;
  }

  .application-icon {
    height: 58px;
    width: 58px;
  }

  .application-icon.placeholder {
    font-size: 1.6rem;
  }

  .application-main h2 {
    font-size: 1.08rem;
  }

  .row-meta {
    gap: 6px 10px;
    font-size: 0.78rem;
  }

  .badge {
    min-height: 24px;
    font-size: 0.72rem;
  }

  .actions,
  .application-actions,
  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions .badge {
    justify-content: center;
  }

  button,
  .button {
    width: 100%;
  }

  textarea {
    min-height: 116px;
  }
}
