:root {
  --page: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #fbfcfd;
  --line: #d8dee7;
  --line-soft: #e8edf3;
  --ink: #101725;
  --muted: #5e6b7c;
  --navy: #0c2747;
  --navy-2: #071a2f;
  --blue: #17406f;
  --green: #2f8b48;
  --green-soft: #e7f4ea;
  --yellow: #9d6c12;
  --yellow-soft: #fff3cf;
  --red: #c73d32;
  --red-soft: #fde8e6;
  --shadow: 0 12px 32px rgba(16, 23, 37, 0.06);
  --radius: 6px;
  --font-ui: "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 82px;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 20;
  transform: translateY(-140%);
  border-radius: 4px;
  background: #ffffff;
  color: var(--navy);
  padding: 10px 12px;
  font-weight: 800;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.skip-link:focus {
  transform: translateY(0);
  outline: 3px solid rgba(47, 139, 72, 0.35);
}

.app-header {
  height: 64px;
  background: linear-gradient(90deg, var(--navy-2), #0b2139);
  color: #ffffff;
  display: grid;
  grid-template-columns: 44px auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 2px 12px rgba(7, 26, 47, 0.28);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  display: grid;
  align-content: center;
  gap: 5px;
}

.icon-button span {
  display: block;
  width: 21px;
  height: 2px;
  background: #ffffff;
  border-radius: 2px;
}

.brand {
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 250px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 4px;
  background: #ffffff;
  color: var(--navy);
  font-weight: 900;
}

.brand strong {
  font-size: 19px;
  letter-spacing: 0;
}

.project-select {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b9c7d7;
}

.project-select span {
  font-size: 12px;
}

.project-select select {
  min-width: 190px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
  padding: 0 12px;
}

.header-status {
  display: flex;
  align-items: center;
  justify-content: end;
  height: 100%;
}

.status-item,
.logout-button {
  height: 100%;
  min-width: 126px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-weight: 700;
}

.logout-form {
  height: 100%;
  margin: 0;
}

.logout-button {
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  background: transparent;
}

.status-dot,
.good,
.wait {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(47, 139, 72, 0.18);
}

.wait {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(157, 108, 18, 0.17);
}

.drive-mark {
  width: 20px;
  height: 18px;
  background: conic-gradient(from 230deg, #2c7df0 0 34%, #f4c340 0 66%, #31a853 0);
  clip-path: polygon(50% 0, 100% 92%, 0 92%);
}

.paper-icon {
  width: 17px;
  height: 21px;
  border: 2px solid #ffffff;
  border-radius: 2px;
  position: relative;
}

.paper-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 6px;
  height: 2px;
  background: #ffffff;
  box-shadow: 0 5px 0 #ffffff;
}

.app-frame {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 104px);
  min-width: 0;
  max-width: 100vw;
}

.app-frame > * {
  min-width: 0;
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 16px 10px;
  max-width: 100vw;
  min-width: 0;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-list a,
.quick-actions a,
.sidebar-footer button {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 43px;
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
  padding: 0 12px;
  border: 1px solid transparent;
  background: transparent;
}

.nav-list a span,
.quick-actions a span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid #9aa6b5;
  border-radius: 4px;
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
}

.nav-list a.is-active,
.nav-list a:hover,
.quick-actions a:hover {
  background: #f1f5fa;
  border-color: #dce5f0;
  color: var(--navy);
}

.nav-list a.is-active {
  border-right: 3px solid var(--blue);
}

.quick-actions {
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}

.quick-actions h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.quick-actions a {
  min-height: 36px;
  border: 1px solid var(--line);
  margin-top: 8px;
}

.quick-actions a:first-of-type span {
  background: var(--navy);
  color: #ffffff;
  border-color: var(--navy);
  font-size: 18px;
  line-height: 1;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

.sidebar-footer button {
  width: 100%;
}

.dashboard {
  padding: 16px;
  min-width: 0;
}

#dashboard,
#episode,
#episodes,
#references,
#pipeline,
#playbook,
#drive {
  scroll-margin-top: 82px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.02fr 1.38fr 0.96fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
  padding: 16px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

h1,
h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  font-size: 19px;
}

p {
  margin: 0;
  color: var(--muted);
}

.panel-note {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.panel-title span,
.panel-title a,
.panel-title button,
.drive-panel button,
.references-panel button {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: var(--navy);
  font-weight: 700;
  font-size: 12px;
  min-height: 32px;
  padding: 0 10px;
  text-decoration: none;
}

.start-panel {
  grid-row: span 2;
}

.episode-form {
  display: grid;
  grid-template-columns: 1fr 0.62fr;
  gap: 12px;
}

.episode-form label,
.cast-field {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.episode-form input,
.episode-form select,
.episode-form textarea,
.reference-tools select,
.reference-tools input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 10px;
}

.episode-form textarea {
  min-height: 72px;
  padding: 9px 10px;
  resize: vertical;
}

.episode-form input:focus,
.episode-form select:focus,
.episode-form textarea:focus,
.reference-tools select:focus,
.reference-tools input:focus {
  outline: 3px solid rgba(23, 64, 111, 0.18);
  border-color: var(--blue);
}

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

.cast-field {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
}

.cast-field legend {
  grid-column: 1 / -1;
  padding: 0 4px;
}

.cast-field label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  color: var(--ink);
}

.cast-field input {
  width: auto;
  min-height: auto;
  accent-color: var(--green);
}

.primary-button {
  border: 0;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--blue), var(--navy));
  color: #ffffff;
  min-height: 44px;
  font-weight: 800;
}

.primary-button:hover,
.logout-button:hover {
  filter: brightness(1.06);
}

.result-box {
  display: block;
  margin-top: 12px;
  color: var(--green);
  font-weight: 700;
  min-height: 20px;
}

.result-box.is-error {
  color: var(--red);
}

.pipeline-panel {
  grid-column: span 1;
}

.pipeline-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(62px, 1fr));
  gap: 8px;
  align-items: start;
}

.pipeline-row article {
  position: relative;
  text-align: center;
}

.pipeline-row article:not(:last-child)::after {
  content: ">";
  position: absolute;
  top: 25px;
  right: -7px;
  color: var(--muted);
  font-size: 18px;
}

.pipeline-row span {
  width: 50px;
  height: 50px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 25%, #2c5b91, var(--navy));
  color: #ffffff;
  font-size: 18px;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 8px 18px rgba(12, 39, 71, 0.18);
}

.pipeline-row article:nth-child(2) span {
  background: radial-gradient(circle at 35% 25%, #65a86f, #2c7a43);
}

.pipeline-row strong,
.pipeline-row small {
  display: block;
}

.pipeline-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.check-list div {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
}

.check-list em {
  color: var(--green);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.gates-panel {
  grid-column: 2 / 3;
}

.playbook-panel {
  grid-column: 3 / 4;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--ink);
  background: #f7f9fb;
  font-weight: 800;
}

td {
  color: var(--ink);
}

td:nth-child(2),
td:nth-child(4) {
  color: var(--muted);
}

.status-badge,
.reference-card span,
.episode-item em {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  min-height: 22px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.status-badge.approved,
.reference-card span,
.episode-item em {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.waiting {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.references-panel {
  grid-column: span 1;
}

.reference-tools {
  display: grid;
  grid-template-columns: 0.75fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(88px, 1fr));
  gap: 8px;
}

.reference-card {
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
  background: #ffffff;
}

.reference-card img {
  width: 100%;
  aspect-ratio: 1.22 / 1;
  object-fit: cover;
  display: block;
  background: #eef2f5;
}

.reference-card div {
  padding: 7px;
}

.reference-card strong,
.reference-card small {
  display: block;
  overflow-wrap: anywhere;
}

.reference-card strong {
  font-size: 12px;
  line-height: 1.2;
}

.reference-card small {
  margin: 3px 0 6px;
  color: var(--muted);
  font-size: 11px;
}

.episodes-panel,
.drive-panel {
  grid-column: span 1;
}

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

.episode-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  border-top: 1px solid var(--line-soft);
}

.episode-item span {
  color: var(--muted);
  font-weight: 800;
}

.episode-item strong {
  overflow-wrap: anywhere;
}

.empty-state {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--line);
  color: var(--muted);
  border-radius: 4px;
}

.drive-path {
  color: var(--muted);
  margin-bottom: 12px;
}

.module-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.module-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
}

.module-card span {
  color: var(--red);
  font-weight: 900;
  font-size: 12px;
}

.module-card strong {
  display: block;
  margin-bottom: 3px;
}

.module-card p {
  font-size: 11px;
  line-height: 1.35;
}

.bottom-bar {
  min-height: 40px;
  display: grid;
  grid-template-columns: 220px 1fr 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
}

.bottom-bar span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bottom-bar i {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--green);
}

.login-shell {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(12, 39, 71, 0.96), rgba(7, 26, 47, 0.94)),
    var(--navy);
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-page {
  width: min(100%, 420px);
}

.login-card {
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  padding: 26px;
}

.login-mark {
  margin-bottom: 16px;
  border-color: var(--line);
  background: var(--navy);
  color: #ffffff;
}

.login-card h1 {
  font-size: 26px;
  margin-bottom: 8px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 800;
}

.login-form input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 12px;
  font-size: 16px;
}

.login-form input:focus {
  outline: 3px solid rgba(23, 64, 111, 0.18);
  border-color: var(--blue);
}

.login-error-message {
  display: none;
  border: 1px solid var(--red-soft);
  border-radius: 4px;
  background: var(--red-soft);
  color: var(--red);
  padding: 10px;
  font-weight: 700;
}

.login-error .login-error-message {
  display: block;
}

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

  .start-panel,
  .pipeline-panel,
  .check-panel,
  .gates-panel,
  .playbook-panel,
  .references-panel,
  .episodes-panel,
  .drive-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .pipeline-panel,
  .references-panel,
  .gates-panel {
    grid-column: 1 / -1;
  }

  .header-status .status-item:nth-child(2),
  .header-status .status-item:nth-child(3) {
    display: none;
  }
}

@media (max-width: 920px) {
  .app-header {
    grid-template-columns: 36px 1fr auto;
  }

  .project-select {
    display: none;
  }

  .app-frame {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: block;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
    width: 100%;
    max-width: 100%;
  }

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

  .quick-actions,
  .sidebar-footer {
    display: none;
  }

  .dashboard-grid,
  .episode-form,
  .bottom-bar {
    grid-template-columns: 1fr;
  }

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

  .pipeline-row article::after {
    display: none;
  }

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

  .module-list {
    grid-template-columns: 1fr;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 15px;
  }

  .app-header {
    grid-template-columns: 36px minmax(0, 1fr) auto;
    height: auto;
    min-height: 62px;
    padding: 10px;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

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

  .header-status .status-item {
    display: none;
  }

  .header-status {
    display: flex;
    min-width: auto;
  }

  .logout-form,
  .logout-button {
    height: 40px;
  }

  .logout-button {
    min-width: auto;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 4px;
    padding: 0 10px;
    font-size: 13px;
  }

  .dashboard {
    padding: 10px;
  }

  .sidebar {
    padding: 10px;
  }

  .nav-list a {
    min-height: 40px;
  }

  .panel {
    padding: 14px;
  }

  .episode-form label,
  .cast-field {
    font-size: 13px;
  }

  .episode-form input,
  .episode-form select,
  .episode-form textarea,
  .reference-tools select,
  .reference-tools input {
    min-height: 46px;
    font-size: 16px;
  }

  .episode-form textarea {
    min-height: 104px;
  }

  .primary-button {
    min-height: 50px;
    font-size: 16px;
  }

  .pipeline-row,
  .reference-tools,
  .reference-grid,
  .cast-field,
  .check-list div,
  .episode-item {
    grid-template-columns: 1fr;
  }

  .reference-card img {
    aspect-ratio: 4 / 3;
  }

  table {
    display: grid;
    white-space: normal;
    overflow-x: visible;
    font-size: 13px;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
  }

  tr {
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    margin-bottom: 8px;
    padding: 8px;
    background: #ffffff;
  }

  td {
    border: 0;
    padding: 5px 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
  }

  .bottom-bar {
    display: none;
  }

  .login-shell {
    padding: 14px;
  }

  .login-card {
    padding: 22px;
  }
}
