:root {
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #f5f7fb;
  color: #1a2130;
}

.layout {
  min-height: 100vh;
  display: flex;
}

.left-nav {
  width: 220px;
  flex: 0 0 220px;
  background: #101828;
  color: #e5e7eb;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.left-nav__brand {
  color: #f9fafb;
  font-size: 14px;
  letter-spacing: .3px;
  margin-bottom: 4px;
  padding: 0 10px 10px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.2);
}

.left-nav a {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: #cbd5e1;
  border-radius: 8px;
}

.left-nav a:hover {
  color: #f8fafc;
  background: rgba(241, 245, 249, 0.08);
}

.left-nav a.active {
  color: #111827;
  background: #e2e8f0;
  font-weight: 700;
}

.content {
  flex: 1;
  display: grid;
  gap: 16px;
  max-width: none;
  margin: 0;
  padding: 20px 24px;
}

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
}

.card h1, .card h2 {
  margin-top: 0;
}

.form {
  display: grid;
  gap: 12px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid-3 {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.status-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 12px;
}

.status-grid div {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.status-grid span {
  color: #667085;
  font-size: 12px;
}

.status-grid strong {
  color: #1a2130;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.key-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.key-select-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.key-detail {
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

input, textarea, select, button {
  border: 1px solid #d4dceb;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

button {
  border: none;
  background: #2c5db8;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  min-width: 140px;
}

.secondary-button {
  background: #eef2fd;
  color: #2155ab;
  border: 1px solid #c8d5f2;
}

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

.reference-panel,
.mask-panel {
  display: grid;
  gap: 12px;
  border: 1px dashed #b8c6dc;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.reference-panel.dragover {
  border-color: #2c5db8;
  background: #eef4ff;
}

.reference-panel__header,
.reference-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.reference-panel__header > div:first-child {
  display: grid;
  gap: 4px;
}

.reference-actions button {
  min-width: 96px;
}

.reference-list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}

.reference-item {
  display: grid;
  gap: 8px;
  border: 1px solid #dbe4f0;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.reference-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #edf2f7;
}

.reference-item button {
  min-width: 0;
  padding: 8px;
}

#mask-canvas {
  width: min(100%, 512px);
  aspect-ratio: 1;
  border: 1px solid #d4dceb;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.status,
.muted {
  font-size: 13px;
}

.status {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f6f8fd;
}

.status.error { color: #9f1d3f; background: #fff1f3; }
.status.success { color: #16583b; background: #effcf3; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-button {
  min-width: 0;
  padding: 8px 12px;
  background: #eef2fd;
  color: #2155ab;
  border: 1px solid #c8d5f2;
}

.filter-button.active {
  background: #2c5db8;
  color: #fff;
}

.task-item {
  border: 1px solid #e3e8f2;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fafcff;
}

.task-item h3 {
  margin: 0 0 8px;
}

.task-meta {
  color: #3d4b62;
  font-size: 12px;
  margin-bottom: 8px;
}

.task-meta.success {
  color: #16583b;
  font-weight: 700;
}

.task-gallery {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  margin-bottom: 10px;
}

.thumb-button {
  min-width: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  color: #1a2130;
  background: #fff;
  border: 1px solid #dbe4f0;
  border-radius: 8px;
  overflow: hidden;
}

.thumb-button img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #edf2f7;
}

.thumb-button span {
  padding: 0 8px 8px;
  font-size: 12px;
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.task-actions button {
  min-width: 96px;
}

.task-links {
  display: grid;
  gap: 8px;
}

.task-links a {
  color: #2155ab;
  text-decoration: none;
}

.task-error {
  color: #9f1d3f;
  font-size: 12px;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.84);
  padding: 24px;
}

.preview-modal img {
  max-width: min(100%, 1080px);
  max-height: 86vh;
  object-fit: contain;
}

#preview-close {
  position: fixed;
  top: 16px;
  right: 16px;
  min-width: 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  color: #111827;
  font-size: 28px;
  line-height: 1;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2fd;
  margin-right: 6px;
  font-size: 11px;
}

.muted {
  color: #667085;
}

@media (max-width: 820px) {
  .layout {
    display: block;
  }

  .left-nav {
    width: auto;
    flex-direction: row;
    overflow-x: auto;
  }

  .left-nav__brand {
    display: none;
  }

  .left-nav a {
    white-space: nowrap;
  }

  .content {
    padding: 16px;
  }

  .key-select-row {
    grid-template-columns: 1fr;
  }
}
