:root {
  color-scheme: light;
  --bg: #f6f5ef;
  --panel: #ffffff;
  --ink: #25231f;
  --muted: #706c61;
  --line: #d9d5ca;
  --line-strong: #b9b2a3;
  --accent: #0f766e;
  --accent-strong: #0a5c56;
  --accent-soft: #d7f2ec;
  --danger: #b42318;
  --warning: #a15c00;
  --canvas: #20201d;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 0 12px;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

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

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
}

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfaf6;
}

.brand-block {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-block h1 {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.15;
}

.brand-block span,
.file-block span,
.metric-grid span,
.warning,
.message {
  color: var(--muted);
  font-size: 13px;
}

.search-input {
  width: calc(100% - 24px);
  min-height: 36px;
  margin: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--ink);
}

.image-list {
  min-height: 0;
  overflow: auto;
  padding: 0 8px 12px;
}

.image-row {
  display: grid;
  width: 100%;
  min-height: 46px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.image-row:hover,
.image-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.image-state {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.image-row.exported .image-state {
  border-color: #79b69d;
  color: #146c43;
}

.main-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 14px;
}

.file-block {
  min-width: 0;
}

.file-block strong {
  display: block;
  overflow: hidden;
  max-width: min(58vw, 780px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar,
.box-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.workspace {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) 330px;
}

.image-area {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--canvas);
  padding: 16px;
}

.image-frame {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.image-frame img {
  display: block;
  max-width: calc(100vw - 682px);
  max-height: calc(100vh - 98px);
  width: auto;
  height: auto;
  object-fit: contain;
}

.image-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.image-frame.is-empty {
  display: none;
}

.empty-state {
  color: #f2efe8;
  font-size: 18px;
  font-weight: 700;
}

.empty-state.hidden {
  display: none;
}

.inspector {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  border-left: 1px solid var(--line);
  background: #fbfaf6;
  padding: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
}

.metric-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.box-actions button {
  flex: 1 1 72px;
}

.box-list {
  display: flex;
  min-height: 40px;
  max-height: 180px;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}

.box-list button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}

.box-list button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.box-list span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.preview-label {
  font-size: 13px;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px;
  color: var(--ink);
  background: #ffffff;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.45;
}

.warning {
  min-height: 18px;
  color: var(--warning);
}

.message {
  min-height: 20px;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: #146c43;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 250px minmax(0, 1fr);
  }

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

  .inspector {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .image-frame img {
    max-width: calc(100vw - 282px);
    max-height: 58vh;
  }
}

@media (max-width: 760px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 280px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .toolbar {
    width: 100%;
  }

  .toolbar button {
    flex: 1 1 88px;
  }

  .file-block strong {
    max-width: 92vw;
  }

  .image-frame img {
    max-width: calc(100vw - 32px);
    max-height: 56vh;
  }
}