:root {
  --border: #e5e7eb;
  --bg: #ffffff;
  --muted: #6b7280;
  --pane-bg: #fafafa;
  --att-thumb-base-size: 160px;
  --att-thumb-scale: 2;
  --att-thumb-long-side: calc(var(--att-thumb-base-size) * var(--att-thumb-scale));
  --overlay-image-gap: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
}

.app-grid {
  height: 100vh;
  display: grid;
  grid-template-columns: 15% 65% 20%;
  gap: 0;
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 10px;
}

@media (min-width: 1220px) {
  .app-grid {
    grid-template-columns: 180px 780px 240px;
  }
}

.pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--pane-bg);
  min-width: 0;
  min-height: 0;
}

#pane-search { border-right: none; }

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.app-title {
  font-size: 14px;
  margin: 0;
}

.pane-title {
  font-size: 13px;
  color: #111827;
}

.pane-actions button {
  font-size: 12px;
  padding: 6px 8px;
}

.env-badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: #fff;
  padding: 2px 6px;
  border-radius: 999px;
}

.pane-body {
  padding: 10px 12px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.feed-sentinel {
  height: 1px;
}

.msg-card {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 10px 0;
}

.msg-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  color: #111827;
}

.channel-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 8px;
  cursor: pointer;
}

.channel-item.is-active {
  outline: 2px solid #111827;
}

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

.overlay-root {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay-root:not([hidden]) {
  display: flex;            /* ←表示するときだけ flex */
}

.overlay-panel {
  width: min(900px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.overlay-tag-editor-panel {
  align-self: flex-start;
  margin-top: 24px;
  max-width: 860px;
  width: min(860px, calc(100vw - 24px));
  background: transparent;
  border: none;
  padding: 0;
}

.msg-attachments {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.att-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.att-thumb-placeholder {
  width: var(--att-thumb-long-side);
  height: var(--att-thumb-long-side);
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
}

.att-thumb-img {
  max-width: var(--att-thumb-long-side);
  max-height: var(--att-thumb-long-side);
  width: auto;
  height: auto;
  display: block;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.att-link {
  font-size: 12px;
}

.overlay-panel.overlay-image-panel {
  width: auto;
  background: transparent;
  border: none;
  padding: 0;
}

.overlay-image-frame {
  position: relative;
}

.overlay-image {
  max-width: calc(100vw - var(--overlay-image-gap));
  max-height: calc(100vh - var(--overlay-image-gap));
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid rgba(229,231,235,0.7);
  background: #fff;
}

.overlay-image-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}

.overlay-image-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;

  width: 56px;
  height: 56px;
  border-radius: 999px;
  padding: 0;

  background: rgba(0,0,0,0.45);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);

  font-size: 38px;
  line-height: 1;

  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.overlay-image-nav:hover {
  background: rgba(0,0,0,0.55);
}

.overlay-image-nav:focus-visible {
  outline: 3px solid rgba(255,255,255,0.7);
  outline-offset: 2px;
}

.overlay-image-nav.is-prev {
  left: 10px;
}

.overlay-image-nav.is-next {
  right: 10px;
}

.overlay-image-nav[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.overlay-image-counter {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  color: #fff;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.search-form {
  display: grid;
  gap: 10px;
}

.search-field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #111827;
}

.search-field input,
.search-field select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.search-actions {
  display: flex;
  gap: 8px;
}

.search-actions button {
  font-size: 12px;
  padding: 6px 10px;
}

.search-radio-group {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search-radio-option {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.search-radio-option input {
  margin: 0;
}

/* Tag index (right pane bottom) */
.tag-index {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 10px 12px;
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
}

.tag-index-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: #111827;
  margin: 0 0 8px 0;
}

.tag-index-status {
  font-size: 12px;
  color: var(--muted);
}

.tag-index-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

button.tag-chip {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
}

.tag-chip--clickable {
  cursor: pointer;
}

.tag-chip--clickable:hover {
  border-color: #9ca3af;
}

.tag-chip--clickable:focus-visible {
  outline: 2px solid #111827;
  outline-offset: 2px;
}

.msg-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  align-items: center;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #f3f4f6;
  color: #111827;
  font-size: 12px;
  line-height: 1.2;
}

/* tagEditor.js の prefix filter 用。UAの [hidden]{display:none} に依存しない（.tag-chip の display 指定に勝つため） */
.tag-chip.is-filtered-out {
  display: none !important;
}

.tag-chip.is-selected {
  border-color: #111827;
  background: #e5e7eb;
  color: #111827;
}

.tag-chip--edit {
  border-color: #9ca3af;
  font-weight: 600;
}

.msg-tags.is-editing {
  position: relative;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  flex-wrap: nowrap;
}

.tag-editor-existing-list .tag-chip.is-selected {
  background: #dbeafe;      /* light blue */
  border-color: #3b82f6;    /* blue */
  border-width: 2px;
}

.tag-editor-existing-list .tag-chip.is-selected:hover {
  border-color: #2563eb;
}

.tag-editor-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1000;
}

.tag-editor-error {
  flex-basis: 100%;
  font-size: 12px;
  line-height: 1.3;
  margin-top: 4px;
  color: #b91c1c;
}

.tag-editor-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-editor-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.tag-editor-suggest {
  display: none;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 6px;
  max-height: 240px;
  overflow: auto;
}

.tag-editor-suggest.is-open {
  display: block;
}

.tag-suggest-item {
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.tag-suggest-item:hover {
  background: #f3f4f6;
}

.tag-suggest-item.is-active {
  background: #e5e7eb;
}

/* Keep the input wide while keeping + / キャンセル / 完了 on the same row. */
.tag-editor-input-row .tag-editor-input {
  flex: 1 1 auto;
  min-width: 140px;
}

.tag-editor-buttons-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.tag-editor-radio-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}

.tag-editor-existing-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  overflow: hidden;
}

.tag-editor-existing-list .tag-index-chips {
  overflow: hidden;
}

.tag-chip.is-pending-delete {
  text-decoration: line-through;
  opacity: 0.7;
}

.msg-tags input {
  height: 28px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 12px;
}

.msg-tags .tag-editor-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.link-previews {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0;
}

.link-preview-card {
  display: flex;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: inherit;
  text-decoration: none;
}

.link-preview-card:hover {
  border-color: #9ca3af;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.link-preview-image {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.link-preview-site {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.link-preview-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  margin-bottom: 4px;
}

.link-preview-desc {
  font-size: 12px;
  color: #4b5563;
  line-height: 1.4;
}

.link-preview-embed {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  overflow-x: auto;
}

.link-preview-embed-youtube {
  padding: 6px;
}

.youtube-embed {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
}

.youtube-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
