:root {
  color-scheme: light;
  --ink: #17322a;
  --muted: #64756f;
  --line: #dfe9e4;
  --page: #f4f8f6;
  --surface: #ffffff;
  --surface-soft: #f7faf8;
  --accent: #16745e;
  --accent-dark: #0f5847;
  --accent-soft: #e6f5ef;
  --gold: #d39a2c;
  --warn: #a85b16;
  --danger: #b42318;
  --shadow: 0 12px 36px rgba(24, 63, 51, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% -10%, rgba(40, 164, 126, 0.14), transparent 32rem),
    linear-gradient(180deg, #f8fbf9 0%, var(--page) 48%, #eef5f1 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
  padding: 9px 13px;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

button:hover { border-color: var(--accent); transform: translateY(-1px); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(22, 116, 94, 0.18);
  outline-offset: 1px;
}

.shell { width: min(1540px, calc(100vw - 32px)); margin: 0 auto; padding: 26px 0 48px; }

.topbar, .panel-header, .tools-row, .item-main, .route-controls, .top-actions, .item-toolbar {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  border: 1px solid rgba(255,255,255,0.8);
  border-radius: 18px;
  background: linear-gradient(118deg, #123f34 0%, #16745e 72%, #23886d 100%);
  box-shadow: var(--shadow);
  color: white;
  padding: 22px 24px;
}

.brand-block { min-width: 0; }
.eyebrow, .section-kicker { margin: 0 0 4px; color: #88e2c5; font-size: 11px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.section-kicker { color: var(--accent); }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(25px, 3vw, 34px); line-height: 1.05; letter-spacing: -.025em; }
h2 { font-size: 18px; letter-spacing: -.01em; }
.subtitle { max-width: 680px; margin-top: 8px; color: rgba(255,255,255,.78); font-size: 14px; line-height: 1.45; }

.top-actions { flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.top-actions button { border-color: rgba(255,255,255,.28); background: rgba(255,255,255,.12); color: white; }
.top-actions button:hover { background: rgba(255,255,255,.2); }
.local-badge { display: inline-flex; align-items: center; gap: 7px; border: 1px solid rgba(255,255,255,.24); border-radius: 999px; background: rgba(0,0,0,.12); color: rgba(255,255,255,.88); font-size: 12px; font-weight: 750; padding: 8px 11px; }
.local-badge span { width: 8px; height: 8px; border-radius: 50%; background: #75e6a4; box-shadow: 0 0 0 4px rgba(117,230,164,.14); }

.mode-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 720px; margin: 0 0 16px; }
.mode-switch button { display: flex; align-items: center; gap: 11px; border-radius: 14px; background: rgba(255,255,255,.82); color: var(--muted); padding: 12px 14px; text-align: left; }
.mode-switch button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); box-shadow: 0 7px 20px rgba(24,63,51,.08); }
.mode-switch .mode-icon { display: grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border-radius: 10px; background: #edf2ef; color: var(--accent); font-size: 20px; }
.mode-switch button[aria-pressed="true"] .mode-icon { background: var(--accent); color: white; }
.mode-switch button > span:last-child { display: grid; gap: 2px; }
.mode-switch strong { color: var(--ink); font-size: 14px; }
.mode-switch small { font-size: 11px; font-weight: 600; }

.workspace, .messages { display: grid; gap: 16px; }
.workspace { grid-template-columns: minmax(360px, .8fr) minmax(660px, 1.45fr); align-items: start; margin-bottom: 16px; }
.workspace.is-direct-mode { grid-template-columns: 1fr; }
.workspace.is-direct-mode .photos-panel { display: none; }
.workspace.is-direct-mode .entry-panel .item-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.messages { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }

.panel { border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.96); box-shadow: var(--shadow); padding: 17px; }
.panel-header { justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.photos-panel { position: sticky; top: 14px; max-height: calc(100vh - 28px); overflow: auto; scrollbar-color: #a9c7bb transparent; }

input, textarea, select { border: 1px solid #d6e2dc; border-radius: 9px; background: #fff; color: var(--ink); padding: 9px 10px; }

.dropzone { display: grid; min-height: 118px; place-items: center; gap: 3px; border: 2px dashed #a9cbbf; border-radius: 13px; background: linear-gradient(180deg, #fbfefd, #f0f8f4); color: var(--accent-dark); text-align: center; cursor: pointer; padding: 18px; transition: background 140ms ease, border-color 140ms ease; }
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { display: none; }
.dropzone-icon { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: var(--accent); color: white; font-size: 24px; font-weight: 400; line-height: 1; }
.dropzone strong { font-size: 15px; }
.dropzone small { color: var(--muted); font-size: 12px; }

.analysis-status { margin-top: 10px; border-radius: 10px; background: var(--surface-soft); color: var(--muted); font-size: 12px; line-height: 1.45; padding: 10px 12px; }
.analysis-status.is-working { background: #edf5ff; color: #245ba6; }
.analysis-status.is-success { background: var(--accent-soft); color: var(--accent-dark); }
.analysis-status.is-error { background: #fef0ef; color: var(--danger); }

.photo-preview { display: grid; gap: 12px; margin-top: 12px; }
.photo-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #f3f5f4; }
.photo-card img { display: block; width: 100%; max-height: 560px; object-fit: contain; background: white; }
.photo-card span { display: block; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 700; padding: 7px 10px; }

.item-summary { border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; font-weight: 800; padding: 7px 10px; }
.tools-row { gap: 10px; margin-bottom: 11px; }
.tools-row label { display: grid; flex: 1; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.tools-row input { min-width: 0; }

.item-toolbar { justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.filter-tabs { display: inline-flex; align-items: center; gap: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); padding: 3px; }
.filter-tabs button { border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; padding: 7px 9px; }
.filter-tabs button[aria-pressed="true"] { background: white; color: var(--accent-dark); box-shadow: 0 2px 8px rgba(24,63,51,.1); }
.filter-tabs span { display: inline-grid; min-width: 19px; height: 19px; place-items: center; margin-left: 3px; border-radius: 999px; background: #e9efec; font-size: 10px; }
.item-toolbar input[type="search"] { width: min(290px, 42%); }

.category-tabs { display: flex; gap: 6px; margin: 0 0 11px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.category-tabs button { flex: 0 0 auto; border-radius: 999px; color: var(--muted); font-size: 11px; padding: 6px 11px; }
.category-tabs button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: white; }

.item-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.item-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; min-width: 0; border: 1px solid var(--line); border-radius: 11px; background: white; padding: 8px; transition: border-color 120ms ease, background 120ms ease; }
.item-row.has-quantity { border-color: #9bcdbb; background: #fbfefd; }
.item-row.is-unsure { border-color: #edc38f; background: #fffbf5; }
.item-row.is-hidden { display: none; }
.item-main { min-width: 0; gap: 8px; }
.quantity-stepper { display: grid; grid-template-columns: 32px 42px 32px; align-items: stretch; flex: 0 0 auto; border: 1px solid #cfe0d8; border-radius: 9px; background: white; overflow: hidden; }
.quantity-stepper button { min-width: 0; border: 0; border-radius: 0; background: var(--surface-soft); color: var(--accent-dark); font-size: 19px; line-height: 1; padding: 6px 2px; }
.quantity-stepper button:hover { background: var(--accent-soft); transform: none; }
.qty { width: 42px; min-width: 42px; border: 0; border-right: 1px solid #e4ece8; border-left: 1px solid #e4ece8; border-radius: 0; padding: 8px 3px; text-align: center; font-size: 15px; font-weight: 850; -moz-appearance: textfield; }
.qty::-webkit-inner-spin-button, .qty::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.item-name { display: grid; min-width: 0; gap: 2px; }
.item-name strong, .item-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-name strong { font-size: 13px; }
.item-name span { color: var(--muted); font-size: 10px; }
.item-name span b { color: var(--accent-dark); letter-spacing: .02em; }
.route-controls { gap: 5px; }
.route-controls select { width: 86px; min-width: 86px; padding: 7px 6px; font-size: 11px; }
.unsure-label { display: grid; place-items: center; color: var(--warn); font-size: 9px; font-weight: 850; line-height: 1; }
.unsure-label input { width: 17px; height: 17px; margin: 0 0 3px; padding: 0; }

.message-panel textarea, .notes-panel textarea { width: 100%; min-height: 310px; resize: vertical; line-height: 1.48; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.notes-panel textarea { min-height: 105px; }
.copy-btn { border-color: #9bcdbb; color: var(--accent-dark); }
.copy-btn.was-copied { border-color: var(--accent-dark); background: var(--accent); color: #fff; }

.mobile-review { display: none; }

body[data-mode="direct"] .unsure-label { display: none; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(320px, .8fr) minmax(520px, 1.2fr); }
  .item-list { grid-template-columns: 1fr; }
  .workspace.is-direct-mode .entry-panel .item-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .workspace, .messages { grid-template-columns: 1fr; }
  .photos-panel { position: static; max-height: none; }
  .photo-preview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-card img { max-height: 440px; }
  .item-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .shell { width: min(100% - 18px, 1540px); padding-top: 10px; }
  .topbar, .item-toolbar { align-items: stretch; flex-direction: column; }
  .topbar { padding: 18px; }
  .top-actions { justify-content: flex-start; }
  .local-badge { order: 2; }
  .mode-switch { grid-template-columns: 1fr 1fr; gap: 7px; }
  .mode-switch button { padding: 9px; }
  .mode-switch .mode-icon { display: none; }
  .mode-switch small { display: none; }
  .photo-preview, .item-list { grid-template-columns: 1fr; }
  .workspace.is-direct-mode .entry-panel .item-list { grid-template-columns: 1fr; }
  .item-toolbar input[type="search"] { width: 100%; }
  .filter-tabs { width: 100%; }
  .filter-tabs button { flex: 1; }
  body[data-mode="direct"] { padding-bottom: 72px; }
  body[data-mode="direct"] .mobile-review { display: flex; position: fixed; z-index: 10; right: 12px; bottom: 12px; left: 12px; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px; background: var(--accent-dark); box-shadow: 0 10px 28px rgba(15,88,71,.28); color: white; padding: 14px 18px; }
  .mobile-review span { display: grid; min-width: 23px; height: 23px; place-items: center; border-radius: 999px; background: white; color: var(--accent-dark); font-size: 11px; }
}

@media (max-width: 470px) {
  .tools-row, .item-row { grid-template-columns: 1fr; align-items: stretch; }
  .tools-row { flex-direction: column; }
  .route-controls { justify-content: space-between; }
  .route-controls select { flex: 1; width: auto; }
  .item-row { grid-template-columns: minmax(0, 1fr) auto; }
  .item-main { align-items: flex-start; }
  .item-name strong, .item-name span { white-space: normal; }
  .route-controls { align-self: stretch; flex-direction: column; justify-content: center; }
  .route-controls select { flex: 0 0 auto; width: 74px; min-width: 74px; }
  body[data-mode="direct"] .route-controls { display: none; }
}
