:root {
  --bg: #15110D;
  --surface: #211b15;
  --surface-2: #2b241d;
  --text: #f2ece4;
  --muted: #a89e92;
  --accent: #CC785C;
  --accent-dim: #7d4b38;
  --danger: #d9534f;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

#app {
  min-height: 100dvh;
  background: var(--bg);
}

.screen {
  min-height: 100dvh;
  background: var(--bg);
}

.overview-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar,
.chat-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(33, 27, 21, 0.98);
  border-bottom: 1px solid rgba(242, 236, 228, 0.08);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
}

.app-title {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip,
.back-button,
.retry-button,
.load-more {
  min-height: 44px;
  border: 1px solid rgba(242, 236, 228, 0.1);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.chip:active,
.chat-card:active,
.back-button:active,
.retry-button:active,
.load-more:active {
  transform: scale(0.985);
  filter: brightness(1.12);
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px calc(env(safe-area-inset-bottom) + 16px);
  -webkit-overflow-scrolling: touch;
}

.section {
  margin-bottom: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.chat-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.chat-card {
  display: block;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid rgba(242, 236, 228, 0.07);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.card-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}

.markers {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  line-height: 1.2;
}

.pill {
  background: var(--accent);
  color: #1c120d;
  font-weight: 800;
}

.badge {
  border: 1px solid rgba(168, 158, 146, 0.22);
  color: var(--muted);
}

.meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.meta-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.phone {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.time {
  flex: 0 0 auto;
  color: var(--muted);
}

.preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty,
.loading {
  padding: 16px 8px;
  color: var(--muted);
}

.error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(217, 83, 79, 0.45);
  border-radius: 12px;
  background: rgba(217, 83, 79, 0.12);
  color: var(--text);
}

.retry-button {
  min-height: 36px;
  border-color: rgba(217, 83, 79, 0.45);
  padding: 6px 11px;
}

.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.chat-header {
  flex: 0 0 auto;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-button {
  flex: 0 0 auto;
  border-radius: 12px;
  background: transparent;
}

.chat-title-wrap {
  min-width: 0;
  flex: 1;
}

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.chat-subtitle {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.view-tabs {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.view-tab {
  flex: 1;
  min-height: 38px;
  border: 1px solid rgba(242, 236, 228, 0.12);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 9px;
  padding: 7px 10px;
  cursor: pointer;
}

.view-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 12px);
  -webkit-overflow-scrolling: touch;
}

.context {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px calc(env(safe-area-inset-bottom) + 12px);
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ctx-block {
  background: var(--surface);
  border: 1px solid rgba(242, 236, 228, 0.07);
  border-radius: 12px;
  padding: 10px 12px;
}

.ctx-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.ctx-empty {
  color: var(--muted);
  font-size: 14px;
}

.ctx-row {
  padding: 6px 0;
  border-top: 1px solid rgba(242, 236, 228, 0.06);
}

.ctx-row:first-child {
  border-top: 0;
}

.ctx-supplies {
  white-space: pre-wrap;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

.kind-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid rgba(168, 158, 146, 0.3);
  color: var(--muted);
}

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

.stock-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.stock-input {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(242, 236, 228, 0.12);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
}

[data-stock-search] {
  min-height: 44px;
  border-radius: 9px;
  padding: 9px 13px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(242, 236, 228, 0.12);
  cursor: pointer;
}

.stock-item {
  padding: 7px 0;
  border-top: 1px solid rgba(242, 236, 228, 0.06);
}

.stock-name {
  font-weight: 600;
  white-space: normal;
}

.load-wrap {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  padding: 6px 0 10px;
  background: linear-gradient(var(--bg) 72%, rgba(21, 17, 13, 0));
}

.load-more {
  min-height: 40px;
  border-radius: 12px;
  color: var(--muted);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  display: flex;
}

.msg.in {
  justify-content: flex-start;
}

.msg.out {
  justify-content: flex-end;
}

.bubble {
  max-width: min(82vw, 560px);
  padding: 8px 10px 6px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid rgba(242, 236, 228, 0.06);
}

.msg.out .bubble {
  background: rgba(204, 120, 92, 0.26);
  border-color: rgba(204, 120, 92, 0.28);
}

.bubble-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.bubble-time {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-top: 1px solid rgba(242, 236, 228, 0.08);
  padding: 10px 10px calc(env(safe-area-inset-bottom) + 10px);
}

.composer-input {
  width: 100%;
  box-sizing: border-box;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(242, 236, 228, 0.12);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
}

.composer-label {
  color: var(--muted);
  font-size: 12px;
}

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

.composer-actions button {
  min-height: 44px;
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
}

.composer-actions [data-send] {
  border: 0;
  background: var(--accent);
  color: #1c120d;
  font-weight: 700;
}

.composer-actions [data-send]:disabled {
  opacity: 0.5;
  cursor: default;
}

.composer-actions [data-ai],
.composer-actions [data-reject] {
  background: var(--surface-2);
  border: 1px solid rgba(242, 236, 228, 0.12);
  color: var(--text);
}

.composer-actions [data-reject] {
  color: var(--danger);
}

.composer-error {
  color: var(--danger);
  font-size: 13px;
}

.composer-status {
  color: var(--muted);
  padding: 6px 2px;
}

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

.topbar-head .app-title {
  margin: 0;
}

.reports-btn {
  min-height: 40px;
  border: 1px solid rgba(242, 236, 228, 0.12);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.reports-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
}

.reports-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(33, 27, 21, 0.98);
  border-bottom: 1px solid rgba(242, 236, 228, 0.08);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
}

.reports-header .title {
  font-weight: 800;
  font-size: 18px;
}

.reports-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px calc(env(safe-area-inset-bottom) + 16px);
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.report-block {
  background: var(--surface);
  border: 1px solid rgba(242, 236, 228, 0.07);
  border-radius: 12px;
  padding: 12px;
}

.report-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.report-pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}

.days-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.day-chip {
  min-height: 36px;
  border: 1px solid rgba(242, 236, 228, 0.12);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

.day-chip.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

@media (min-width: 720px) {
  .content,
  .reports-content,
  .messages,
  .context,
  .topbar,
  .composer,
  .chat-header {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
}
