/* ============================================================
   作業レポートエディタ - 共通スタイル
   ============================================================ */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #dde3ec;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok-bg: #ecfdf5;
  --ok-border: #10b981;
  --err-bg: #fef2f2;
  --err-border: #ef4444;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --font: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans",
          Meiryo, "Yu Gothic", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Courier New",
               "Hiragino Kaku Gothic ProN", Meiryo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: none; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------
   ヘッダー
   ------------------------------------------------------------ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--primary); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
}
.nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

/* ------------------------------------------------------------
   レイアウト
   ------------------------------------------------------------ */
.container {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
}
.container-narrow { max-width: 720px; }
.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 24px 0 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}
.card h2 { margin: 0 0 16px; font-size: 17px; }
.card-narrow { max-width: 560px; }
.static-value { margin: 0; font-size: 15px; font-weight: 600; padding: 6px 0; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

/* ------------------------------------------------------------
   ボタン / フォーム
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--err-bg); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

input[type="text"], input[type="password"], input[type="date"], input[type="email"], select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent);
  outline-offset: 0;
  border-color: var(--primary);
}
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.form-row input, .form-row select { width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.input-sm { padding: 4px 8px; font-size: 13px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* ------------------------------------------------------------
   フラッシュ(浮いて表示される通知。app.jsで自動消滅)
   ------------------------------------------------------------ */
.flash-wrap {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  width: min(560px, calc(100vw - 32px));
  pointer-events: none;
}
.flash {
  pointer-events: auto;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--ok-border);
  background: var(--ok-bg);
  font-size: 14px;
  white-space: pre-line;
  box-shadow: 0 4px 16px rgba(16, 24, 40, .14);
  animation: flash-in .25s ease-out;
}
.flash-err { border-color: var(--err-border); background: var(--err-bg); }
.flash-warn { border-color: var(--warn-border); background: var(--warn-bg); }
.flash-hide { opacity: 0; transform: translateY(-8px); transition: opacity .3s, transform .3s; }
@keyframes flash-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------
   ログイン
   ------------------------------------------------------------ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #eef2ff 0%, var(--bg) 60%);
}
.login-card {
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
}
.login-title { margin: 0; font-size: 20px; text-align: center; }
.login-sub { margin: 4px 0 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ------------------------------------------------------------
   一覧テーブル
   ------------------------------------------------------------ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table th, .report-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.report-table thead th {
  background: #f8fafc;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.report-table tbody tr:last-child td { border-bottom: none; }
.report-table tbody tr:hover { background: #f8fafc; }
.td-date { white-space: nowrap; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.td-title { max-width: 420px; }
.td-title a { color: var(--text); font-weight: 500; }
.td-title a:hover { color: var(--primary); }
.td-actions, .th-actions { white-space: nowrap; text-align: right; }
.td-actions .inline-form { margin-left: 4px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
}
.badge-draft { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.badge-pub { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge-role { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .btn { margin-top: 12px; }

/* ============================================================
   エディタ画面
   ============================================================ */
body:has(.container-editor) .footer { display: none; }
.container.container-editor {
  max-width: none;
  margin: 0;
  padding: 0;
  width: 100%;
  height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
}
#editor-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 12px 16px 16px;
  gap: 12px;
}
.editor-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.title-input { flex: 1 1 260px; min-width: 200px; font-size: 15px; font-weight: 600; }
.date-input { width: 150px; }
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.spacer { flex: 1; }

.editor-main {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 12px;
}
.editor-pane, .preview-pane {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.pane-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  letter-spacing: .04em;
}
#md-editor {
  flex: 1;
  width: 100%;
  border: none;
  border-radius: 0;
  resize: none;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.75;
  tab-size: 4;
  background: var(--surface);
  color: var(--text);
  min-height: 0;
}
#md-editor:focus { outline: none; }
#preview {
  flex: 1;
  overflow: auto;
  padding: 16px 20px;
  min-height: 0;
}

/* ------------------------------------------------------------
   Ajaxファイラー(左列)
   幅1100px以上: 3カラムの左列として常設(トグルで開閉)
   幅1100px未満: 左からスライドするドロワー
   ------------------------------------------------------------ */
.filer {
  position: relative;
  flex: none;
  width: 280px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden auto;
}
@media (min-width: 1100px) {
  body:not(.filer-open) .filer { display: none; }
}
@media (max-width: 1099.98px) {
  .filer {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: min(300px, 100vw);
    border-radius: 0;
    border-left: none;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 16px rgba(16, 24, 40, .08);
    transform: translateX(-100%);
    transition: transform .18s ease-out;
    z-index: 60;
  }
  body.filer-open .filer { transform: translateX(0); }
}
.filer.dragover::after {
  content: "ドロップでアップロード";
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, .08);
  border: 2px dashed var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 600;
  pointer-events: none;
}
.filer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.filer-upload input[type="file"] { width: 100%; font-size: 12px; }
.filer-progress {
  margin-top: 6px;
  font-size: 13px;
  color: var(--primary);
}
.filer-hint { font-size: 12px; color: var(--text-muted); }
.filer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.filer-empty { color: var(--text-muted); font-size: 13px; padding: 12px 4px; }
.filer-item {
  display: flex;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.filer-thumb {
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: 6px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.filer-thumb img { width: 100%; height: 100%; object-fit: cover; }
.filer-ext { font-size: 11px; font-weight: 700; color: var(--text-muted); }
.filer-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.filer-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filer-meta { font-size: 12px; }
.filer-actions { display: flex; gap: 6px; margin-top: auto; }
.filer-foot { font-size: 12px; padding-top: 4px; border-top: 1px solid var(--border); }

/* ============================================================
   ビューワ
   ============================================================ */
.container-viewer { max-width: 860px; }
.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.report-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 44px;
}
.report-title { margin: 0 0 8px; font-size: 26px; line-height: 1.4; }
.report-meta {
  display: flex;
  gap: 16px;
  color: var(--text-muted);
  font-size: 13px;
  align-items: center;
}
.print-only { display: none; }
.report-sep { margin: 20px 0 24px; }

/* ------------------------------------------------------------
   Markdown本文
   ------------------------------------------------------------ */
.md-body { overflow-wrap: break-word; }
.md-body > :first-child { margin-top: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  line-height: 1.4;
  margin: 1.6em 0 .6em;
}
.md-body h1 { font-size: 1.7em; border-bottom: 2px solid var(--border); padding-bottom: .3em; }
.md-body h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: .25em; }
.md-body h3 { font-size: 1.17em; }
.md-body h4 { font-size: 1.05em; }
.md-body p { margin: .8em 0; }
.md-body ul, .md-body ol { padding-left: 1.6em; margin: .8em 0; }
.md-body li { margin: .25em 0; }
.md-body code {
  font-family: var(--font-mono);
  font-size: .9em;
  background: #f1f5f9;
  border-radius: 4px;
  padding: .15em .4em;
}
.md-body pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.6;
}
.md-body pre code { background: transparent; color: inherit; padding: 0; font-size: .9em; }
.md-body blockquote {
  margin: .8em 0;
  padding: .4em 1em;
  border-left: 4px solid var(--border);
  color: var(--text-muted);
  background: #f8fafc;
}
.md-body table { border-collapse: collapse; margin: 1em 0; width: 100%; font-size: .95em; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 12px; }
.md-body th { background: #f8fafc; font-weight: 600; }
.md-body img { max-width: 100%; height: auto; border-radius: 4px; }
.md-body hr { margin: 1.6em 0; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------
   ユーザー管理
   ------------------------------------------------------------ */
.password-form input, .rename-form input { min-width: 150px; }

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (max-width: 900px) {
  .editor-main { flex-direction: column; }
  .container.container-editor { height: auto; min-height: calc(100vh - 56px); }
  #md-editor { min-height: 300px; }
  #preview { min-height: 300px; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { gap: 8px; }
  .user-chip small { display: none; }
}
@media (max-width: 640px) {
  .topbar-inner {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 4px 10px;
  }
  .brand { font-size: 15px; }
  .nav { flex: 1 1 100%; order: 3; width: 100%; }
  .nav a { padding: 4px 8px; font-size: 13px; }
  .topbar-user { margin-left: auto; }
  .report-view { padding: 20px 18px; }
  .filer { width: 100vw; }
}

/* ============================================================
   印刷 / PDF出力
   ============================================================ */
@media print {
  @page { margin: 18mm 16mm; }
  body { background: #fff; font-size: 11.5pt; }
  .topbar, .footer, .no-print, .flash-wrap, .filer { display: none !important; }
  .print-only { display: flex; gap: 12px; }
  .container { margin: 0; padding: 0; max-width: none; }
  .report-view {
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
  }
  .report-title { font-size: 20pt; }
  /* 大セクション(h1 = 「# 」)ごとに改ページする。
     文書の先頭にあるh1だけはページ頭から始めるため改行しない。
     ※タイトルを独立した表紙ページにしたい場合は下の :first-child ルールを削除 */
  .md-body h1 { page-break-before: always; break-before: page; }
  .md-body > h1:first-child { page-break-before: auto; break-before: auto; }
  .md-body a { color: #000; text-decoration: underline; }
  .md-body pre { background: #f3f4f6 !important; color: #111 !important; }
  .md-body img, .md-body blockquote, .md-body table, .md-body pre { break-inside: avoid; }
  .md-body h1, .md-body h2, .md-body h3 { break-after: avoid; }
}
