:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --soft: #eef4f7;
  --paper: #ffffff;
  --line: #d9e3ea;
  --blue: #2563eb;
  --green: #0f766e;
  --amber: #b7791f;
  --red: #b42318;
  --charcoal: #263241;
  --shadow: 0 14px 34px rgba(38, 50, 65, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f8fb;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell,
.caption-shell {
  min-height: 100vh;
}

.loading-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
}

.loading-mark {
  width: 42px;
  height: 42px;
  border: 4px solid var(--line);
  border-top-color: var(--green);
  border-radius: 999px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.caption-shell {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 18px;
  color: #f8fafc;
  background: #111827;
}

.brand-lockup {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  font-weight: 900;
}

.brand-lockup strong,
.brand-lockup span,
.sidebar-stat span,
.sidebar-stat strong,
.project-button strong,
.project-button span {
  display: block;
}

.brand-lockup span,
.sidebar-stat span,
.project-button span {
  color: #aeb9c8;
}

.brand-lockup strong {
  font-size: 16px;
}

.brand-lockup span {
  margin-top: 2px;
  font-size: 12px;
}

.sidebar-label {
  margin: 22px 0 9px;
  color: #aeb9c8;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.project-list {
  display: grid;
  gap: 8px;
}

.project-button {
  width: 100%;
  text-align: left;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  padding: 11px;
}

.project-button strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.project-button span {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.35;
}

.project-button.active {
  color: #111827;
  background: #f8fafc;
  border-color: #f8fafc;
}

.project-button.active span {
  color: #526173;
}

.sidebar-stat {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-stat span {
  font-size: 12px;
}

.sidebar-stat strong {
  font-size: 24px;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 7px;
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 12px;
  font-size: 19px;
}

.subcopy,
.panel-header p {
  color: var(--muted);
  line-height: 1.55;
}

.subcopy {
  max-width: 820px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  padding: 9px 13px;
  font-weight: 850;
  text-decoration: none;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button.primary {
  color: #ffffff;
  background: var(--blue);
  border-color: var(--blue);
}

.button.success {
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

.button.warning {
  color: #ffffff;
  background: var(--amber);
  border-color: var(--amber);
}

.button.full-width {
  width: 100%;
}

.button.compact {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 12px;
}

.button.danger {
  color: #ffffff;
  background: var(--red);
  border-color: var(--red);
}

.icon-box {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 12px;
  font-weight: 900;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.metric.active {
  border-color: rgba(15, 118, 110, 0.38);
  background: #f1fbf8;
}

.metric span,
.metric small {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.metric small {
  margin-top: 6px;
  color: var(--green);
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.75fr);
  gap: 16px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 16px;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px 0;
}

.panel-header p {
  margin-bottom: 0;
}

.panel-body {
  padding: 18px;
}

.drop-zone {
  min-height: 180px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 2px dashed #b8c8d6;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fbfd;
  text-align: center;
}

.drop-zone strong {
  color: var(--ink);
  font-size: 19px;
  overflow-wrap: anywhere;
}

.upload-actions,
.editor-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.caption-table {
  display: grid;
  gap: 8px;
}

.caption-row {
  display: grid;
  grid-template-columns: 92px 92px minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: stretch;
}

.caption-row.heading {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.caption-row input,
.caption-row textarea,
.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfdff;
  padding: 10px 11px;
}

.caption-row textarea {
  min-height: 54px;
  resize: vertical;
  line-height: 1.4;
}

.icon-button {
  width: 42px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--red);
  background: #fff7f6;
  font-weight: 900;
}

.style-grid,
.export-grid,
.system-list {
  display: grid;
  gap: 12px;
}

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

.field {
  display: grid;
  gap: 7px;
}

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

.caption-preview.full {
  grid-column: 1 / -1;
}

.field span {
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 900;
}

.field small {
  color: var(--muted);
  line-height: 1.35;
}

.color-control {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.color-control input[type="color"] {
  width: 44px;
  min-width: 44px;
  height: 42px;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
}

.color-hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-transform: lowercase;
}

.caption-preview {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #eef2f7, #d8e1ea);
  display: grid;
  place-items: center;
  padding: 14px;
}

.caption-preview span {
  border: 1px solid transparent;
  border-radius: 6px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  font-size: 18px;
  line-height: 1.25;
  padding: 8px 12px;
  text-align: center;
}

.file-field input {
  padding: 9px;
}

.checkbox-field {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
}

.checkbox-field input {
  width: 18px;
}

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

.export-progress {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.system-list div,
.history-item,
.notice,
.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
  padding: 12px;
}

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

.history-item {
  display: grid;
  gap: 10px;
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.system-list strong,
.system-list span {
  display: block;
}

.system-list span {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

.notice {
  margin-bottom: 12px;
  color: #744b0b;
  background: #fff8e8;
}

.empty {
  color: var(--muted);
  border-style: dashed;
}

.empty.dark {
  color: #aeb9c8;
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.status.green {
  color: #075443;
  background: #dff8ef;
}

.status.amber {
  color: #744b0b;
  background: #fff1d6;
}

.status.red {
  color: #8a1f1f;
  background: #ffe1e1;
}

.status.blue {
  color: #123f7a;
  background: #dcecff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 36px));
  border-radius: 8px;
  color: #ffffff;
  background: var(--charcoal);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1120px) {
  .caption-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .project-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panel-header {
    display: grid;
  }

  .top-actions {
    justify-content: stretch;
  }

  .button {
    width: 100%;
  }

  .status-grid,
  .project-list,
  .style-grid {
    grid-template-columns: 1fr;
  }

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

  .caption-row.heading {
    display: none;
  }

  .icon-button {
    width: 100%;
  }

  h1 {
    font-size: 26px;
  }
}
