* { box-sizing: border-box; margin: 0; padding: 0; }
:root { --brand: #3b82f6; }
html, body, #app { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 14px;
  color: #1f2937;
  background: #f3f4f6;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; }
h1 { font-size: 18px; }
h2 { font-size: 15px; margin-bottom: 12px; }

.center-page { height: 100%; display: flex; align-items: center; justify-content: center; color: #6b7280; }

/* ---- 認証 ---- */
.auth-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  padding: 32px;
  width: min(400px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: #1f2937;
}
.auth-sub { color: #6b7280; font-size: 13px; }
.auth-card label, .settings-section label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #374151; }
.auth-card input, .settings-section input:not([type="checkbox"]):not([type="radio"]), .settings-section textarea, .settings-section select,
.canned-form input, .canned-form textarea, .op-form input, .op-form select {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 10px;
}
.form-error { color: #dc2626; font-size: 13px; }
.link-btn { color: var(--brand); font-size: 13px; align-self: center; }
.link-btn:hover { text-decoration: underline; }

.primary-btn {
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}
.primary-btn:disabled { opacity: 0.6; }
.ghost-btn {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 6px 12px;
  color: #374151;
  background: #fff;
  font-size: 13px;
  flex: none;
}
.ghost-btn:hover { background: #f9fafb; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(0, 0, 0, 0.06); }

/* ---- レイアウト ---- */
.layout { height: 100%; display: flex; }
.sidebar {
  width: 340px;
  flex: none;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.side-brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.side-actions { display: flex; gap: 4px; }
.side-me { padding: 0 16px 10px; color: #6b7280; font-size: 12px; display: flex; gap: 8px; }
.online-count { color: #059669; }
.presence { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.presence.on { background: #34d399; }

.tabs { display: flex; border-bottom: 1px solid #e5e7eb; padding: 0 12px; gap: 4px; }
.tab { padding: 8px 12px; color: #6b7280; border-bottom: 2px solid transparent; font-weight: 600; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.empty-list { color: #9ca3af; text-align: center; padding: 32px 0; font-size: 13px; }
.conv-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
}
.conv-item:hover { background: #f3f4f6; }
.conv-item.selected { background: #eff6ff; }
.conv-item-main { flex: 1; min-width: 0; }
.conv-item-title { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item-time { color: #9ca3af; font-size: 11px; flex: none; }
.conv-item-preview { color: #6b7280; font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verified { color: #059669; font-size: 11px; margin-left: 4px; }

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 14px;
}

/* ---- チャット ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fff; }
.conn-banner {
  flex: none;
  text-align: center;
  font-size: 12px;
  color: #92400e;
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
  padding: 6px 12px;
  animation: conn-banner-in 0.25s ease-out;
}
@keyframes conn-banner-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.empty-main { flex: 1; display: flex; align-items: center; justify-content: center; color: #9ca3af; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  flex: none;
}
.chat-header-main { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 700; }
.chat-header-sub { color: #6b7280; font-size: 12px; }
.assign-select { border: 1px solid #d1d5db; border-radius: 8px; padding: 6px 8px; font-size: 13px; }

.stream { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 10px; background: #fafafa; }
.load-older { align-self: center; color: #6b7280; font-size: 12px; padding: 6px 12px; border-radius: 8px; background: #f3f4f6; }
.day-sep { align-self: center; color: #9ca3af; font-size: 11px; padding: 2px 10px; background: #f3f4f6; border-radius: 999px; }
.sys-msg { align-self: center; color: #6b7280; font-size: 12px; text-align: center; max-width: 90%; padding: 6px 12px; background: #f3f4f6; border-radius: 10px; }
.row { display: flex; gap: 10px; }
.row.mine { justify-content: flex-end; }
.row-main { max-width: 640px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.row.mine .row-main { align-items: flex-end; }
.row .avatar { width: 30px; height: 30px; font-size: 12px; margin-top: 16px; }
.sender-name { font-size: 11px; color: #9ca3af; }
.bubble {
  padding: 9px 13px;
  border-radius: 16px 16px 16px 4px;
  background: #eef0f3;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.row.mine .bubble { background: var(--brand); color: #fff; border-radius: 16px 16px 4px 16px; }
.row.mine .bubble a { color: #fff; }
.bubble a { color: #2563eb; }
.msg-meta { font-size: 10px; color: #9ca3af; display: flex; gap: 6px; }
.read-mark { color: #6b7280; }
.bubble.typing { display: flex; gap: 4px; padding: 12px 14px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; animation: blink 1.2s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

.att-img img { max-width: 280px; max-height: 280px; border-radius: 12px; display: block; }
.att-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #eef0f3;
  border-radius: 10px;
  color: #1f2937;
  text-decoration: none;
}
.att-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.att-file-size { color: #9ca3af; font-size: 11px; flex: none; }

/* ---- 入力欄 ---- */
.composer { flex: none; border-top: 1px solid #e5e7eb; padding: 10px 14px; background: #fff; }
.pending-atts { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #f3f4f6; border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.canned-select { border: 1px solid #d1d5db; border-radius: 8px; padding: 6px 8px; font-size: 13px; max-width: 120px; flex: none; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  outline: none;
  padding: 10px 12px;
  max-height: 140px;
  line-height: 1.5;
}
.composer textarea:focus { border-color: var(--brand); }
.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.send-btn:disabled { opacity: 0.5; cursor: default; }

/* ---- 設定 ---- */
.settings-page { height: 100%; overflow-y: auto; }
.settings-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
}
.settings-body { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; display: flex; flex-direction: column; gap: 20px; }
.settings-section { background: #fff; border-radius: 16px; padding: 20px 24px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); }
.settings-section form { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.settings-section form label { width: 100%; }
.settings-section input:not([type="checkbox"]):not([type="radio"]), .settings-section textarea { width: 100%; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.pw-row { display: flex; gap: 12px; width: 100%; }
.pw-row label { flex: 1; }

/* ウィジェットの配置設定 (左右のラジオ + 余白 + 縮小プレビュー) */
.field-group { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.field-group-title { font-size: 13px; font-weight: 600; color: #374151; }
.field-group .hint { margin: 0; }
.layout-fields { display: flex; gap: 16px; align-items: flex-end; width: 100%; flex-wrap: wrap; }
.settings-section form .radio-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; flex: 1; }
.settings-section form .radio-row label { width: auto; }
.settings-section form .radio-row label:not(.check-label) { width: 104px; }
.radio-field { display: flex; flex-direction: column; gap: 4px; }
.field-caption { font-size: 13px; color: #374151; }
/* 数値入力の高さに合わせて、キャプションの下端どうしが揃うようにする */
.radio-choices { display: flex; gap: 14px; align-items: center; min-height: 37px; }
/* 実寸 1280x800 の画面に見立てた比率でランチャーの位置を示す */
.launcher-preview {
  position: relative;
  width: 132px;
  height: 84px;
  flex: none;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
}
.launcher-preview-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; }

.embed-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid #e5e7eb; }
.embed-block h3 { font-size: 13px; margin: 12px 0 4px; }
.hint { color: #6b7280; font-size: 12px; margin-bottom: 8px; }
.code-block {
  background: #111827;
  color: #e5e7eb;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-inline {
  background: #f3f4f6;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}
.secret-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.canned-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.canned-list li { display: flex; align-items: center; gap: 12px; background: #f9fafb; border-radius: 10px; padding: 10px 14px; }
.canned-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.canned-item-main span { color: #6b7280; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canned-form { width: 100%; }
.canned-form input, .canned-form textarea { width: 100%; }

.op-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 13px; }
.op-table th { text-align: left; color: #6b7280; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid #e5e7eb; }
.op-table td { padding: 8px; border-bottom: 1px solid #f3f4f6; }
.op-table tr.inactive td { color: #9ca3af; }
.op-table select { border: 1px solid #d1d5db; border-radius: 6px; padding: 4px 6px; font-size: 12px; }
.op-actions { display: flex; gap: 6px; }
.op-form { display: flex; gap: 8px; flex-wrap: wrap; }
.op-form input { flex: 1; min-width: 140px; }

@media (max-width: 800px) {
  .sidebar { width: 280px; }
  .pw-row { flex-direction: column; }
}
