:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --panel: #ffffff;
  --panel-soft: #fbfbf8;
  --ink: #1f2428;
  --muted: #626a70;
  --line: #dfe4df;
  --green: #27675a;
  --blue: #315f8f;
  --red: #983648;
  --amber: #aa7a15;
  --violet: #70569b;
  --shadow: 0 18px 42px rgba(24, 31, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(39, 103, 90, 0.09) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(49, 95, 143, 0.07) 0 1px, transparent 1px 100%),
    var(--bg);
  background-size: 44px 44px;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 0 24px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 2px 18px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.topbar-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.sync-status {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.primary-button,
.action-button,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  padding: 7px 13px;
}

.primary-button:hover {
  background: #1e594d;
}

.stat-pill,
.meta-pill,
.tag,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

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

.library-panel,
.detail-panel,
.board-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.library-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

.workspace.is-board .library-panel {
  position: static;
  max-height: none;
}

.workspace.is-board .priority-strip,
.workspace.is-board .script-list {
  display: none;
}

.toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 8px 10px;
}

.search-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 4px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 4px;
}

.view-toggle-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.view-toggle-button.is-active {
  background: var(--green);
  color: #fff;
}

select {
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 0 10px;
}

.priority-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8f8f4;
}

.priority-box {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px;
}

.priority-box strong {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
}

.priority-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.script-list {
  max-height: calc(100vh - 230px);
  overflow: auto;
  padding: 10px;
}

.board-panel {
  display: none;
  overflow: hidden;
}

.workspace.is-board .board-panel {
  display: block;
}

.board-scroll {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(230px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding: 12px;
}

.board-column {
  min-height: 300px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  transition: border-color 140ms ease, background 140ms ease;
}

.board-column.is-drag-over,
.board-column-body.is-drag-over {
  border-color: rgba(39, 103, 90, 0.7);
  background: #eef6f1;
}

.board-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.board-column-header strong {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.board-column-body {
  display: grid;
  align-content: start;
  gap: 8px;
  max-height: 560px;
  overflow-y: auto;
  padding: 10px;
  border-radius: 0 0 8px 8px;
}

.board-card {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 10px;
  text-align: left;
  cursor: grab;
  outline: 0;
}

.board-card:hover,
.board-card.is-active,
.board-card:focus-visible {
  border-color: rgba(39, 103, 90, 0.55);
  box-shadow: 0 8px 20px rgba(39, 103, 90, 0.12);
}

.board-card.is-dragging {
  cursor: grabbing;
  opacity: 0.62;
}

.board-card-title {
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
}

.board-card-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.board-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.board-card-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px auto;
  gap: 6px;
  align-items: end;
  margin-top: 2px;
}

.board-card-controls label {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.board-card-controls label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.board-card-controls select {
  width: 100%;
  height: 32px;
  border-radius: 6px;
  padding: 0 7px;
  font-size: 12px;
}

.board-detail-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.board-detail-button:hover {
  border-color: rgba(39, 103, 90, 0.55);
  color: var(--green);
}

.board-empty {
  display: grid;
  place-items: center;
  min-height: 84px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.script-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.script-card:hover,
.script-card.is-active {
  border-color: rgba(39, 103, 90, 0.55);
  box-shadow: 0 8px 20px rgba(39, 103, 90, 0.12);
}

.script-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  background: var(--green);
}

.script-mark.short {
  background: var(--green);
}

.script-mark.long {
  background: var(--blue);
}

.script-mark.memo {
  background: var(--amber);
}

.script-mark.vehicle {
  background: var(--red);
}

.script-mark.template {
  background: var(--violet);
}

.card-title {
  display: block;
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.card-subtitle {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.status-badge {
  border-color: transparent;
  color: #fff;
  background: var(--muted);
}

.status-badge[data-status="採用候補"] {
  background: var(--green);
}

.status-badge[data-status="案出し中"] {
  background: var(--amber);
}

.status-badge[data-status="保留"] {
  background: var(--blue);
}

.detail-panel {
  min-height: calc(100vh - 96px);
  overflow: hidden;
}

.detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.detail-title {
  margin: 0 0 10px;
  font-size: 24px;
  line-height: 1.25;
}

.detail-summary {
  max-width: 820px;
  margin: 0;
  color: var(--muted);
}

.detail-actions {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.action-button {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  padding: 7px 11px;
}

.action-button:hover {
  border-color: rgba(39, 103, 90, 0.55);
  color: var(--green);
}

.danger-button:hover {
  border-color: rgba(152, 54, 72, 0.45);
  color: var(--red);
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #f8f8f4;
}

.quick-edit {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.quick-edit-caption {
  align-self: center;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.quick-edit label {
  display: grid;
  gap: 4px;
  min-width: 150px;
}

.quick-edit label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.quick-edit select {
  height: 36px;
  background: var(--panel-soft);
}

.detail-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: 16px;
  padding: 18px;
}

.markdown-body {
  min-width: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  line-height: 1.3;
}

.markdown-body h1 {
  margin: 0 0 16px;
  font-size: 24px;
}

.markdown-body h2 {
  margin: 24px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 18px;
}

.markdown-body h3 {
  margin: 18px 0 8px;
  color: var(--green);
  font-size: 15px;
}

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

.markdown-body li {
  margin: 3px 0;
}

.markdown-body strong {
  font-weight: 900;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 16px;
  background: var(--panel);
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: #eef4ef;
}

.side-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 12px;
}

.side-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.side-block h2 {
  margin: 0 0 8px;
  font-size: 14px;
}

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

.side-list li {
  border-left: 3px solid var(--green);
  padding-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-color: rgba(49, 95, 143, 0.25);
  color: var(--blue);
  background: #f5f9fc;
}

.empty-state {
  padding: 26px 14px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(18px);
  opacity: 0;
  border: 1px solid rgba(39, 103, 90, 0.2);
  border-radius: 8px;
  background: #1f2428;
  color: #fff;
  padding: 10px 12px;
  font-size: 13px;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.script-dialog {
  width: min(920px, calc(100vw - 24px));
  max-height: min(860px, calc(100vh - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: 0 26px 80px rgba(20, 28, 31, 0.24);
}

.script-dialog::backdrop {
  background: rgba(18, 24, 28, 0.42);
}

.script-form {
  display: grid;
  max-height: min(860px, calc(100vh - 24px));
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
}

.dialog-header {
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.dialog-actions {
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  overflow: auto;
  padding: 16px 18px;
}

.form-grid label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.form-grid label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.form-grid input,
.form-grid textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 9px 10px;
}

.form-grid textarea {
  resize: vertical;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100% - 20px, 760px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .topbar-stats {
    justify-content: flex-start;
  }

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

  .library-panel {
    position: static;
    max-height: none;
  }

  .script-list {
    max-height: 420px;
  }

  .detail-panel {
    min-height: auto;
  }

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

  .side-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    width: min(100% - 14px, 560px);
    padding-top: 10px;
  }

  h1 {
    font-size: 26px;
  }

  .filters,
  .priority-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .view-toggle {
    width: 100%;
  }

  .board-scroll {
    grid-auto-columns: minmax(250px, 82vw);
  }

  .board-card-controls {
    grid-template-columns: 1fr;
  }

  .detail-header {
    grid-template-columns: 1fr;
  }

  .detail-actions {
    justify-content: flex-start;
  }

  .detail-title {
    font-size: 21px;
  }
}
