/* App Shell Layout (Z0 Base Canvas) */
#app-root {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--surface-0);
  overflow: hidden;
  position: relative;
}

/* Auth / Login View Overlay */
#auth-view {
  position: fixed;
  inset: 0;
  background-color: var(--surface-0);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  width: 380px;
  background-color: var(--surface-1);
  padding: 32px;
  border-radius: var(--radius-base);
  box-shadow: var(--edge-highlight), var(--depth-shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-high);
}

.login-subtitle {
  font-size: 12px;
  color: var(--text-med);
}

/* Sidebar Navigation (Z1 Structural Panel) */
#sidebar {
  width: 300px;
  background-color: var(--surface-1);
  box-shadow: var(--edge-highlight);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  user-select: none;
  z-index: 10;
}

.sidebar-header {
  padding: 20px 20px 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.sidebar-brand-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  background-color: var(--surface-3);
  border-radius: 4px;
  color: var(--text-med);
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-low);
  padding: 16px 20px 8px 20px;
}

.contact-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-base);
  cursor: pointer;
  transition: background 0.12s ease;
  color: var(--text-med);
}

.contact-item:hover {
  background-color: var(--surface-2);
  color: var(--text-high);
}

.contact-item.active {
  background-color: var(--surface-3);
  color: var(--text-high);
  box-shadow: var(--edge-highlight);
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.contact-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.contact-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-last-msg {
  font-size: 11.5px;
  color: var(--text-low);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--status-offline);
  flex-shrink: 0;
  transition: background-color 0.2s ease;
}

.status-dot.online {
  background-color: var(--status-online);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.unread-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  background-color: var(--focal-core);
  color: #0c0f14;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--surface-1);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background-color: var(--surface-3);
  color: var(--text-high);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}

/* Main Workspace Zone (Z2 Content Viewport with strict outer margin & inner padding) */
#main-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin: 16px 16px 16px 0;
  background-color: var(--surface-2);
  border-radius: var(--radius-base);
  box-shadow: var(--edge-highlight), var(--depth-shadow);
  overflow: hidden;
  position: relative;
  max-width: 1200px;
}

/* Top Ambient Telemetry Bar */
.telemetry-bar {
  height: 52px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
  background-color: var(--surface-2);
  flex-shrink: 0;
}

.partner-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.partner-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-high);
}

.partner-meta {
  font-size: 12px;
  color: var(--text-med);
}

.ambient-status {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-med);
}

.telemetry-node {
  display: flex;
  align-items: center;
  gap: 6px;
}

.telemetry-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--status-online);
}

.telemetry-dot.syncing {
  background-color: var(--status-syncing);
}

.telemetry-dot.offline {
  background-color: var(--status-error);
}

/* Message Feed (Strict Inner Breathing Room: padding 24px 32px) */
#message-feed {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-chat-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-med);
}

.empty-chat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background-color: var(--surface-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--focal-core);
  box-shadow: var(--edge-highlight);
}

/* Message Item & Bubble Architecture (Anti-Inception) */
.message-row {
  display: flex;
  flex-direction: column;
  max-width: 820px;
  gap: 4px;
}

.message-row.incoming {
  align-self: flex-start;
}

.message-row.outgoing {
  align-self: flex-end;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-low);
  padding: 0 4px;
}

.message-sender {
  font-weight: 600;
  color: var(--text-med);
}

.message-bubble {
  padding: 12px 18px;
  border-radius: var(--radius-base);
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  box-shadow: var(--edge-highlight);
}

.message-row.incoming .message-bubble {
  background-color: var(--surface-1);
  color: var(--text-high);
  border-top-left-radius: 2px;
}

.message-row.outgoing .message-bubble {
  background-color: var(--surface-3);
  color: var(--text-high);
  border-top-right-radius: 2px;
}

.message-status {
  font-size: 10px;
  color: var(--text-low);
  margin-left: 4px;
}

/* Attachments inside Messages */
.attachment-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.attachment-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background-color: hsla(var(--base-h), var(--base-s), 8%, 0.6);
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
}

.attachment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.attachment-icon {
  color: var(--focal-core);
  font-weight: 700;
  font-size: 11px;
}

.attachment-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.attachment-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Inline Markdown Render Box */
.inline-md-box {
  margin-top: 10px;
  padding: 14px 18px;
  background-color: var(--surface-0);
  border-radius: 6px;
  border: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
  max-height: 380px;
  overflow-y: auto;
}

/* Bottom Input Zone */
.chat-input-zone {
  padding: 16px 32px 24px 32px;
  background-color: var(--surface-2);
  border-top: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

/* Attachment Staging Area */
#staging-area {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.staged-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background-color: var(--surface-1);
  border: 1px solid var(--surface-3);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-high);
}

.staged-remove {
  cursor: pointer;
  color: var(--text-low);
  font-weight: bold;
}
.staged-remove:hover {
  color: var(--status-error);
}

.input-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.typing-indicator {
  font-size: 11.5px;
  color: var(--text-low);
  min-height: 16px;
  font-style: italic;
}

/* Document Inspector Modal / Split Pane */
#doc-inspector {
  position: fixed;
  inset: 0;
  background-color: rgba(12, 15, 20, 0.85);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 40px;
}

.doc-inspector-card {
  width: 1000px;
  max-width: 90vw;
  height: 85vh;
  background-color: var(--surface-2);
  border-radius: var(--radius-base);
  box-shadow: var(--edge-highlight), var(--depth-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.doc-inspector-header {
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
  background-color: var(--surface-1);
}

.doc-inspector-body {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
  background-color: var(--surface-2);
}

/* Command Palette (L3 Hotkey Ctrl+K) */
#command-palette {
  position: fixed;
  inset: 0;
  background-color: rgba(12, 15, 20, 0.8);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
  z-index: 600;
}

.palette-card {
  width: 540px;
  background-color: var(--surface-1);
  border-radius: var(--radius-base);
  box-shadow: var(--edge-highlight), var(--depth-shadow);
  overflow: hidden;
}

.palette-input-box {
  padding: 16px;
  border-bottom: 1px solid hsla(var(--base-h), 20%, 100%, 0.04);
}

.palette-results {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
}

.palette-item {
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-med);
}

.palette-item.active, .palette-item:hover {
  background-color: var(--surface-3);
  color: var(--text-high);
}

/* Toast Undo Notification */
#toast-undo {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--surface-3);
  color: var(--text-high);
  padding: 12px 20px;
  border-radius: var(--radius-base);
  box-shadow: var(--edge-highlight), var(--depth-shadow);
  display: none;
  align-items: center;
  gap: 16px;
  z-index: 800;
  font-size: 13px;
}

/* Short Dropzone overlay */
.dropzone-overlay {
  position: absolute;
  inset: 0;
  background-color: hsla(var(--base-h), var(--base-s), 10%, 0.92);
  border: 2px dashed var(--focal-core);
  border-radius: var(--radius-base);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 50;
  pointer-events: none;
}
