:root {
  --charcoal: #2b2926;
  --charcoal-light: #3c3a36;
  --bg: #faf5ec;
  --panel-bg: #ffffff;
  --teal: #1f7a72;
  --teal-dark: #155f59;
  --teal-tint: #e4f2f0;
  --text: #2c2925;
  --text-muted: #736c62;
  --border: #e8ddc9;
  --error: #b3362c;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  color: inherit;
}

a {
  color: var(--teal-dark);
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

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

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--charcoal);
  color: #f2ede2;
  padding: 24px 16px;
}

.brand {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.08em;
  margin-bottom: 24px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: #d8d2c4;
  cursor: pointer;
}

.nav-item--active {
  background: var(--charcoal-light);
  color: #ffffff;
  font-weight: 600;
}

.nav-item--disabled {
  color: #948d80;
  cursor: default;
}

.nav-item--disabled:hover {
  background: rgba(255, 255, 255, 0.04);
}

.nav-icon {
  font-size: 14px;
}

.nav-note {
  margin: 0 0 6px 12px;
  font-size: 12px;
  color: #b8b0a0;
}

/* Main */
.main {
  flex: 1;
  padding: 24px 32px 48px;
  min-width: 0;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.app-header__desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.stepper {
  display: flex;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stepper a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--teal-tint);
  color: var(--teal-dark);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.restore-banner {
  background: var(--teal-tint);
  color: var(--teal-dark);
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: 14px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 20px;
  align-items: start;
}

.content-left, .content-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

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

.panel__header h2 {
  margin: 0;
  font-size: 16px;
}

.section-hint {
  margin: -4px 0 12px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Form fields */
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.field--wide {
  grid-column: 1 / -1;
}

.field input[type="text"],
.field input[type="number"],
.field textarea {
  font-weight: normal;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fffdf9;
}

.field input:focus, .field textarea:focus {
  border-color: var(--teal);
}

.field__error {
  min-height: 16px;
  font-size: 12px;
  font-weight: normal;
  color: var(--error);
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  margin-right: 14px;
}

fieldset.field {
  border: none;
  padding: 0;
  margin: 0;
}

/* Buttons */
.btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--teal-dark);
}

.btn--ghost {
  background: transparent;
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.dropzone p {
  margin: 4px 0;
}

.dropzone__hint {
  font-size: 12px;
}

.dropzone.dragover {
  border-color: var(--teal);
  background: var(--teal-tint);
}

.dropzone.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.upload-notice {
  background: #fff6e8;
  border: 1px solid #e7cf9b;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Image list */
.image-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.image-item__thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}

.image-item__info {
  flex: 1;
  min-width: 0;
}

.image-item__name {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-item__meta {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.image-item__role {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.image-item__controls {
  display: flex;
  gap: 4px;
}

.image-item__controls button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.image-item__controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 13px;
}

/* Preview */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
}

.preview-item {
  margin: 0;
}

.preview-item img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.preview-item figcaption {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stale-banner {
  background: #fff1e0;
  border: 1px solid #e6b675;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: #8a5a1c;
}

.error-banner {
  background: #fdecea;
  border: 1px solid #e6a29a;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--error);
}

/* Status grid */
.status-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0 0 4px;
  font-size: 13px;
}

.status-grid dt {
  color: var(--text-muted);
}

.status-grid dd {
  margin: 0;
  font-weight: 600;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.badge--muted {
  background: #eee6d6;
  color: #8a7c5c;
}

/* History */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  max-height: 220px;
  overflow-y: auto;
}

/* Responsive */
@media (max-width: 800px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    padding: 12px 16px;
  }

  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .main {
    padding: 16px;
  }

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

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