:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #63707b;
  --line: #d9e0e6;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #027a48;
  --shadow: 0 10px 28px rgba(28, 39, 49, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 750;
  padding: 0 16px;
  cursor: pointer;
}

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

button.secondary-button,
.card-controls button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.danger,
.card-controls button.danger {
  border-color: #f3b8b2;
  color: var(--danger);
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

#app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2rem, 9vw, 3.5rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
}

main {
  display: grid;
  gap: 14px;
}

.toolbar,
.auth-panel,
.ai-panel,
.import-panel,
.manual-panel,
.inventory-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}


.toolbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
}

.summary {
  display: grid;
  gap: 4px;
}

.summary span,
.progress-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.summary strong {
  font-size: 2rem;
  line-height: 1;
}

.sync-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  padding: 8px 12px;
  white-space: nowrap;
}

.sync-pill[data-state="saved"] {
  border-color: #9ad5bc;
  color: var(--ok);
}

.sync-pill[data-state="syncing"] {
  border-color: #ffd599;
  color: var(--warn);
}

.sync-pill[data-state="error"] {
  border-color: #f3b8b2;
  color: var(--danger);
}

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

.ai-panel,
.import-panel,
.manual-panel,
.inventory-panel {
  display: grid;
  gap: 12px;
}

.history-panel {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.history-panel .section-heading {
  margin-bottom: 8px;
}

.compact-button {
  min-height: 36px;
  padding: 0 12px;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}

.history-entry {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.history-entry.assistant {
  border-color: #b8d8d4;
  background: #f4fbfa;
}

.history-entry div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-entry strong {
  color: var(--ink);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.history-entry time,
.history-empty {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.history-entry p {
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.ai-form,
.upload-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.file-picker {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--primary);
  border-radius: 8px;
  color: var(--primary);
  cursor: pointer;
}

#invoiceFile {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

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

.wide-field,
.item-form button {
  grid-column: 1 / -1;
}

.message {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.message[data-kind="success"] {
  color: var(--ok);
}

.message[data-kind="error"] {
  color: var(--danger);
}

.raw-text {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.raw-text pre {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
  padding: 12px;
  white-space: pre-wrap;
}

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

.preview-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 3px;
}

.filters button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.filters button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 28px 14px;
  text-align: center;
}

.inventory-list,
.brand-group,
.card-grid {
  display: grid;
  gap: 12px;
}

.brand-group {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.brand-group h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 900;
}

.brand-group h3 span {
  color: var(--muted);
  font-weight: 800;
}

.inventory-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-top div {
  display: grid;
  gap: 2px;
}

.brand-name {
  color: var(--ink);
  font-size: 1.18rem;
  font-weight: 950;
  line-height: 1.05;
  text-transform: uppercase;
}

.card-top span,
.card-note {
  color: var(--muted);
  font-size: 0.86rem;
}

.style-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid #b8d8d4;
  border-radius: 999px;
  background: #effaf8;
  color: #0b5f59;
  font-size: 0.8rem;
  font-weight: 850;
  padding: 4px 9px;
  white-space: nowrap;
}

dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.card-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (min-width: 680px) {
  #app {
    padding: 24px;
  }

  main {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar,
  .ai-panel,
  .import-panel,
  .inventory-panel {
    grid-column: 1 / -1;
  }

  .ai-form,
  .upload-row {
    grid-template-columns: 1fr auto;
  }

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

  .preview-row {
    grid-template-columns: 110px repeat(6, minmax(80px, 1fr)) auto;
    align-items: center;
  }
}

@media (min-width: 980px) {
  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
