/* SafeHarbor — unified messaging shell */

:root {
  --sh-bg:           #1a2f3d;
  --sh-surface:      #213648;
  --sh-surface-lift: rgba(255,255,255,0.06);
  --sh-border:       rgba(160, 200, 180, 0.18);
  --sh-divider:      rgba(160, 200, 180, 0.12);
  --sh-text:         #f0f4f8;
  --sh-text-soft:    rgba(210, 225, 215, 0.6);
  --sh-accent-safe:  #5a9e8a;
  --sh-accent-peace: #7ab8a0;
  --sh-flag-red:     #fb7185;
  --sh-gold:         #d4a63e;
  --sh-btn:          #4a7c6b;
  --sh-btn-hover:    #5a9e8a;
  --sh-white-glass:  rgba(255,255,255,0.06);
}

.sh-body {
  background: var(--sh-bg);
  color: var(--sh-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.sh-root {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.sh-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--sh-border);
  flex-shrink: 0;
  background: var(--sh-surface);
}

.sh-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.sh-brand {
  font-family: Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}

.sh-brand-safe {
  color: #ffffff;
}

.sh-brand-harbor {
  color: #5a9e8a;
}

.sh-party {
  font-size: 14px;
  color: var(--sh-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sh-header-right {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.sh-export-btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--sh-border);
  background: var(--sh-white-glass);
  color: var(--sh-text-soft);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}

.sh-export-btn:hover:not(:disabled) {
  background: var(--sh-surface-lift);
  border-color: rgba(160, 200, 180, 0.3);
  color: var(--sh-text);
}

.sh-export-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 3-column layout — wider left column, narrower variants */
.sh-body-cols {
  display: grid;
  grid-template-columns: 290px 1fr 0.8fr;
  overflow: hidden;
  height: 100%;
}

/* Left column */
.sh-left-col {
  background: var(--sh-surface);
  border-right: 1px solid var(--sh-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Delivery rules in left column */
.sh-delivery-rules {
  padding: 16px;
  border-bottom: 1px solid var(--sh-divider);
  flex-shrink: 0;
}

.sh-delivery-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sh-text-soft);
  margin-bottom: 6px;
}

.sh-delivery-body {
  font-size: 11px;
  color: var(--sh-text-soft);
  line-height: 1.5;
}

/* Rules section (removed from right column) */
#shVariantsPanel .sh-rules {
  display: none;
}

.sh-rule {
  font-size: 11px;
  color: var(--sh-text-soft);
  line-height: 1.5;
}

.sh-rule strong {
  color: var(--sh-text);
  font-weight: 600;
}

.sh-thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sh-thread-list-loading,
.sh-thread-list-error,
.sh-thread-list-empty {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--sh-text-soft);
}

.sh-thread-list-error-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.sh-thread-list-error-btn {
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid var(--sh-border);
  background: var(--sh-white-glass);
  color: var(--sh-text-soft);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}

.sh-thread-list-error-btn:hover {
  background: var(--sh-surface-lift);
  border-color: var(--sh-accent-safe);
  color: var(--sh-text);
}

.sh-thread-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--sh-divider);
  transition: background 0.12s;
}

.sh-thread-item:hover {
  background: var(--sh-surface-lift);
}

.sh-thread-item.active {
  background: rgba(90, 158, 138, 0.12);
  border-left: 2px solid var(--sh-accent-safe);
}

.sh-thread-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sh-text);
  margin-bottom: 2px;
}

.sh-thread-item-date {
  font-size: 11px;
  color: var(--sh-text-soft);
}

.sh-new-btn {
  margin: 0 12px 12px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--sh-accent-safe);
  background: transparent;
  color: var(--sh-accent-safe);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: calc(100% - 24px);
  transition: all 0.12s;
  font-family: inherit;
}

.sh-new-btn:hover:not(:disabled) {
  background: rgba(90, 158, 138, 0.12);
  border-color: var(--sh-accent-safe);
  color: var(--sh-text);
}

.sh-new-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Center column */
.sh-center-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.sh-thread-col {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.sh-thread-col::-webkit-scrollbar {
  width: 4px;
}

.sh-thread-col::-webkit-scrollbar-thumb {
  background: rgba(160, 200, 180, 0.25);
  border-radius: 4px;
}

.sh-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--sh-text-soft);
  text-align: center;
  padding: 40px 20px;
}

/* Messages */
.sh-msg {
  display: flex;
  flex-direction: column;
  max-width: 68%;
  word-wrap: break-word;
}

.sh-msg.outgoing {
  align-self: flex-end;
  align-items: flex-end;
}

.sh-msg.incoming {
  align-self: flex-start;
  align-items: flex-start;
}

.sh-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  position: relative;
}

.sh-msg.outgoing .sh-bubble {
  background: var(--sh-btn);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}

.sh-msg.incoming .sh-bubble {
  background: var(--sh-surface-lift);
  border: 1px solid var(--sh-border);
  color: var(--sh-text);
  border-radius: 16px 16px 16px 4px;
}

/* Metadata (timestamp, read marker, countdown) */
.sh-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--sh-text-soft);
  display: flex;
  gap: 8px;
  align-items: center;
}

.sh-read-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sh-accent-safe);
  display: inline-block;
}

.sh-countdown {
  color: var(--sh-gold);
  font-size: 11px;
  font-weight: 500;
}

/* Right column */
.sh-variants-col {
  background: var(--sh-surface);
  border-left: 1px solid var(--sh-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 12px;
  min-height: 200px;
}

.sh-variants-col::-webkit-scrollbar {
  width: 4px;
}

.sh-variants-col::-webkit-scrollbar-thumb {
  background: rgba(160, 200, 180, 0.25);
  border-radius: 4px;
}

.sh-variants-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.sh-variant-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(232, 238, 246, 0.6);
  margin-bottom: 2px;
}

.sh-variant-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(96, 165, 250, 0.15);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  transition: all 0.12s;
  min-height: auto;
}

.sh-variant-box:hover {
  background: rgba(96, 165, 250, 0.08);
  border-color: rgba(96, 165, 250, 0.25);
}

.sh-variant-label {
  font-weight: 700;
  font-size: 13px;
  color: #e8eef6;
}

.sh-variant-desc {
  font-size: 11px;
  color: rgba(232, 238, 246, 0.6);
  font-weight: 500;
}

.sh-variant-content {
  font-size: 12px;
  color: rgba(232, 238, 246, 0.5);
  line-height: 1.4;
  flex: 1;
  overflow-y: auto;
  max-height: 50px;
  white-space: pre-wrap;
  word-break: break-word;
}

.sh-variant-content.working {
  font-style: italic;
  color: rgba(232, 238, 246, 0.4);
}

.sh-variant-box .sh-variant-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.sh-variant-btn {
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid rgba(96, 165, 250, 0.2);
  background: rgba(96, 165, 250, 0.08);
  color: rgba(232, 238, 246, 0.7);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
}

.sh-variant-btn:hover:not(:disabled) {
  background: rgba(96, 165, 250, 0.15);
  border-color: rgba(96, 165, 250, 0.3);
  color: #e8eef6;
}

.sh-variant-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Compose area — auto-expands as user types */
.sh-compose {
  border-top: 1px solid var(--sh-border);
  background: var(--sh-surface);
  padding: 16px 20px;
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 50vh;
  width: 100%;
  box-sizing: border-box;
  position: relative;
}

.sh-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: ns-resize;
  background: transparent;
  border-top: 2px solid rgba(96, 165, 250, 0.3);
  transition: border-color 0.2s;
  z-index: 10;
}

.sh-resize-handle:hover {
  border-top-color: rgba(96, 165, 250, 0.6);
  background: rgba(96, 165, 250, 0.1);
}

/* Hide duplicate delivery card in compose area (we have it in left column) */
.sh-compose-wrap .mc-delivery-card {
  display: none;
}

.sh-compose-wrap {
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

/* MessageComposer overrides (scoped to compose wrapper) */
.sh-compose-wrap {
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-root {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-compose-and-variants {
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-compose-left {
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-textarea {
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-delivery-card {
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-moderation-card {
  width: 100%;
  box-sizing: border-box;
}

.sh-compose-wrap .mc-moderation-card {
  background: var(--sh-white-glass);
  border: 1px solid var(--sh-border);
  border-radius: 8px;
  padding: 12px;
}

.sh-compose-wrap .mc-mod-icon {
  font-size: 16px;
}

.sh-compose-wrap .mc-mod-title {
  font-weight: 600;
  color: var(--sh-text);
  font-size: 13px;
}

.sh-compose-wrap .mc-mod-reason {
  color: var(--sh-text-soft);
  font-size: 12px;
  margin-top: 4px;
}

.sh-compose-wrap .mc-mod-rewrite {
  margin-top: 8px;
}

.sh-compose-wrap .mc-mod-rewrite-label {
  color: var(--sh-text-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 4px;
}

.sh-compose-wrap .mc-mod-rewrite-text {
  background: rgba(255,255,255,0.04);
  padding: 8px;
  border-radius: 4px;
  color: var(--sh-text);
  font-size: 12px;
  line-height: 1.5;
}

.sh-compose-wrap .mc-mod-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.sh-compose-wrap .mc-delivery-card {
  background: var(--sh-white-glass);
  border: 1px solid var(--sh-border);
  border-radius: 8px;
  padding: 12px;
}

.sh-compose-wrap .mc-delivery-title {
  font-weight: 600;
  color: var(--sh-text);
  font-size: 13px;
  margin-bottom: 6px;
}

.sh-compose-wrap .mc-delivery-body {
  color: var(--sh-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.sh-compose-wrap .mc-compose-and-variants {
  display: flex;
  flex-direction: row;
  gap: 12px;
  align-items: flex-start;
}

.sh-compose-wrap .mc-compose-left {
  flex: 1;
  min-width: 0;
}

.sh-compose-wrap .mc-compose-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sh-compose-wrap .mc-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--sh-text);
}

.sh-compose-wrap .mc-textarea {
  background: var(--sh-surface-lift);
  border: 1px solid var(--sh-border);
  border-radius: 6px;
  color: var(--sh-text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 100px;
}

.sh-compose-wrap .mc-textarea::placeholder {
  color: var(--sh-text-soft);
}

.sh-compose-wrap .mc-textarea:focus {
  outline: none;
  border-color: var(--sh-accent-safe);
  background: rgba(160, 200, 180, 0.08);
}

.sh-compose-wrap .mc-char-count {
  font-size: 11px;
  color: var(--sh-text-soft);
  text-align: right;
}

/* Hide assist guide in both compose area and variants panel, but keep variant cards visible */
.sh-compose-wrap .mc-assist-section {
  display: none;
}

/* Hide guide in variants panel; show only when variants exist */
#shVariantsPanel .mc-assist-guide {
  display: none;
}

/* Show variant cards when they're added to variants panel */
#shVariantsPanel .mc-variant {
  display: block;
}

.sh-compose-wrap .mc-assist-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--sh-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.sh-compose-wrap .mc-assist-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sh-compose-wrap .mc-variant {
  background: var(--sh-white-glass);
  border: 1px solid var(--sh-border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.12s;
}

.sh-compose-wrap .mc-variant:hover {
  background: var(--sh-surface-lift);
  border-color: var(--sh-accent-safe);
}

.sh-compose-wrap .mc-variant-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sh-text-soft);
  margin-bottom: 4px;
}

.sh-compose-wrap .mc-variant-desc {
  font-size: 12px;
  color: var(--sh-text);
  line-height: 1.5;
  margin-bottom: 6px;
}

.sh-compose-wrap .mc-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sh-compose-wrap .mc-btn-primary,
.sh-compose-wrap .mc-btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--sh-border);
  background: var(--sh-white-glass);
  color: var(--sh-text-soft);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}

.sh-compose-wrap .mc-btn-primary {
  background: var(--sh-btn);
  color: #fff;
  border-color: transparent;
}

.sh-compose-wrap .mc-btn-primary:hover:not(:disabled) {
  background: var(--sh-btn-hover);
}

.sh-compose-wrap .mc-btn:hover:not(:disabled) {
  background: var(--sh-surface-lift);
  border-color: var(--sh-accent-safe);
  color: var(--sh-text);
}

.sh-compose-wrap .mc-btn:disabled,
.sh-compose-wrap .mc-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mode-specific accent color */
.mode-peace {
  --sh-accent-safe: var(--sh-accent-peace);
}

/* ── Constrain flagged overlay to bubble width ── */
.sh-msg.incoming {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.sh-msg.incoming .ifd-flagged-wrap {
  max-width: 68%;
  width: auto;
  display: block;
}

/* ── Message bubble width fix ── */
.sh-bubble {
  max-width: 68%;
}

.sh-msg.outgoing {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ── Incoming bubble width fix ── */
.sh-msg.incoming .ifd-flagged-wrap,
.sh-msg.incoming .ifd-bubble {
  max-width: 100%;
  width: auto;
}

.sh-msg.incoming {
  max-width: 68%;
  align-self: flex-start;
}

.sh-msg.outgoing {
  max-width: 68%;
  align-self: flex-end;
}

/* ── Compose width matches outgoing bubble ── */

/* Mobile */
@media (max-width: 899px) {
  .sh-body-cols {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .sh-left-col {
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--sh-border);
  }
  .sh-variants-col {
    max-height: 280px;
    border-left: none;
    border-top: 1px solid var(--sh-border);
    padding: 16px;
    justify-content: flex-start;
  }
  .sh-compose-wrap .mc-compose-and-variants {
    flex-direction: column;
  }

  .sh-compose-wrap .mc-assist-section {
    width: 100%;
    flex-shrink: 1;
  }

  .mc-variant-mobile {
    cursor: pointer;
  }

  .mc-variant-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .mc-variant-chevron {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--sh-text-soft);
  }
}

.mc-btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  background: var(--sh-white-glass);
  border: 1px solid var(--sh-border);
  border-radius: 4px;
  color: var(--sh-text-soft);
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
  font-weight: 500;
}

.mc-btn-sm:hover:not(:disabled) {
  background: var(--sh-surface-lift);
  border-color: var(--sh-accent-safe);
  color: var(--sh-text);
}

.mc-btn-sm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
