:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef2f5;
  color: #17212b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8fafb 0%, #eef2f5 48%, #e8edf1 100%);
}

.app {
  width: min(820px, 100vw);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
}

.toolbar,
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar {
  position: relative;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 28px rgba(32, 48, 64, 0.08);
}

button {
  min-height: 38px;
  border: 1px solid #cbd7df;
  border-radius: 7px;
  padding: 0 12px;
  background: #ffffff;
  color: #17212b;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

button:active {
  transform: scale(0.98);
}

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

button.primary {
  border-color: #117c7a;
  background: #117c7a;
  color: white;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 8px;
  font-size: 14px;
  color: #344454;
  white-space: nowrap;
}

.settings-panel {
  min-height: 38px;
}

.settings-panel summary {
  display: flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid #cbd7df;
  border-radius: 7px;
  padding: 0 12px;
  background: #ffffff;
  color: #17212b;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.settings-panel summary::-webkit-details-marker {
  display: none;
}

.settings-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.settings-grid button {
  min-width: 88px;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: #117c7a;
}

.status {
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 0 4px;
  color: #526170;
  font-size: 14px;
}

.progress {
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 12px;
}

.progress-title {
  margin-bottom: 4px;
  color: #526170;
  font-size: 12px;
  font-weight: 700;
}

.progress-body {
  color: #17212b;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat {
  overflow: auto;
  min-height: 0;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.message {
  max-width: min(78%, 620px);
  margin: 0 0 10px;
  padding: 11px 13px;
  border-radius: 8px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 12px rgba(25, 39, 52, 0.07);
}

.message.user {
  margin-left: auto;
  background: #d7f4ee;
  border: 1px solid #b9e6dc;
}

.message.assistant {
  margin-right: auto;
  background: #ffffff;
  border: 1px solid #dce5ec;
}

.message.error {
  max-width: 100%;
  color: #8a1f11;
  background: #fff0ec;
  border: 1px solid #f2c7bc;
}

.composer {
  align-items: stretch;
  padding: 10px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -8px 26px rgba(32, 48, 64, 0.08);
}

textarea {
  flex: 1;
  min-height: 68px;
  resize: none;
  border: 1px solid #cbd7df;
  border-radius: 8px;
  padding: 11px 12px;
  background: #f9fbfc;
  color: #17212b;
  font: inherit;
  line-height: 1.45;
  outline: none;
}

textarea:focus {
  border-color: #117c7a;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(17, 124, 122, 0.14);
}

.composer button {
  min-width: 92px;
  border-color: #2563a9;
  background: #2563a9;
  color: white;
}

@media (max-width: 640px) {
  .app {
    width: 100vw;
    padding: 8px;
    gap: 8px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .toolbar button,
  .settings-panel summary {
    min-height: 34px;
    padding: 0 6px;
    font-size: 13px;
  }

  .settings-panel {
    min-height: 34px;
  }

  .settings-panel {
    grid-column: span 1;
  }

  .settings-grid {
    position: absolute;
    left: 8px;
    right: 8px;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 7px;
    padding: 8px;
    border: 1px solid #d9e1e8;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 12px 28px rgba(32, 48, 64, 0.16);
  }

  .settings-grid button {
    min-width: 0;
  }

  .toggle {
    min-height: 34px;
    justify-content: center;
    padding: 0 4px;
    font-size: 13px;
  }

  .status {
    min-height: 30px;
    font-size: 13px;
  }

  .progress {
    padding: 8px 10px;
  }

  .progress-body {
    max-height: 150px;
    overflow: auto;
    font-size: 13px;
  }

  .composer {
    display: grid;
    grid-template-columns: 1fr 78px;
    gap: 8px;
    padding: 8px;
  }

  textarea {
    width: 100%;
    min-height: 58px;
    max-height: 126px;
    font-size: 17px;
  }

  .composer button {
    width: auto;
    min-width: 0;
    min-height: 58px;
    font-size: 16px;
  }

  .chat {
    padding: 12px;
  }

  .message {
    max-width: 88%;
    font-size: 15px;
  }
}
