:root {
  --primary: #4bd1fc;
  --primary-light: #8cedff;
  --primary-dark: #0098cc;
  --ink: #111418;
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --line: #e4e7eb;
  --muted: #616e7c;
  --danger: #d64545;
  --success: #1f9d55;
  --warning: #b7791f;
  --radius: 8px;
  --font-sans: Inter, "Noto Sans JP", system-ui, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background-color: var(--bg-soft);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================== Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  height: 60px;
  flex-shrink: 0;
  gap: 16px;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.logo-image { height: 32px; width: 32px; }

.logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--ink);
}

.logo-text .highlight { color: var(--primary); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.locale-switch { display: flex; gap: 6px; }

.locale-switch button {
  background: none;
  border: 1px solid var(--line);
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--muted);
  font-family: inherit;
}

.locale-switch button:hover { border-color: var(--ink); color: var(--ink); }

.locale-switch button.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  padding: 0;
}

.icon-button:hover { border-color: var(--ink); color: var(--ink); }

.icon-button svg { width: 17px; height: 17px; }

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.is-ready { background: rgba(75, 209, 252, 0.14); color: var(--primary-dark); }
.status-pill.is-busy { background: rgba(75, 209, 252, 0.2); color: var(--primary-dark); }
.status-pill.is-failed { background: rgba(214, 69, 69, 0.12); color: var(--danger); }
.status-pill.is-offline { background: rgba(183, 121, 31, 0.12); color: var(--warning); }

/* ============================================================== Layout */

.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  height: 100%;
}

.input-panel {
  width: 380px;
  border-right: 1px solid var(--line);
  padding: 24px;
  overflow-y: auto;
  flex-shrink: 0;
}

.output-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  position: relative;
  min-width: 0;
}

/* ============================================================== Form */

.job-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-label {
  font-weight: 700;
  font-size: 0.875rem;
  margin-bottom: 8px;
  display: block;
}

.upload-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 36px 20px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
  background: var(--bg);
}

.upload-box:hover,
.upload-box.is-dragover {
  border-color: var(--primary);
  background: rgba(75, 209, 252, 0.05);
}

.upload-box.has-file { border-style: solid; border-color: var(--primary); }

.upload-input { display: none; }

.upload-icon svg {
  width: 30px;
  height: 30px;
  color: var(--primary);
  margin-bottom: 10px;
}

.upload-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  display: block;
  word-break: break-all;
}

.upload-box.has-file .upload-title { color: var(--primary-dark); }

.upload-meta { font-size: 0.75rem; color: var(--muted); }

.modern-select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23616e7c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.modern-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(75, 209, 252, 0.18);
}

/* --- submit + error --------------------------------------------------- */

.btn-primary {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  width: 100%;
  font-family: inherit;
}

.btn-primary:hover:not(:disabled) { background: var(--primary); color: var(--ink); }

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(214, 69, 69, 0.08);
  border: 1px solid rgba(214, 69, 69, 0.3);
  color: var(--danger);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-family: inherit;
}

.btn-ghost:hover { background: rgba(75, 209, 252, 0.1); }

/* --- progress --------------------------------------------------------- */

.progress-wrap {
  background: var(--bg-soft);
  padding: 16px;
  border-radius: var(--radius);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
}

progress {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  appearance: none;
  border: none;
  background-color: var(--line);
}

progress::-webkit-progress-bar { background-color: var(--line); border-radius: 3px; }
progress::-webkit-progress-value {
  background-color: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}
progress::-moz-progress-bar { background-color: var(--primary); border-radius: 3px; }

.stage-tracker {
  display: flex;
  align-items: flex-start;
  margin-top: 14px;
  gap: 2px;
}

.stage-tracker .stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 34px;
}

.stage-tracker .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  display: block;
}

.stage-tracker .stage em {
  font-style: normal;
  font-size: 0.6875rem;
  color: var(--muted);
  white-space: nowrap;
}

.stage-tracker .stage.is-done .dot { background: var(--primary); }
.stage-tracker .stage.is-active .dot {
  background: var(--primary);
  animation: pulse 1.6s ease-in-out infinite;
}
.stage-tracker .stage.is-failed .dot { background: var(--danger); }
.stage-tracker .stage.is-done em,
.stage-tracker .stage.is-active em { color: var(--ink); font-weight: 600; }

.stage-tracker .rail {
  flex: 1;
  height: 2px;
  background: var(--line);
  margin-top: 4px;
  min-width: 8px;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(75, 209, 252, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(75, 209, 252, 0.12); }
}

.progress-detail {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 12px 0 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.logs-toggle { margin-top: 8px; align-self: flex-start; }

.logs {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: var(--radius);
  background: #16191d;
  color: #c8d0d9;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.6;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.job-tracker { display: flex; flex-direction: column; }

/* ============================================================== Output */

.output-header {
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 60px;
  gap: 16px;
  flex-wrap: wrap;
}

.output-header h2 {
  font-size: 1.05rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.primary-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.8125rem;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { border-color: var(--ink); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn svg { width: 14px; height: 14px; }

.btn.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }

.btn.btn-dark:hover:not(:disabled) { background: var(--primary); border-color: var(--primary); color: var(--ink); }

.btn.btn-danger { color: var(--danger); border-color: rgba(214, 69, 69, 0.4); }

.btn.btn-danger:hover:not(:disabled) { border-color: var(--danger); background: rgba(214, 69, 69, 0.06); }

.btn.btn-icon-only { padding: 8px; }

.preview-container {
  flex: 1;
  padding: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preview-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 24px;
}

.preview-placeholder svg {
  width: 48px;
  height: 48px;
  color: var(--line);
  margin-bottom: 16px;
}

.preview-placeholder.is-loading svg {
  color: var(--primary);
  animation: bob 1.4s ease-in-out infinite;
}

.preview-placeholder.is-error { color: var(--danger); }
.preview-placeholder.is-error svg { color: rgba(214, 69, 69, 0.35); }

.preview-placeholder p { margin: 0; max-width: 46ch; line-height: 1.6; overflow-wrap: anywhere; }

@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: 0.7; }
  50% { transform: translateY(-6px); opacity: 1; }
}

.pdf-preview {
  flex: 1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

/* ============================================================== History */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 24, 0.3);
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 40;
}

.drawer-backdrop.is-open { opacity: 1; }

.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(17, 20, 24, 0.12);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.history-drawer.is-open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 { margin: 0; font-size: 1.05rem; }

.drawer-note {
  margin: 12px 20px 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-empty {
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
  padding: 24px 12px;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-family: inherit;
}

.history-item:hover { border-color: var(--primary); }

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

.history-name {
  font-weight: 600;
  font-size: 0.8425rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  font-size: 0.6875rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status-chip {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--bg-soft);
  color: var(--muted);
}

.status-chip.is-completed { background: rgba(31, 157, 85, 0.1); color: var(--success); }
.status-chip.is-failed { background: rgba(214, 69, 69, 0.1); color: var(--danger); }
.status-chip.is-interrupted { background: rgba(183, 121, 31, 0.12); color: var(--warning); }
.status-chip.is-running,
.status-chip.is-queued,
.status-chip.is-compiling { background: rgba(75, 209, 252, 0.16); color: var(--primary-dark); }

/* ============================================================== Help page */

.help-page {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 64px;
}

.docs-panel {
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px 36px 40px;
}

.docs-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.docs-head h1 { font-size: 1.4rem; margin: 0; }

.help-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  flex-shrink: 0;
}

.help-button:hover { border-color: var(--ink); color: var(--ink); }

.help-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.docs-intro { color: var(--muted); line-height: 1.7; }

.docs-panel section { margin-top: 28px; }

.docs-panel h2 {
  font-size: 1.05rem;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.docs-panel p, .docs-panel li { line-height: 1.8; font-size: 0.9rem; }

.docs-panel ul, .docs-panel ol { padding-left: 22px; margin: 8px 0; }

.docs-panel li { margin-bottom: 4px; }

/* ============================================================== Utilities */

.is-hidden { display: none !important; }

/* ============================================================== Mobile */

@media (max-width: 900px) {
  body { overflow: auto; height: auto; min-height: 100dvh; }

  .topbar { padding: 10px 16px; }

  .app-layout { flex-direction: column; overflow: visible; }

  .input-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow-y: visible;
    height: auto;
  }

  .output-panel { min-height: 70vh; height: auto; }

  .preview-container { min-height: 60vh; }

  .pdf-preview { min-height: 55vh; }

  .output-header { padding: 12px 16px; }

  .docs-panel { padding: 24px 20px 32px; }
}

@media (max-width: 480px) {
  .locale-switch button { padding: 4px 9px; font-size: 0.75rem; }
  .status-pill { display: none; }
}
