/* ============================================================
   みときや - 問い合わせ管理ツール
   白ベース + 紫アクセント / 角丸カード / デスクトップ優先
   ============================================================ */

:root {
  --accent: #6d28d9;
  --accent-light: #ede9fe;
  --accent-hover: #5b21b6;
  --bg: #f6f5fa;
  --surface: #ffffff;
  --border: #e5e3ee;
  --text: #26212e;
  --text-sub: #6f6a7c;
  --unread-bg: #f5f1ff;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(38, 33, 46, 0.08);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); }
button { font-family: inherit; }
h1, h2, h3 { margin: 0 0 8px; }

/* --- 共通部品 --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #b9a8e4; cursor: not-allowed; }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--accent-light); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-muted { background: #ececf1; color: var(--text-sub); }
.badge-warn { background: #fef3c7; color: #92400e; }

.badge-unhandled { background: #fee2e2; color: #991b1b; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-on_hold { background: #fef3c7; color: #92400e; }

.muted { color: var(--text-sub); }

/* --- モックバナー / フラッシュ / トースト --- */

.mock-banner {
  background: #fef3c7;
  color: #92400e;
  text-align: center;
  padding: 4px 8px;
  font-size: 12px;
}

.flash-container { padding: 8px 16px 0; }
.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-info { background: var(--accent-light); color: var(--accent-hover); }
.flash-success { background: #dcfce7; color: #166534; }

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 340px;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* --- ヘッダー --- */

.app-shell { display: flex; flex-direction: column; height: 100vh; }
body:has(.mock-banner) .app-shell { height: calc(100vh - 25px); }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.app-logo { font-size: 20px; }
.app-name { font-size: 17px; font-weight: 700; color: var(--accent); }
.back-link { text-decoration: none; font-size: 13px; }
.header-right { display: flex; align-items: center; gap: 14px; }
.last-synced { font-size: 12px; color: var(--text-sub); }
.user-chip { font-size: 13px; color: var(--text-sub); }

.sync-icon { display: inline-block; }
.syncing .sync-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- 3カラムレイアウト --- */

.main-layout {
  display: grid;
  grid-template-columns: 220px minmax(320px, 420px) 1fr;
  gap: 12px;
  padding: 12px 20px 16px;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-align: left;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-light); color: var(--accent-hover); font-weight: 700; }
.nav-count {
  font-size: 11px;
  color: var(--text-sub);
  background: var(--bg);
  border-radius: 999px;
  padding: 0 8px;
  flex-shrink: 0;
}
.nav-item.active .nav-count { background: #fff; color: var(--accent-hover); }
.nav-form-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-section-title {
  font-size: 11px;
  color: var(--text-sub);
  margin: 14px 10px 4px;
}
.sidebar-section-title.first { margin-top: 0; }
.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-link {
  padding: 6px 10px;
  text-decoration: none;
  color: var(--text-sub);
  font-size: 13px;
  border-radius: 8px;
}
.sidebar-link:hover { background: var(--bg); color: var(--text); }

/* --- 中央: 問い合わせ一覧 --- */

.inbox-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.inbox-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.filter-search { width: 100%; }
.filter-row .filter-group:first-child { flex: 1 1 220px; }
.filter-sort { flex: 0 0 116px; }
.filter-label {
  color: var(--text-sub);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.search-input:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
.date-range {
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-row input[type="date"],
.filter-row select {
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--surface);
}
.date-range input[type="date"] { min-width: 118px; }
.filter-clear {
  min-height: 32px;
  margin-left: auto;
}

.inbox-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.inbox-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.inbox-item:hover { border-color: var(--accent); }
.inbox-item.selected { border-color: var(--accent); outline: 2px solid var(--accent-light); }

/* 未読は太字 + 丸マーク + 薄い背景色で目立たせる */
.inbox-item.unread { background: var(--unread-bg); }
.inbox-item.unread .item-name,
.inbox-item.unread .item-summary { font-weight: 700; }
.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}
.inbox-item.unread .unread-dot { background: var(--accent); }

.item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-sub);
}
.item-form {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-date { margin-left: auto; flex-shrink: 0; }
.item-middle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.item-name { font-size: 13px; }
.item-star { color: #f59e0b; }
.item-memo-icon { font-size: 11px; }
.item-summary {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- 右側: 詳細 --- */

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  min-height: 0;
}
.detail-content { padding: 18px 20px; }
.detail-back { display: none; margin-bottom: 8px; }

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.detail-kicker {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.detail-form-title { font-size: 16px; }
.read-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 11px;
  white-space: nowrap;
}
.star-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #c9c4d4;
  line-height: 1;
}
.star-btn.active { color: #f59e0b; }

.detail-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 10px 0;
  font-size: 13px;
}
.meta-label {
  display: block;
  color: var(--text-sub);
  font-size: 11px;
}

.function-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.function-tab {
  min-height: 62px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 8px 10px;
  text-align: left;
}
.function-tab:hover {
  border-color: var(--accent);
  background: #fbfaff;
}
.function-tab.active {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.function-tab-main {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}
.function-tab-sub {
  color: var(--text-sub);
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.function-tab.active .function-tab-main { color: var(--accent-hover); }
.function-panels {
  margin-top: 12px;
  border-top: 1px solid var(--border);
}
.function-panel {
  padding-top: 14px;
}
.function-panel h3 {
  color: var(--text-sub);
  font-size: 13px;
  margin-bottom: 10px;
}
.detail-status-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, 1fr));
  gap: 8px;
}
.status-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  min-height: 46px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.72;
}
.status-btn:hover { opacity: 1; }
.status-btn.active {
  opacity: 1;
  font-weight: 700;
  border-color: currentColor;
  box-shadow: inset 0 0 0 1px currentColor;
}
.status-btn.badge-unhandled { background: #fee2e2; color: #991b1b; }
.status-btn.badge-in_progress { background: #dbeafe; color: #1e40af; }
.status-btn.badge-completed { background: #dcfce7; color: #166534; }
.status-btn.badge-on_hold { background: #fef3c7; color: #92400e; }

.important-row {
  margin-top: 12px;
  max-width: 260px;
}
.action-btn {
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 7px 10px;
  text-align: left;
  text-decoration: none;
}
.action-btn:hover { border-color: var(--accent); background: #fbfaff; }
.action-main { font-size: 13px; font-weight: 700; line-height: 1.3; }
.action-sub { color: var(--text-sub); font-size: 11px; line-height: 1.3; }
.important-action.active {
  border-color: #f59e0b;
  background: #fffbeb;
}
.important-action.active .action-main { color: #b45309; }
.action-link .action-main { color: var(--accent-hover); }
.action-unavailable {
  min-height: 46px;
  display: flex;
  align-items: center;
  color: var(--text-sub);
  font-size: 12px;
}
.form-action-panel {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  gap: 12px;
  align-items: stretch;
}
.response-id-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 0;
}

.qa-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: #fbfaff;
}
.qa-question { font-size: 12px; color: var(--text-sub); margin-bottom: 2px; }
.qa-answer p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.answer-list { margin: 0; padding-left: 18px; }

.memo-note { font-weight: 400; font-size: 11px; }
#memo-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
#memo-input:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
.memo-status { font-size: 11px; color: var(--text-sub); min-height: 18px; margin-top: 2px; }
.memo-status.saved { color: var(--success); }
.memo-status.error { color: var(--danger); }

.detail-footer {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.response-id-note { font-size: 11px; color: var(--text-sub); word-break: break-all; }

/* --- 空状態 --- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--text-sub);
  text-align: center;
}
.empty-icon { font-size: 34px; margin-bottom: 6px; }

/* --- ログイン画面 --- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-width: 440px;
  width: 100%;
  padding: 36px 32px;
  text-align: center;
}
.login-logo { font-size: 40px; }
.login-title { font-size: 26px; color: var(--accent); margin: 6px 0; }
.login-description { color: var(--text-sub); font-size: 13px; margin-bottom: 22px; }
.google-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 26px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}
.google-login-btn:hover { background: var(--bg); }
.login-info {
  text-align: left;
  margin-top: 26px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.login-info h2 { font-size: 13px; }
.login-info ul { padding-left: 18px; margin: 6px 0; font-size: 12px; color: var(--text-sub); }
.login-privacy { font-size: 11px; color: var(--text-sub); }

/* --- フォーム管理画面 --- */

.page-body { padding: 16px 20px; overflow-y: auto; }
.page-narrow { max-width: 640px; margin: 0 auto; width: 100%; }

.onboarding-card {
  background: var(--accent-light);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.onboarding-card h2 { font-size: 16px; color: var(--accent-hover); }
.onboarding-card p { margin: 0; font-size: 13px; }

.forms-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.selected-count { font-size: 12px; color: var(--text-sub); }

.forms-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.forms-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.forms-table th, .forms-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.forms-table th { font-size: 11px; color: var(--text-sub); font-weight: 600; white-space: nowrap; }
.forms-table tr:last-child td { border-bottom: none; }
.col-check { width: 32px; }
.col-num { text-align: right; width: 52px; }
.form-title { font-weight: 600; }
.form-id-note { font-size: 10px; color: var(--text-sub); word-break: break-all; }
.form-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- 設定画面 --- */

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.settings-card h2 { font-size: 15px; }
.account-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.account-avatar { width: 44px; height: 44px; border-radius: 50%; }
.account-name { font-weight: 700; }
.account-email { font-size: 12px; color: var(--text-sub); }
.settings-form-list { list-style: none; padding: 0; margin: 8px 0; }
.settings-form-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }

/* --- エラーページ --- */

.error-page {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 20px;
}
.error-page h1 { font-size: 56px; color: var(--accent); margin: 0; }

/* --- スマートフォン対応 --- */

@media (max-width: 960px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }
  .sidebar { order: 0; max-height: 200px; }
  .inbox-panel { order: 1; }
  .detail-panel { display: none; }

  /* 詳細表示時は一覧の代わりに詳細を全面表示する */
  .main-layout.show-detail .sidebar,
  .main-layout.show-detail .inbox-panel { display: none; }
  .main-layout.show-detail .detail-panel { display: block; }
  .detail-back { display: inline-flex; }

  .app-header { flex-wrap: wrap; gap: 8px; }
  .detail-meta { grid-template-columns: 1fr; }
  .function-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-status-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-action-panel { grid-template-columns: 1fr; }
  .important-row { max-width: none; }
}
