/* 色は css/theme.css で一元定義（このファイルに色コードを直接書かない） */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--brand-dark); }
small { font-weight: normal; color: var(--muted); }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: ui-monospace, Consolas, monospace; }

#app { display: flex; flex-direction: column; height: 100dvh; }
#header {
  display: flex; align-items: center; gap: 8px;
  background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  flex-shrink: 0;
}
#header-logo { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; background: #fff; }
#header-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

#tabbar {
  display: flex; flex-shrink: 0;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1; position: relative; border: none; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; font-size: 10px; color: var(--muted); cursor: pointer;
}
#tabbar button.active { color: var(--brand); font-weight: 700; }
.tab-icon { font-size: 20px; }
.tab-badge {
  position: absolute; top: 2px; right: calc(50% - 22px);
  background: var(--danger); color: #fff; border-radius: 9px;
  font-size: 10px; min-width: 18px; padding: 1px 5px; text-align: center;
}

/* ---- 汎用 ---- */
.page-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 18px; font-weight: 700; padding: 14px 16px 8px;
}
.page-title .btn { margin-left: auto; }
.card {
  background: var(--card); border-radius: 12px; padding: 16px;
  margin: 10px 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card.center { text-align: center; }
.card h4 { margin: 10px 0 8px; font-size: 14px; color: var(--brand-dark); }
.card h4:first-child { margin-top: 0; }
.loading, .empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0; line-height: 1.6; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input:not([type=checkbox],[type=radio]), .field select, .field textarea, .search-row input {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text);
}
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px !important; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: none; font-size: 18px; cursor: pointer;
  padding: 6px; opacity: .45; line-height: 1;
}
.pw-toggle.on { opacity: 1; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check input { width: 20px; height: 20px; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: 15px; }
.check-row input { width: 19px; height: 19px; }

.btn {
  display: inline-block; border: none; border-radius: 10px; cursor: pointer;
  padding: 12px 18px; font-size: 15px; font-weight: 700;
  background: #eee; color: var(--text);
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--brand-dark); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger.ghost { background: #fff; border: 1px solid var(--danger); color: var(--danger); }
.btn.block { display: block; width: 100%; margin-top: 8px; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.big { padding: 16px; font-size: 17px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.icon-btn {
  border: none; background: none; font-size: 20px; cursor: pointer;
  padding: 6px 10px; color: var(--brand-dark); flex-shrink: 0;
}
.chip {
  display: inline-block; background: var(--chat-bg); color: var(--brand-dark);
  font-size: 11px; border-radius: 8px; padding: 2px 7px; margin-left: 4px; font-weight: 600;
}
.chip.ghost { background: var(--brand-soft); color: var(--muted); }
.badge {
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 12px; min-width: 20px; padding: 2px 6px; text-align: center; display: inline-block;
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
.table th { color: var(--muted); font-size: 12px; }
.row-ng td { background: var(--danger-soft, #FCEBE8); }
.state.ok { color: var(--brand); font-weight: 700; font-size: 13px; }
.state.ng { color: var(--danger); font-weight: 700; font-size: 13px; }

/* ---- 認証 ---- */
.auth-wrap { max-width: 440px; margin: 0 auto; padding: 40px 16px; }
.auth-logo {
  text-align: center; font-size: 26px; font-weight: 800; color: var(--brand);
  margin-bottom: 8px;
}
.auth-desc { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 14px; line-height: 1.7; }
.auth-links { text-align: center; margin-top: 18px; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.org-preview {
  text-align: center; font-weight: 700; color: var(--brand-dark);
  background: var(--chat-bg); border-radius: 10px; padding: 10px; margin-bottom: 12px;
}

/* ---- グループ一覧 ---- */
.group-list { padding-bottom: 10px; }
.group-item {
  display: flex; align-items: center; gap: 12px;
  background: #fff; padding: 13px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.group-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.group-main { flex: 1; min-width: 0; }
.group-name { font-weight: 700; font-size: 15px; }
.group-last {
  font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px;
}
.group-side { text-align: right; flex-shrink: 0; }
.group-time { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

/* ---- チャットルーム ---- */
.room { display: flex; flex-direction: column; height: 100%; }
.room-header {
  display: flex; align-items: center; gap: 4px;
  background: #fff; border-bottom: 1px solid var(--line); padding: 6px 8px; flex-shrink: 0;
}
.room-title { flex: 1; min-width: 0; }
.room-name { font-weight: 700; font-size: 15px; }
.room-sub { font-size: 11px; color: var(--muted); }
.pins-bar {
  background: var(--pin-bg); border-bottom: 1px solid var(--pin-line); padding: 8px 14px;
  font-size: 13px; cursor: pointer; flex-shrink: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mode-note {
  background: var(--brand-soft); color: var(--brand-dark); font-size: 12px; padding: 7px 14px; flex-shrink: 0;
}
.msg-list { flex: 1; overflow-y: auto; padding: 12px 12px 18px; background: var(--chat-bg); }
.date-sep { text-align: center; margin: 14px 0 10px; }
.date-sep span {
  background: rgba(0,0,0,.15); color: #fff; font-size: 11px;
  border-radius: 12px; padding: 3px 12px;
}
.msg { margin-bottom: 10px; }
.msg-sender { font-size: 11px; color: var(--muted); margin: 0 0 2px 4px; }
.msg-row { display: flex; align-items: flex-end; gap: 6px; }
.msg.mine .msg-row { justify-content: flex-end; }
.bubble {
  background: #fff; border-radius: 14px; padding: 9px 12px;
  max-width: 76%; font-size: 15px; line-height: 1.55; position: relative;
  word-break: break-word; cursor: pointer;
}
.msg.mine .bubble { background: var(--mine); }
.bubble .body a { word-break: break-all; }
.bubble.stamp { background: transparent; box-shadow: none; }
.stamp-body {
  background: #fff; border: 2px solid var(--brand); color: var(--brand-dark);
  font-weight: 800; font-size: 17px; border-radius: 14px; padding: 12px 18px;
}
.msg.mine .stamp-body { background: var(--mine); }
.important-tag {
  display: inline-block; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 6px; padding: 1px 7px; margin-bottom: 4px;
}
.pin-mark { position: absolute; top: -8px; right: -4px; font-size: 13px; }
.quote {
  border-left: 3px solid var(--brand); background: rgba(0,0,0,.05);
  font-size: 12px; color: var(--muted); border-radius: 6px; padding: 5px 8px; margin-bottom: 6px;
}
.edited { font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg-meta { font-size: 10px; color: var(--muted); flex-shrink: 0; text-align: right; line-height: 1.5; }
.msg.mine .msg-meta { text-align: right; }
.msg:not(.mine) .msg-meta { text-align: left; }
.reads { color: var(--brand-dark); font-weight: 600; }
.att-image { margin-top: 6px; }
.att-image img { max-width: 100%; border-radius: 10px; display: block; cursor: pointer; }
.img-ph {
  background: var(--brand-soft); color: var(--muted); font-size: 12px;
  border-radius: 10px; padding: 26px 12px; text-align: center;
}
.img-full { max-width: 88vw; max-height: 80vh; border-radius: 8px; display: block; }
.att-file {
  display: block; background: rgba(0,0,0,.05); border-radius: 8px;
  padding: 8px 10px; margin-top: 6px; font-size: 13px; cursor: pointer;
}
.react-row { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 0 4px; }
.react-row.right { justify-content: flex-end; margin-right: 4px; }
.react-chip {
  background: #fff; border: 1px solid var(--brand); color: var(--brand-dark);
  font-size: 11px; border-radius: 10px; padding: 2px 8px; font-weight: 600;
}
.react-btn-row { margin: 4px 0 0 4px; }
.react-btn {
  border: 1px dashed var(--muted); background: none; color: var(--muted);
  font-size: 11px; border-radius: 10px; padding: 3px 10px; cursor: pointer;
}

/* ---- コンポーザー ---- */
.composer {
  background: #fff; border-top: 1px solid var(--line);
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px); flex-shrink: 0;
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea {
  flex: 1; border: 1px solid var(--line); border-radius: 18px;
  padding: 10px 14px; font-size: 16px; resize: none; max-height: 120px;
  font-family: inherit;
}
.icon-btn.send { color: var(--brand); font-size: 22px; }
.important-check { font-size: 12px; color: var(--danger); display: flex; align-items: center; gap: 5px; margin-top: 6px; }
.composer-note {
  background: #fff; border-top: 1px solid var(--line); text-align: center;
  color: var(--muted); font-size: 13px; padding: 14px;
}
.file-chip {
  display: inline-block; background: var(--brand-soft); border-radius: 8px;
  font-size: 12px; padding: 4px 8px; margin: 0 4px 6px 0;
}
.file-chip b, .quote-chip b { cursor: pointer; color: var(--danger); padding: 0 3px; }
.quote-chip {
  background: var(--brand-soft); border-radius: 8px; font-size: 12px; padding: 6px 8px; margin-bottom: 6px;
}

/* ---- モーダル ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.sheet { align-items: flex-end; padding: 0; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 18px;
  max-width: 480px; width: 100%; max-height: 82vh; overflow-y: auto;
}
.modal-overlay.sheet .modal-box { border-radius: 14px 14px 0 0; }
.modal-box h3 { font-size: 16px; margin-bottom: 12px; color: var(--brand-dark); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.confirm-msg { font-size: 15px; line-height: 1.7; }
.action-sheet { display: flex; flex-direction: column; gap: 2px; }
.sheet-btn {
  border: none; background: none; text-align: left; font-size: 16px;
  padding: 13px 8px; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--text);
}
.sheet-btn.cancel { color: var(--muted); border-bottom: none; text-align: center; }
.stamp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stamp-btn {
  border: 2px solid var(--brand); background: #fff; color: var(--brand-dark);
  font-size: 15px; font-weight: 700; border-radius: 10px; padding: 13px 6px; cursor: pointer;
}
.stamp-btn.active { background: var(--mine); }
.stamp-btn.remove { border-color: var(--muted); color: var(--muted); grid-column: span 2; }
.reads-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.reads-cols h4 { font-size: 13px; margin-bottom: 6px; color: var(--brand-dark); }
.read-row { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.read-row small { display: block; color: var(--muted); font-size: 11px; }
.search-row { display: flex; gap: 6px; margin-bottom: 12px; }
.search-item { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.pin-item { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

/* ---- 回覧板 ---- */
.circ-item {
  display: flex; align-items: center; gap: 10px;
  background: #fff; padding: 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.circ-main { flex: 1; min-width: 0; }
.circ-title { font-weight: 700; font-size: 15px; }
.circ-sub { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.circ-sub .chip { margin-left: 0; }
.deadline { color: var(--danger); font-weight: 600; }
.circ-side { text-align: right; flex-shrink: 0; }
.circ-count { font-size: 12px; color: var(--muted); margin-top: 4px; }
.circ-detail h2 { font-size: 18px; margin-bottom: 8px; }
.circ-meta { font-size: 12px; color: var(--muted); margin: 8px 0; }
.circ-body { line-height: 1.9; margin: 14px 0; white-space: normal; }
.confirm-box { margin-top: 16px; }
.confirmed-box {
  background: var(--chat-bg); color: var(--brand-dark); font-weight: 700;
  border-radius: 10px; padding: 14px; text-align: center; margin-top: 16px; line-height: 1.8;
}

/* ---- 管理 ---- */
.admin-menu { margin: 10px 12px; background: #fff; border-radius: 12px; overflow: hidden; }
.admin-menu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 15px 16px; border-bottom: 1px solid var(--line);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.admin-menu-item .arrow, .member-row .arrow { margin-left: auto; color: var(--muted); }
.member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer;
}
.member-row .muted { font-size: 12px; line-height: 1.6; }
.member-pick { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.pick-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.pick-row label { display: flex; align-items: center; gap: 7px; }
.pick-sender { color: var(--muted); font-size: 12px; }
.log-row { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.6; }
.quiet-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.quiet-row input { padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.version-footer {
  text-align: center; font-size: 12px; color: var(--muted);
  padding: 18px 0 28px; user-select: none; -webkit-user-select: none;
}

/* ---- 印刷 ---- */
.print-page { background: #fff; min-height: 100%; padding: 24px; max-width: 800px; margin: 0 auto; }
.print-bar { display: flex; gap: 8px; margin-bottom: 18px; }
.print-page h1 { font-size: 16px; margin-bottom: 6px; }
.print-page h2 { font-size: 20px; margin-bottom: 10px; }
.print-meta { font-size: 12px; color: #555; margin: 8px 0; }
.print-body { line-height: 2; margin: 16px 0; font-size: 14px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
.print-table th, .print-table td { border: 1px solid #999; padding: 6px 8px; text-align: left; }
.print-table th { background: #f0f0f0; }

@media print {
  #header, #tabbar, .no-print { display: none !important; }
  #view { overflow: visible; }
  body, .print-page { background: #fff; }
  .print-page { padding: 0; max-width: none; }
}

/* ---- トースト ---- */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(14,26,46,.92); color: #fff; font-size: 14px;
  border-radius: 20px; padding: 10px 20px; z-index: 200; max-width: 86vw;
}
#toast.error { background: rgba(200,55,45,.94); }

@media (min-width: 720px) {
  #view > .group-list, #view > .circ-list, .admin-menu { max-width: 720px; margin-left: auto; margin-right: auto; }
  .card { max-width: 720px; margin-left: auto; margin-right: auto; }
  .page-title { max-width: 720px; margin: 0 auto; }
  .room { max-width: 900px; margin: 0 auto; width: 100%; }
}
