:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e2e8f0;
  --text: #172033;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --radius: 20px;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(
      circle at top right,
      rgba(37, 99, 235, 0.10),
      transparent 30%
    ),
    var(--bg);
  color: var(--text);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans JP",
    sans-serif;
}

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

.ai-improvement-app {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 60px;
}

.ai-improvement-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.ai-improvement-header h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  letter-spacing: -0.04em;
}

.header-description {
  max-width: 700px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.8;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
}

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

.summary-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-value {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  letter-spacing: -0.04em;
}

.workspace {
  display: grid;
  grid-template-columns:
    minmax(420px, 0.9fr)
    minmax(500px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.candidate-panel,
.detail-panel {
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.candidate-panel {
  padding: 22px;
}

.detail-panel {
  position: sticky;
  top: 20px;
  overflow: hidden;
}

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

.section-heading h2 {
  margin: 0;
  font-size: 22px;
}

.status-filter {
  min-height: 42px;
  padding: 0 38px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface);
}

.message-area {
  margin-bottom: 12px;
}

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

.empty-state,
.detail-empty {
  color: var(--muted);
  text-align: center;
}

.empty-state {
  padding: 48px 20px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}

.detail-empty {
  min-height: 560px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.detail-empty-icon {
  width: 68px;
  height: 68px;
  margin-bottom: 18px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  font-weight: 900;
}

.detail-empty h2 {
  margin: 0 0 10px;
}

.detail-empty p {
  max-width: 360px;
  margin: 0;
  line-height: 1.8;
}

@media (max-width: 980px) {
  .ai-improvement-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

  .detail-panel {
    position: static;
  }
}

@media (max-width: 600px) {
  .ai-improvement-app {
    width: min(100% - 20px, 1500px);
    padding-top: 20px;
  }

  .header-actions {
    width: 100%;
  }

  .primary-button,
  .secondary-button {
    flex: 1;
  }

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

  .candidate-panel {
    padding: 16px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }
}

/* AI improvement interaction and overflow guard */

.workspace > *,
.candidate-panel,
.detail-panel,
.detail-content,
.detail-section,
.detail-grid,
.detail-form,
.detail-form > label {
  min-width: 0;
}

.candidate-card {
  appearance: none;
  width: 100%;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.candidate-card:hover {
  border-color: #93c5fd;
  background: #f8fbff;
  box-shadow:
    0 10px 24px
    rgba(37, 99, 235, 0.10);
  transform: translateY(-1px);
}

.candidate-card:focus-visible {
  outline:
    3px solid
    rgba(37, 99, 235, 0.18);
  outline-offset: 2px;
}

.candidate-card.is-selected {
  border-color: var(--accent);
  background: #eff6ff;
  box-shadow:
    0 0 0 3px
    rgba(37, 99, 235, 0.12);
}

.candidate-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.candidate-question,
.candidate-meta,
.detail-section p {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.candidate-question {
  margin-top: 10px;
  font-weight: 700;
  line-height: 1.6;
}

.candidate-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

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

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.detail-heading h2 {
  margin: 0;
}

.detail-section {
  margin-top: 20px;
}

.detail-section p {
  margin: 8px 0 0;
  line-height: 1.7;
}

.detail-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.detail-form {
  display: grid;
  grid-template-columns:
    minmax(0, 1fr)
    minmax(0, 1fr);
  gap: 16px;
  margin-top: 22px;
}

.detail-form > label {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

.detail-form > label:nth-child(2),
.detail-form > label:nth-child(3) {
  grid-column: 1 / -1;
}

.detail-form input,
.detail-form textarea,
.detail-form select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.detail-form input:focus,
.detail-form textarea:focus,
.detail-form select:focus {
  border-color: var(--accent);
  outline:
    3px solid
    rgba(37, 99, 235, 0.12);
}

.detail-form textarea {
  resize: vertical;
  line-height: 1.6;
}

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

@media (max-width: 700px) {
  .detail-content {
    padding: 18px;
  }

  .detail-heading {
    flex-direction: column;
    gap: 8px;
  }

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

  .detail-form > label:nth-child(2),
  .detail-form > label:nth-child(3) {
    grid-column: auto;
  }
}

/* Phase2-A approval workflow */

.question-example-list {
  margin: 10px 0 0;
  padding-left: 22px;
  display: grid;
  gap: 8px;
}

.question-example-list li {
  line-height: 1.6;
  overflow-wrap: anywhere;
}

@media (min-width: 981px) {
  .summary-grid {
    grid-template-columns:
      repeat(5, minmax(0, 1fr));
  }
}


.review-queue-panel {
  margin: 18px 0 22px;
  padding: 18px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(14px);
}

.review-queue-note {
  font-size: 0.82rem;
  opacity: 0.72;
}

.review-queue-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.review-queue-item,
.review-queue-empty {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.review-queue-item p {
  margin: 7px 0 0;
  line-height: 1.55;
}

.review-queue-item > span {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.78rem;
  opacity: 0.76;
}

.event-timeline {
  position: relative;
  display: grid;
  gap: 12px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.event-timeline-item {
  padding: 12px 14px;
  border-left: 3px solid rgba(125, 211, 252, 0.7);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.event-timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.event-timeline-head time,
.event-timeline-meta,
.event-timeline-empty {
  font-size: 0.82rem;
  opacity: 0.72;
}

.event-timeline-item p {
  margin: 8px 0 0;
  white-space: pre-wrap;
}

@media (max-width: 900px) {
  .review-queue-list {
    grid-template-columns: 1fr;
  }
}

body.ai-management-auth-pending {
  visibility: hidden;
}

.ai-draft-panel[hidden] {
  display: none;
}

.ai-draft-panel {
  margin-top: 22px;
  padding: 24px;
  border: 1px solid #dbe5ff;
  border-radius: 22px;
  background:
    linear-gradient(
      135deg,
      rgba(239, 246, 255, 0.98),
      rgba(255, 255, 255, 0.98)
    );
  box-shadow:
    0 18px 45px rgba(15, 23, 42, 0.08);
}

.ai-draft-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.ai-draft-panel-header h2 {
  margin: 2px 0 8px;
  font-size: 24px;
}

.ai-draft-panel-note {
  margin: 0;
  color: #64748b;
  line-height: 1.7;
}

.ai-draft-generate-button {
  flex: 0 0 auto;
  min-width: 190px;
}

.ai-draft-result {
  margin-top: 22px;
}

.ai-draft-card {
  padding: 20px;
  border: 1px solid #dbeafe;
  border-radius: 18px;
  background: #ffffff;
}

.ai-draft-card h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.ai-draft-field {
  margin-top: 14px;
}

.ai-draft-field-label {
  display: block;
  margin-bottom: 5px;
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
}

.ai-draft-field-value {
  margin: 0;
  color: #172033;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-draft-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.ai-draft-empty {
  padding: 18px;
  border: 1px dashed #cbd5e1;
  border-radius: 16px;
  background: rgba(248, 250, 252, 0.8);
  color: #64748b;
  line-height: 1.7;
}

.ai-draft-history-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e2e8f0;
}

.ai-draft-history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.ai-draft-history-heading h3 {
  margin: 0;
  font-size: 16px;
}

.ai-draft-history-heading span {
  color: #94a3b8;
  font-size: 12px;
}

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

.ai-draft-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #ffffff;
}

.ai-draft-history-item strong {
  font-size: 13px;
}

.ai-draft-history-item time {
  color: #64748b;
  font-size: 12px;
}

@media (max-width: 760px) {
  .ai-draft-panel {
    padding: 18px;
  }

  .ai-draft-panel-header {
    flex-direction: column;
  }

  .ai-draft-generate-button {
    width: 100%;
  }

  .ai-draft-history-item {
    align-items: flex-start;
    flex-direction: column;
  }
}
