:root {
  --primary:       #0F766E;
  --primary-light: #CCFBF1;
  --primary-dark:  #0D5C57;
  --bg:            #f1f3f4;
  --card:          #FFFFFF;
  --border:        #E5E7EB;
  --text:          #1E293B;
  --text-muted:    #64748B;
  --danger:        #DC2626;
  --danger-light:  #FEE2E2;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', sans-serif; background: var(--bg); color: var(--text); font-size: 13px; line-height: 1.6; }

/* ── Layout ── */
#app { display: flex; height: 100vh; }
#left-panel  { width: 70%; min-width: 320px; background: var(--bg); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
#right-panel { width: 30%; min-width: 240px; background: var(--card); border-left: 1px solid var(--border); display: flex; flex-direction: column; }

/* ── 2-column main grid ── */
#main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 768px) { #main-grid { grid-template-columns: 1fr; } }

/* ── 行2: 利用者選択(55%) + 作成ボタン群(45%) ── */
#user-action-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
#left-cards-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#action-btns-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}
#action-btns-row {
  display: flex;
  flex-direction: row;
  gap: 20px;
  justify-content: center;
  align-items: center;
}
@media (max-width: 768px) {
  #user-action-row { grid-template-columns: 1fr; }
  #action-btns-area { padding: 8px 0 0; }
  #action-btns-row { justify-content: flex-start; }
}

/* ── Header Card ── */
#header-card { background: var(--card); border-radius: 10px; padding: 14px 16px; border: 1px solid var(--border); border-left: 4px solid var(--primary); display: flex; align-items: center; gap: 12px; }
#header-title { font-size: 15px; font-weight: bold; color: var(--primary); flex: 1; }
#header-sub   { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
#settings-btn { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 12px; color: var(--text-muted); white-space: nowrap; font-family: inherit; }
#settings-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Cards ── */
.card { background: var(--card); border-radius: 10px; padding: 14px; border: 1px solid var(--border); }
.card-label { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }

/* ── User Select (compact) ── */
#user-select { width: 100%; padding: 7px 10px; border: 1.5px solid var(--primary); border-radius: 8px; font-size: 12px; font-family: inherit; outline: none; margin-top: 4px; }
#refresh-users-btn { background: #475569; color: #fff; border: none; border-radius: 6px; padding: 6px 16px; font-size: 12px; font-family: inherit; cursor: pointer; white-space: nowrap; margin-top: 8px; }
#refresh-users-btn:hover { background: #334155; }

/* ── Progress Bar (legacy, kept for work-progress area) ── */
.progress-bar-wrap  { background: #F1F5F9; border-radius: 100px; height: 8px; overflow: hidden; }
.progress-bar       { background: linear-gradient(90deg, var(--primary), #14B8A6); height: 100%; border-radius: 100px; transition: width 0.5s ease; }

/* ── Gamification Dashboard ── */
.effort-bar-row {
  display: flex; gap: 5px; margin: 6px 0 10px;
}
.effort-seg {
  flex: 1; height: 14px; background: #E2E8F0; border-radius: 4px; overflow: hidden;
}
.effort-fill {
  height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, var(--primary), #14B8A6);
  transition: width 0.6s cubic-bezier(.34,1.56,.64,1);
}
.effort-seg.full .effort-fill {
  background: linear-gradient(90deg, #0D9488, #14B8A6);
  box-shadow: 0 0 6px rgba(20,184,166,0.5);
}
.gamif-counter {
  display: flex; align-items: baseline; gap: 6px; margin: 5px 0 3px;
  padding: 5px 0; border-top: 1px solid #F1F5F9;
}
.gamif-label  { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.gamif-num    { font-size: 17px; font-weight: bold; color: var(--primary); font-variant-numeric: tabular-nums; }
.gamif-date   { font-size: 10px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.gamif-system .gamif-num  { font-size: 14px; color: #64748B; }
.gamif-system .gamif-label { color: #94A3B8; }
.gamif-comment {
  font-size: 12px; color: var(--primary-dark); background: #F0FDF9;
  border-left: 3px solid var(--primary); padding: 6px 10px; border-radius: 0 6px 6px 0;
  margin: 4px 0 6px; animation: fadeInUp 0.4s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Status Card ── */
#status-card   { border-left: 4px solid var(--primary) !important; background: #F0FDF9 !important; }
#status-step   { font-weight: bold; color: var(--primary); }
#status-user   { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--primary-light); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 6px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Action Buttons (通常の横長ボタン) ── */
.action-btn { display: block; width: 100%; padding: 12px 16px; border: none; border-radius: 25px; font-size: 13px; font-family: inherit; cursor: pointer; text-align: left; font-weight: bold; transition: all 0.2s; }
.action-btn-primary   { background: linear-gradient(135deg, var(--primary), #14B8A6); color: white; box-shadow: 0 2px 8px rgba(15,118,110,0.3); }
.action-btn-primary:hover:not(:disabled)   { box-shadow: 0 4px 14px rgba(15,118,110,0.4); transform: translateY(-1px); }
.action-btn-secondary { background: white; color: var(--primary); border: 1.5px solid var(--primary) !important; }
.action-btn-secondary:hover:not(:disabled) { background: var(--primary-light); }
.action-btn:disabled  { opacity: 0.5; cursor: not-allowed; transform: none !important; }
#actions-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Type Toggle ── */
.type-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.type-btn {
  flex: 1; padding: 6px 4px; border: 1.5px solid var(--border); border-radius: 20px;
  background: white; color: var(--text-muted); font-size: 11px; font-family: inherit;
  cursor: pointer; font-weight: 500; transition: all 0.15s;
}
.type-btn:hover { border-color: var(--primary); color: var(--primary); }
.type-btn.active { background: var(--primary); color: white; border-color: var(--primary); font-weight: bold; }

/* ── Icon Action Buttons (丸いアイコンボタン) ── */
.card-divider { border: none; border-top: 1px solid var(--border); margin: 12px 0 10px; }
.icon-btn-row { display: flex; gap: 12px; justify-content: center; padding: 4px 0 2px; }
/* ツールチップ付きラッパー */
.icon-btn-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.icon-btn-tooltip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: #1E293B; color: white; font-size: 11px; line-height: 1.6;
  padding: 8px 12px; border-radius: 8px; white-space: normal;
  width: 240px; text-align: center; z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
}
.icon-btn-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #1E293B;
}
.icon-action-btn {
  width: 80px; height: 80px;
  border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 0; text-align: center; font-family: inherit;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}
.icon-action-btn:hover:not(:disabled) { transform: scale(1.08); }
.icon-action-btn:active:not(:disabled) { transform: scale(0.96); }
.icon-action-primary {
  background: linear-gradient(135deg, var(--primary), #14B8A6);
  color: white; border: none;
  box-shadow: 0 3px 10px rgba(15,118,110,0.35);
}
.icon-action-primary:hover:not(:disabled) { box-shadow: 0 6px 16px rgba(15,118,110,0.45); }
.icon-action-secondary {
  background: white; color: var(--primary);
  border: 2px solid var(--primary) !important;
  box-shadow: 0 2px 6px rgba(15,118,110,0.12);
}
.icon-action-secondary:hover:not(:disabled) { background: var(--primary-light); }
.icon-btn-icon  { font-size: 24px; line-height: 1; }
.icon-btn-label { font-size: 10px; font-weight: bold; line-height: 1.3; }

/* ── Error Badge ── */
#error-badge { background: var(--danger-light); color: var(--danger); border: 1px solid #FECACA; border-radius: 8px; padding: 10px 14px; cursor: pointer; font-weight: bold; font-size: 12px; }
#error-badge:hover { background: #FEE2E2; }

/* ── Right panel tabs ── */
#right-tab-bar { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.right-tab-btn { flex: 1; padding: 10px 6px; background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; font-size: 12px; font-family: inherit; color: var(--text-muted); font-weight: 500; transition: color 0.15s, border-color 0.15s; }
.right-tab-btn:hover { color: var(--primary); }
.right-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: bold; }
#chat-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#log-panel  { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }

/* ── Chat (LINE-style) ── */
#chat-messages  { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 10px; background: #D8EAF5; }
.chat-row       { display: flex; align-items: flex-end; gap: 6px; }
.chat-row-agent { flex-direction: row; }
.chat-row-user  { flex-direction: row-reverse; }
.chat-icon      { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
.chat-icon-agent { background: #0F766E; }
.chat-icon-user  { background: #4ADE80; }
.chat-body      { display: flex; flex-direction: column; max-width: 75%; }
.chat-body-agent { align-items: flex-start; }
.chat-body-user  { align-items: flex-end; }
.chat-sender    { font-size: 10px; color: #4B5563; margin-bottom: 3px; font-weight: 500; }
.chat-bubble    { padding: 9px 12px; font-size: 12px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.chat-bubble-agent { background: white; border: 1px solid #D1D5DB; border-radius: 2px 14px 14px 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.chat-bubble-user  { background: #C7F2A0; border-radius: 14px 2px 14px 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.chat-time      { font-size: 10px; color: #6B7280; margin-top: 3px; }

/* ── Work Progress (in progress card) ── */
.wp-divider  { border: none; border-top: 1px solid var(--border); margin: 10px 0 8px; }
.wp-title    { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.wp-user     { font-size: 11px; font-weight: bold; color: var(--primary); margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wp-bar-wrap { background: #F1F5F9; border-radius: 100px; height: 5px; overflow: hidden; margin-bottom: 4px; }
.wp-fill     { background: linear-gradient(90deg, var(--primary), #14B8A6); height: 100%; border-radius: 100px; transition: width 0.3s ease; }
.wp-stage    { font-size: 10px; color: var(--text-muted); }

/* ── Modals ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: white; border-radius: 12px; width: 90%; max-width: 540px; max-height: 82vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { padding: 16px 20px; font-weight: bold; font-size: 15px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header button { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-header button:hover { color: var(--text); }

/* ── Settings Tabs ── */
.tab-bar { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; background: #F8FAFC; flex-shrink: 0; }
.tab-btn { padding: 10px 14px; border: none; background: none; font-size: 12px; cursor: pointer; white-space: nowrap; color: var(--text-muted); border-bottom: 2px solid transparent; font-family: inherit; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: bold; }
#tab-content { padding: 20px; overflow-y: auto; flex: 1; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: bold; color: var(--text-muted); margin-bottom: 6px; }
.form-input { width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; outline: none; }
.form-input:focus { border-color: var(--primary); }
.save-btn { background: var(--primary); color: white; border: none; border-radius: 8px; padding: 9px 20px; font-size: 13px; cursor: pointer; font-family: inherit; }
.save-btn:hover { background: var(--primary-dark); }
.save-status { margin-top: 10px; font-size: 12px; padding: 8px 12px; border-radius: 6px; display: none; }
.save-ok  { display: block; background: #D1FAE5; color: #065F46; }
.save-err { display: block; background: var(--danger-light); color: var(--danger); }

/* ── Error Modal List ── */
#error-list-content { padding: 16px; overflow-y: auto; flex: 1; }
.error-item { background: white; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.error-item-name { font-weight: bold; margin-bottom: 3px; }
.error-item-type   { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.error-item-detail { font-size: 11px; color: var(--danger); background: var(--danger-light); border-radius: 4px; padding: 4px 8px; margin-bottom: 8px; word-break: break-all; }
.error-item-btns { display: flex; gap: 8px; }
.err-retry-btn   { background: var(--primary); color: white; border: none; border-radius: 6px; padding: 6px 12px; font-size: 12px; cursor: pointer; font-family: inherit; }
.err-retry-btn:hover   { background: var(--primary-dark); }
.err-dismiss-btn { background: var(--border); color: var(--text); border: none; border-radius: 6px; padding: 6px 12px; font-size: 12px; cursor: pointer; font-family: inherit; }
.err-dismiss-btn:hover { background: #D1D5DB; }

/* ── Auth Screens ── */
#login-screen { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 3000; }
.auth-card { background: white; border-radius: 16px; padding: 36px 40px; width: 100%; max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,0.12); border-top: 4px solid var(--primary); }
.auth-logo     { font-size: 20px; font-weight: bold; color: var(--primary); text-align: center; margin-bottom: 6px; }
.auth-subtitle { font-size: 12px; color: var(--text-muted); text-align: center; margin-bottom: 24px; }
.auth-btn { width: 100%; padding: 12px; background: linear-gradient(135deg, var(--primary), #14B8A6); color: white; border: none; border-radius: 25px; font-size: 14px; font-family: inherit; font-weight: bold; cursor: pointer; margin-top: 8px; box-shadow: 0 2px 8px rgba(15,118,110,0.3); }
.auth-btn:hover:not(:disabled) { box-shadow: 0 4px 14px rgba(15,118,110,0.4); transform: translateY(-1px); }
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.auth-err { color: var(--danger); font-size: 12px; margin-top: 10px; text-align: center; min-height: 18px; }

/* ── Logout Button ── */
#logout-btn { background: none; border: 1px solid #FECACA; border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 11px; color: #DC2626; white-space: nowrap; font-family: inherit; }
#logout-btn:hover { background: #FEE2E2; }

/* ── Help Button ── */
#folder-guide-btn { background: none; border: 1px solid #BFDBFE; border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 12px; color: #2563EB; white-space: nowrap; font-family: inherit; margin-right: 6px; }
#folder-guide-btn:hover { background: #EFF6FF; }
#help-btn { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 12px; color: var(--text-muted); white-space: nowrap; font-family: inherit; margin-right: 6px; }
#help-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Help Modal ── */
.help-modal-content { background: white; border-radius: 12px; width: 82%; max-width: 540px; max-height: 82vh; display: flex; flex-direction: column; overflow: hidden; }
.help-modal-header  { padding: 14px 20px; font-weight: bold; font-size: 15px; background: var(--primary); color: white; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; border-radius: 12px 12px 0 0; }
.help-modal-header button { background: rgba(255,255,255,0.2); border: none; color: white; font-size: 16px; cursor: pointer; border-radius: 4px; padding: 2px 8px; line-height: 1; }
.help-modal-header button:hover { background: rgba(255,255,255,0.35); }

/* ── Batch Confirm Modal ── */
#batch-confirm-modal .modal-content { max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); }
#batch-confirm-modal .modal-header  { background: var(--primary); color: white; border-radius: 12px 12px 0 0; }
#batch-confirm-modal .modal-header button { color: rgba(255,255,255,0.8); }
#batch-confirm-modal .modal-header button:hover { color: white; }
.batch-confirm-body  { padding: 22px 24px; font-size: 14px; line-height: 1.9; color: var(--text); }
.batch-confirm-count { font-size: 18px; font-weight: bold; color: var(--primary); }
.batch-confirm-info  { margin-top: 14px; padding: 12px 16px; background: var(--primary-light); border-radius: 8px; border-left: 3px solid var(--primary); font-size: 13px; }
.batch-confirm-time  { font-weight: bold; color: var(--primary-dark); }
.batch-confirm-note  { margin: 6px 0 0; font-size: 12px; color: var(--text-muted); }
.batch-confirm-footer{ padding: 14px 20px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); }
.batch-btn-cancel { padding: 9px 20px; border: 1.5px solid #CBD5E1; border-radius: 8px; background: white; color: #64748B; cursor: pointer; font-size: 13px; transition: all 0.15s; }
.batch-btn-cancel:hover { border-color: #94A3B8; color: var(--text); }
.batch-btn-start  { padding: 9px 24px; border: none; border-radius: 8px; background: linear-gradient(135deg, var(--primary), #14B8A6); color: white; cursor: pointer; font-size: 13px; font-weight: bold; box-shadow: 0 2px 8px rgba(15,118,110,0.3); transition: all 0.15s; }
.batch-btn-start:hover { box-shadow: 0 4px 14px rgba(15,118,110,0.4); transform: translateY(-1px); }

/* ── Operation Log Items ── */
.log-item { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 11px; line-height: 1.5; }
.log-item.log-success { border-left: 3px solid #059669; }
.log-item.log-error   { border-left: 3px solid var(--danger); }
.log-item.log-info    { border-left: 3px solid #3B82F6; }
.log-time    { color: var(--text-muted); font-size: 10px; }
.log-content { margin-top: 2px; }
.log-icon    { margin-right: 4px; }
.log-detail  { color: var(--text-muted); font-size: 10px; margin-top: 2px; }

/* ── Loading Overlay ── */
#loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.92); display: flex; align-items: center; justify-content: center; z-index: 2000; flex-direction: column; gap: 14px; }
.loading-spinner { width: 40px; height: 40px; border: 4px solid var(--primary-light); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
.loading-text { color: var(--primary); font-weight: bold; font-size: 14px; }

/* ── 作成ルールパネル ── */
#custom-rules-panel {
  width: 100%;
  box-sizing: border-box;
}
.crp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.crp-title {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}
.crp-example-link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}
.crp-example-link:hover { text-decoration: underline; }
.crp-desc {
  font-size: 11px;
  color: #6b7280;
  margin: 0 0 8px;
  line-height: 1.5;
}
.crp-textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 80px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 10px;
  resize: vertical;
  color: #374151;
  background: #fff;
  line-height: 1.6;
}
.crp-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(20,184,166,.15);
}
.crp-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.crp-save-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.crp-save-btn:hover { opacity: 0.85; }
.crp-status { font-size: 12px; }

/* 記載例モーダル */
.rex-section { margin-bottom: 14px; }
.rex-label {
  font-weight: 700;
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 4px;
  border-left: 3px solid var(--primary);
  padding-left: 8px;
}
.rex-body {
  font-size: 12px;
  color: #374151;
  line-height: 1.8;
  background: #f8fafc;
  border-radius: 6px;
  padding: 8px 12px;
}

/* 記載例モーダルボックス */
.rex-modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 580px;
  width: 92%;
  max-height: 82vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  position: relative;
}
