:root {
  --ink: #1e2329;
  --muted: #68707a;
  --line: #d8dde3;
  --panel: #ffffff;
  --bg: #eef2f5;
  --blue: #235f9c;
  --green: #2f7d67;
  --rose: #9b4058;
  --gold: #a9782f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover { border-color: var(--blue); }
button.primary { background: var(--blue); color: white; border-color: var(--blue); }

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

.sidebar {
  background: #17202a;
  color: white;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #e7eff7;
  color: #17202a;
  border-radius: 6px;
  font-weight: 800;
}

.brand span, .storage-mini small {
  display: block;
  color: #b7c1cc;
  font-size: 12px;
  margin-top: 3px;
}

nav {
  display: grid;
  gap: 8px;
}

.nav {
  text-align: left;
  background: transparent;
  color: #dfe7ef;
  border-color: rgba(255,255,255,.14);
}

.nav.active {
  background: #e7eff7;
  color: #17202a;
}

.storage-mini {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
  padding: 12px;
}

main {
  min-width: 0;
  padding: 20px;
}

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

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 6px; }
h2 { font-size: 18px; margin-bottom: 4px; }
h3 { font-size: 16px; margin-top: 24px; }
p { color: var(--muted); line-height: 1.7; }

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-row span {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.view { display: none; }
.view.active { display: block; }

.control-console {
  display: grid;
  grid-template-columns: 170px minmax(280px, 1fr) minmax(240px, 300px) minmax(220px, 280px);
  gap: 22px;
  align-items: stretch;
  margin-bottom: 18px;
  padding: 24px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(17,24,39,.18);
}

.console-hero {
  grid-column: 1 / -1;
  min-height: 300px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(17,24,39,0) 54%, rgba(17,24,39,.12) 100%),
    url("/media/ai-cm-control-console-banner.png");
  background-size: cover;
  background-position: center;
  box-shadow: 0 18px 45px rgba(0,0,0,.18);
}

.console-menu {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 22px;
  background: #1c2534;
  border-radius: 8px;
}

.console-menu button {
  justify-content: flex-start;
  gap: 10px;
  min-height: 44px;
  color: #dce4f2;
  background: transparent;
  border: 0;
}

.console-menu button::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #2fc8d4;
}

.console-menu button.active,
.console-menu button:hover {
  color: #fff;
  background: #f44786;
}

.console-preview {
  min-width: 0;
  display: grid;
  align-items: center;
}

.console-preview-screen {
  position: relative;
  display: flex;
  min-height: 410px;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 28px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  color: #17202a;
  background:
    linear-gradient(180deg, rgba(255,255,255,0) 45%, rgba(255,255,255,.86) 100%),
    url("/media/ai-cm-source-visual.png");
  background-size: cover;
  background-position: center;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}

.console-preview-note {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 48px);
  white-space: nowrap;
  background: rgba(23,32,42,.84);
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 800;
}

.console-preview-play {
  width: 58px;
  height: 58px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #f44786;
  color: #fff;
  box-shadow: 0 12px 32px rgba(244,71,134,.35);
}

.console-preview-screen strong {
  font-size: 22px;
}

.console-preview-screen small {
  color: #5d6675;
  font-weight: 800;
}

.console-preview-screen.is-playing .console-preview-play {
  background: #17202a;
}

.console-settings {
  display: grid;
  gap: 12px;
  align-content: start;
}

.console-settings h2,
.console-points h2 {
  margin: 0;
  font-size: 24px;
}

.console-settings label {
  position: relative;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 14px;
  background: #fff;
  color: #17202a;
  border-radius: 8px;
}

.console-settings label::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #f44786;
  grid-column: 1;
  grid-row: 1;
}

.console-settings label > span:not(.point-mark) {
  grid-column: 1 / 2;
  padding-left: 34px;
  color: #5d6675;
  font-size: 12px;
}

.console-settings select {
  grid-column: 2 / 3;
  width: auto;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #17202a;
  font-weight: 900;
  font-size: 17px;
}

.console-settings .primary {
  width: 100%;
  justify-content: center;
  background: #f44786;
}

.point-aware-button {
  display: grid;
  gap: 2px;
  min-height: 58px;
  text-align: center;
}

.point-aware-button small {
  font-size: 12px;
  font-weight: 800;
  opacity: .92;
}

.console-generated {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.console-generated-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.console-generated h2 {
  margin: 0;
  font-size: 24px;
}

.console-generated-head button {
  min-height: 36px;
  padding: 8px 12px;
  background: #fff;
  color: #17202a;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
}

.generated-list {
  display: grid;
  gap: 10px;
  max-height: 410px;
  overflow: auto;
}

.generated-list > p {
  margin: 0;
  padding: 18px;
  color: #dce4f2;
  background: #1c2534;
  border-radius: 8px;
}

.generated-chapter {
  display: grid;
  gap: 8px;
}

.generated-chapter h3 {
  margin: 8px 0 0;
  color: #dce4f2;
  font-size: 14px;
}

.generated-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  background: #fff;
  color: #17202a;
  border-radius: 8px;
}

.generated-thumb {
  width: 64px;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0) 35%, rgba(255,255,255,.78)),
    url("/media/ai-cm-source-visual.png");
  background-size: cover;
  background-position: center;
}

.generated-card strong,
.generated-card span {
  display: block;
}

.generated-check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 900;
}

.generated-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
}

.generated-check span {
  display: inline;
  color: #17202a;
  font-size: 12px;
}

.generated-card span {
  color: #5d6675;
  font-size: 12px;
  font-weight: 800;
}

.generated-card p {
  margin: 4px 0 8px;
  color: #5d6675;
  font-size: 12px;
}

.continuePrompt {
  min-height: 58px;
  margin: 0 0 8px;
  padding: 8px;
  font-size: 12px;
}

.generated-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.generated-actions button {
  min-height: 28px;
  padding: 5px 8px;
  font-size: 12px;
}

.console-points {
  grid-column: 1 / -1;
  display: grid;
  gap: 16px;
  margin-top: 4px;
  padding: 22px 24px;
  background: #fff;
  color: #17202a;
  border-radius: 8px;
}

.console-points h2,
.console-points p {
  text-align: center;
}

.console-points p {
  margin: 6px 0 0;
  color: #5d6675;
}

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

.point-estimate-card {
  display: grid;
  gap: 18px;
  justify-items: center;
  min-height: 112px;
  padding: 20px 16px;
  border: 1px solid #e6edf7;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(24,32,42,.06);
  text-align: center;
}

.point-estimate-card strong {
  min-width: 76px;
  border-radius: 999px;
  padding: 8px 14px;
  color: #fff;
  background: #2fc8d4;
}

.point-estimate-card:nth-child(2) strong { background: #2bb673; }
.point-estimate-card:nth-child(3) strong { background: #3a86ff; }
.point-estimate-card:nth-child(4) strong { background: #f44786; }

.point-estimate-card span {
  font-weight: 800;
}

.console-points .point-note {
  margin-top: 0;
  font-size: 12px;
}

.mode-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(320px, .9fr);
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 10px rgba(24,32,42,.04);
}

.panel + .panel, .flow-panel { margin-top: 16px; }

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

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 13px;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfd;
}

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

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

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.preview-stage {
  display: grid;
  place-items: center;
}

.phone-frame {
  width: min(300px, 100%);
  aspect-ratio: 9 / 16;
  background: #101418;
  border-radius: 22px;
  padding: 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.video-placeholder {
  border: 0;
  height: 100%;
  width: 100%;
  border-radius: 14px;
  background:
    linear-gradient(160deg, rgba(35,95,156,.9), rgba(47,125,103,.78)),
    url("/media/ai-cm-source-banner.png");
  background-size: cover;
  background-position: center;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  padding: 22px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.video-placeholder strong { font-size: 20px; margin-bottom: 8px; }
.video-placeholder span { line-height: 1.6; }
.video-placeholder em {
  margin-top: 12px;
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255,255,255,.88);
  color: #17202a;
  border-radius: 999px;
  padding: 6px 10px;
}

.video-placeholder.is-playing .preview-play-mark {
  background: rgba(255,255,255,.92);
  color: #e43f7b;
}

.preview-play-mark {
  position: absolute;
  inset: 20px 20px auto auto;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(23,32,42,.78);
  color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,.24);
}

.finish-preview {
  background: #17202a;
  color: #fff;
}

.finish-preview span {
  display: inline-block;
  margin-left: 4px;
}

.point-mark {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  border-radius: 999px;
  background: #17202a;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  cursor: help;
  vertical-align: middle;
}

.chapter {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fbfcfd;
}

.chapter-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
  margin-bottom: 10px;
}

.transition-control {
  max-width: 280px;
  margin: 0 0 10px;
}

.clip-row {
  display: grid;
  grid-template-columns: 80px 1fr 90px 330px;
  gap: 10px;
  align-items: center;
  border-top: 1px solid #e8edf2;
  padding: 10px 0;
}

.clip-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

button.mini {
  min-height: 30px;
  padding: 6px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  background: #e8f1f8;
  color: var(--blue);
}

.badge.ok { background: #e5f3ee; color: var(--green); }
.badge.wait { background: #fbf1dd; color: var(--gold); }
.badge.fail { background: #f8e6eb; color: var(--rose); }

.flow-empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 20px;
}

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

.job, .ledger-row, .worker-row {
  display: grid;
  grid-template-columns: 150px 1fr 110px;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.worker-info, .points-info, .materials-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.ledger-row, .material-row {
  grid-template-columns: 130px 90px 1fr;
}

.material-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.danger-text { color: var(--rose); font-weight: 700; }
.ok-text { color: var(--green); font-weight: 700; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.material-grid, .plan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.checkout-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.sample-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.sample-video-frame {
  background: #101418;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 9 / 16;
}

.sample-video-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.help-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .85fr);
  gap: 16px;
  margin-top: 16px;
}

.help-form textarea {
  min-height: 180px;
}

.help-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
}

.saved-check {
  border-top: 1px solid #e8edf2;
  margin-top: 16px;
  padding-top: 14px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.validation-result {
  background: #f7f9fb;
  border: 1px solid #e3e8ee;
  border-radius: 8px;
  color: var(--muted);
  padding: 10px;
}

.validation-result strong {
  color: var(--ink);
}

.voice-blocks {
  display: grid;
  gap: 12px;
}

.voice-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.voice-block textarea {
  min-height: 120px;
}

.voice-block-status {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: start;
  border-top: 1px solid #e3e8ee;
  padding: 10px 0 0;
  margin-top: 10px;
}

.check-row > span {
  border-radius: 999px;
  padding: 5px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  background: #e8f1f8;
  color: var(--blue);
}

.check-row.ok > span {
  background: #e5f3ee;
  color: var(--green);
}

.check-row.warning > span {
  background: #fbf1dd;
  color: var(--gold);
}

.check-row.error > span {
  background: #f8e6eb;
  color: var(--rose);
}

.check-row p {
  margin-bottom: 0;
}

.estimate-box {
  display: grid;
  gap: 10px;
  max-width: 520px;
  margin: 10px 0 18px;
}

.page-copy {
  max-width: 980px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.steps span, .source-list span {
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: 999px;
  padding: 8px 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 12px 8px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 260px;
  max-width: 420px;
  background: #17202a;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}

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

.point-tooltip {
  position: absolute;
  z-index: 1000;
  max-width: 280px;
  background: #17202a;
  color: #fff;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(24,32,42,.24);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}

.point-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .control-console { grid-template-columns: 1fr; }
  .console-menu { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .point-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode-grid, .split, .help-layout { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .control-console { padding: 14px; }
  .console-hero { min-height: 190px; }
  .console-menu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .console-preview-screen { min-height: 300px; }
  .point-card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  main { padding: 12px; }
  .form-grid, .material-grid, .plan-grid, .sample-grid { grid-template-columns: 1fr; }
  .topbar, .panel-head { display: block; }
  .clip-row, .job, .ledger-row, .worker-row, .material-row { grid-template-columns: 1fr; }
}
