/* ─── リセット ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', sans-serif; background: #f0f2f5; color: #333; font-size: 14px; line-height: 1.5; }

/* ─── ヘッダー（共通） ──────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: #232f3e; color: #fff;
  height: 54px; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { font-size: 0.85rem; color: #ff9900; font-weight: 700; text-decoration: none; letter-spacing: 0.5px; }
.header-sep { color: #4a5568; font-size: 0.9rem; }
.header-title { font-size: 0.95rem; font-weight: 600; color: #e2e8f0; }
.header-right { display: flex; align-items: center; gap: 8px; }

/* ─── ボタン ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: 6px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer; border: none;
  transition: background 0.15s, box-shadow 0.15s; text-decoration: none;
  white-space: nowrap;
}
.btn-primary   { background: #ff9900; color: #fff; }
.btn-primary:hover   { background: #e68a00; }
.btn-secondary { background: #fff; color: #444; border: 1px solid #ccc; }
.btn-secondary:hover { background: #f5f5f5; }
.btn-danger    { background: #e53e3e; color: #fff; }
.btn-danger:hover    { background: #c53030; }
.btn-ghost     { background: transparent; color: #ccc; border: 1px solid #4a5568; }
.btn-ghost:hover     { background: #2d3748; }
.btn-sm        { padding: 5px 12px; font-size: 0.8rem; }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }

/* ─── ビュー共通 ─────────────────────────────────────────────────────────────── */
.view { display: block; min-height: calc(100vh - 54px); }
.view.hidden { display: none; }

/* ─── トースト通知 ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2d3748; color: #fff;
  padding: 10px 22px; border-radius: 8px; font-size: 0.88rem; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); z-index: 9999;
  transition: opacity 0.3s; opacity: 0; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.toast-ok    { background: #276749; }
#toast.toast-error { background: #9b2c2c; }

/* ─── 一覧画面 ───────────────────────────────────────────────────────────────── */
#view-list { padding: 20px 24px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-left h1 { font-size: 1.05rem; font-weight: 700; color: #232f3e; }
.toolbar-right { display: flex; gap: 8px; }
.count-badge { background: #edf2f7; color: #555; border-radius: 20px; padding: 2px 10px; font-size: 0.78rem; font-weight: 600; }

/* フィルターバー */
.filter-bar {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 16px;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.filter-bar label { display: block; font-size: 0.75rem; font-weight: 600; color: #666; margin-bottom: 3px; }
.filter-bar input[type="text"],
.filter-bar input[type="date"],
.filter-bar select {
  padding: 6px 10px; border: 1px solid #ccc; border-radius: 5px;
  font-size: 0.83rem; color: #333; background: #fff; min-width: 120px;
}
.filter-bar input[type="text"] { min-width: 200px; }
.filter-bar input:focus, .filter-bar select:focus {
  outline: none; border-color: #ff9900; box-shadow: 0 0 0 2px rgba(255,153,0,0.15);
}
.filter-item { display: flex; flex-direction: column; }
.filter-reset { align-self: flex-end; }

/* テーブル */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; border: 1px solid #e2e8f0; font-size: 0.84rem; }
thead { background: #2d3748; color: #e2e8f0; }
th { padding: 10px 12px; text-align: left; font-weight: 600; font-size: 0.78rem; white-space: nowrap; user-select: none; }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { background: #374151; }
th.sorted { color: #ff9900; }
th.sorted::after { content: ' ▲'; font-size: 0.7rem; }
th.sorted[data-dir="desc"]::after { content: ' ▼'; }
td { padding: 9px 12px; border-bottom: 1px solid #edf2f7; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover td { background: #fef9f0; }
.td-title { font-weight: 600; color: #2d3748; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-msg { text-align: center; padding: 48px; color: #aaa; font-size: 0.9rem; line-height: 2; }

/* ─── バッジ ─────────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }

/* ステータス */
.st-new       { background: #edf2f7; color: #4a5568; }       /* 受付済み */
.st-checking  { background: #dbeafe; color: #1e40af; }       /* 確認中   */
.st-planned   { background: #fef3c7; color: #92400e; }       /* 対応予定 */
.st-wip       { background: #fde68a; color: #78350f; }       /* 対応中   */
.st-done      { background: #d1fae5; color: #065f46; }       /* 完了     */
.st-rejected  { background: #fee2e2; color: #991b1b; }       /* 却下     */

/* 優先度 */
.pr-high { background: #fee2e2; color: #991b1b; }
.pr-mid  { background: #fef3c7; color: #92400e; }
.pr-low  { background: #f3f4f6; color: #6b7280; }

/* ─── フォーム画面（新規・編集共通） ────────────────────────────────────────── */
#view-new, #view-edit { padding: 24px; }
.form-container { max-width: 780px; margin: 0 auto; }

.form-section {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  margin-bottom: 16px; overflow: hidden;
}
.form-section-title {
  background: #f7fafc; border-bottom: 1px solid #e2e8f0;
  padding: 10px 20px; font-size: 0.88rem; font-weight: 700;
  color: #2d3748; display: flex; align-items: center; gap: 8px;
}
.form-section-title .opt {
  font-size: 0.72rem; font-weight: 400; color: #aaa;
  background: #eee; padding: 1px 6px; border-radius: 3px;
}
.form-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-full  { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.8rem; font-weight: 600; color: #4a5568; }
.field.required label::after { content: ' *'; color: #e53e3e; }
.field input, .field select, .field textarea {
  padding: 8px 10px; border: 1px solid #cbd5e0; border-radius: 6px;
  font-size: 0.88rem; color: #2d3748; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s; background: #fff; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: #ff9900; box-shadow: 0 0 0 2px rgba(255,153,0,0.15);
}
.field input.error, .field textarea.error, .field select.error {
  border-color: #e53e3e; box-shadow: 0 0 0 2px rgba(229,62,62,0.1);
}
.field textarea { resize: vertical; min-height: 100px; }
.field-hint { font-size: 0.75rem; color: #a0aec0; margin-top: 2px; }
.field-readonly { font-size: 0.88rem; color: #2d3748; padding: 8px 10px; background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 6px; }

.form-actions { display: flex; gap: 10px; padding: 20px 0 8px; }

/* ─── 詳細画面 ───────────────────────────────────────────────────────────────── */
#view-detail { padding: 24px; }
.detail-container { max-width: 780px; margin: 0 auto; }

.detail-head {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 20px 24px; margin-bottom: 14px;
}
.detail-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.detail-head-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.detail-head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.detail-id { font-family: monospace; font-size: 0.82rem; color: #888; margin-bottom: 4px; }
.detail-title { font-size: 1.15rem; font-weight: 700; color: #1a202c; margin-bottom: 6px; }
.detail-meta { font-size: 0.82rem; color: #718096; display: flex; gap: 16px; flex-wrap: wrap; }

.detail-section {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  margin-bottom: 14px; overflow: hidden;
}
.detail-section-title {
  background: #f7fafc; border-bottom: 1px solid #e2e8f0;
  padding: 9px 20px; font-size: 0.85rem; font-weight: 700; color: #2d3748;
}
.detail-body { padding: 16px 20px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.detail-item { padding: 8px 0; border-bottom: 1px solid #f0f0f0; display: flex; gap: 12px; align-items: flex-start; }
.detail-grid .detail-item:nth-last-child(-n+2) { border-bottom: none; }
.detail-item .di-label { font-size: 0.78rem; color: #718096; font-weight: 600; min-width: 100px; flex-shrink: 0; padding-top: 1px; }
.detail-item .di-value { font-size: 0.88rem; color: #2d3748; word-break: break-word; }

.detail-full { padding: 12px 0; border-bottom: 1px solid #f0f0f0; }
.detail-full:last-child { border-bottom: none; }
.detail-full .df-label { font-size: 0.78rem; color: #718096; font-weight: 600; margin-bottom: 6px; }
.detail-full .df-value { font-size: 0.88rem; color: #2d3748; white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.df-value.empty { color: #aaa; font-style: italic; }

/* 管理セクション（admin専用） */
.admin-section {
  background: #fff; border: 2px solid #e2d9f3; border-radius: 8px;
  margin-bottom: 14px; overflow: hidden;
}
.admin-section-title {
  background: #f5f0ff; border-bottom: 1px solid #e2d9f3;
  padding: 9px 20px; font-size: 0.85rem; font-weight: 700; color: #553c9a;
  display: flex; align-items: center; gap: 6px;
}
.admin-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px 20px; }
.admin-form-grid .form-full { grid-column: 1 / -1; }
.admin-form-actions { padding: 0 20px 16px; display: flex; gap: 10px; }

/* ─── 履歴タイムライン ───────────────────────────────────────────────────────── */
.history-list { padding: 12px 20px; }
.history-item { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f0f0f0; }
.history-item:last-child { border-bottom: none; }
.history-dot { width: 8px; height: 8px; background: #cbd5e0; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.history-content { flex: 1; min-width: 0; }
.history-meta { font-size: 0.75rem; color: #a0aec0; margin-bottom: 2px; }
.history-field { font-size: 0.83rem; color: #4a5568; }
.history-field .hf-name { font-weight: 700; color: #2d3748; }
.history-field .hf-before { color: #e53e3e; text-decoration: line-through; }
.history-field .hf-after  { color: #276749; font-weight: 600; }
.history-empty { color: #aaa; font-size: 0.85rem; padding: 12px 0; font-style: italic; }

/* ─── ローディング ───────────────────────────────────────────────────────────── */
.loading { text-align: center; padding: 48px; color: #aaa; font-size: 0.9rem; }
