:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #16151f;
  --muted: #676575;
  --line: #dfddea;
  --purple: #63308f;
  --purple-strong: #4e2377;
  --teal: #087f8c;
  --green: #2e8b57;
  --amber: #a46705;
  --red: #b42318;
  --shadow: 0 18px 45px rgba(36, 24, 61, 0.09);
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #17131f;
  color: #fff;
  padding: 28px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand,
.status-panel {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #7a3db2;
  font-weight: 800;
}

.brand span,
.status-panel span,
.topbar p,
.panel-header p,
.summary-panel p {
  color: var(--muted);
  display: block;
}

.sidebar .brand span,
.sidebar .status-panel span {
  color: #bfb6ce;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
  margin: 34px 0;
}

.nav a {
  color: #d8d1e4;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.status-panel {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #2fd17c;
  box-shadow: 0 0 0 6px rgba(47, 209, 124, 0.12);
}

.main {
  padding: 32px;
  min-width: 0;
  display: grid;
  gap: 18px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--purple);
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  max-width: 820px;
  font-size: 34px;
  line-height: 1.12;
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 18px;
  margin-bottom: 6px;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  min-width: 0;
}

.input-panel,
.summary-panel,
.output-panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel,
.summary-panel,
.output-panel {
  padding: 22px;
  min-width: 0;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

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

.segmented {
  display: inline-flex;
  padding: 4px;
  background: #f0eef6;
  border-radius: 8px;
}

.segment {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}

.segment.active {
  background: #fff;
  color: var(--purple);
  box-shadow: 0 2px 8px rgba(35, 24, 54, 0.12);
}

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

#textForm {
  grid-template-columns: minmax(0, 1fr) 180px;
  align-items: end;
}

#textForm label,
#textForm textarea {
  grid-column: 1 / -1;
}

label {
  font-weight: 700;
}

textarea {
  width: 100%;
  max-width: 100%;
  min-height: 240px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  outline: none;
}

textarea:focus,
input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 4px rgba(99, 48, 143, 0.12);
}

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 220px;
  border: 1px dashed #a99abe;
  border-radius: 8px;
  background: #fbfaff;
  text-align: center;
  padding: 24px;
}

.dropzone span {
  color: var(--muted);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid #cce8d6;
  border-radius: 8px;
  background: #f2fbf5;
  color: var(--green);
  padding: 10px 12px;
  overflow-wrap: anywhere;
}

.file-status small {
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: var(--purple);
  color: #fff;
}

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

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

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

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 0;
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--purple);
  font-size: 30px;
  font-weight: 900;
}

.metric strong {
  color: var(--muted);
  font-size: 13px;
}

.wide {
  min-width: 0;
}

.story-list,
.quality-list {
  display: grid;
  gap: 14px;
}

.quality-list {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.module-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 360px);
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.story-card,
.quality-card,
.module-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.module-card {
  min-height: 150px;
}

.module-card p,
.quality-card p,
.story-card p {
  color: var(--muted);
}

.story-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #eee8f6;
  color: var(--purple);
}

.badge.green {
  background: #e9f6ef;
  color: var(--green);
}

.badge.amber {
  background: #fff5df;
  color: var(--amber);
}

.badge.red {
  background: #fdecec;
  color: var(--red);
}

.story-assets {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.mini-section {
  background: #faf9fd;
  border: 1px solid #ece7f3;
  border-radius: 8px;
  padding: 12px;
  min-width: 260px;
}

.mini-section strong {
  display: block;
  margin-bottom: 8px;
}

ul {
  margin: 0;
  padding-left: 18px;
}

li {
  margin: 5px 0;
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fbfbfd;
  overflow-wrap: anywhere;
}

.summary-block {
  display: grid;
  gap: 18px;
}

.summary-block > div:first-child {
  max-width: 900px;
}

.summary-block p {
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 420px;
  background: #17131f;
  color: #fff;
  padding: 14px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

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

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

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

  .topbar,
  .panel-header,
  .story-title {
    flex-direction: column;
  }

  #textForm {
    grid-template-columns: 1fr;
  }

  .story-assets {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 18px;
  }

  h1 {
    font-size: 26px;
  }

  .sidebar {
    padding: 22px 18px;
  }
}
