/* ─── Layout System ─── */

/* ═══ App Shell ═══ */
.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: var(--space-2);
  gap: var(--space-2);
  overflow: hidden;
}

/* ═══ App Header ═══ */
.app-header {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 0.4rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-logo {
  height: 30px;
  width: auto;
  flex-shrink: 0;
}

.app-logo-fallback {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.app-title-group {
  display: flex;
  flex-direction: column;
}

.app-title-group h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-main);
}

.app-title-group .app-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.app-credit {
  font-size: 0.625rem;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* ═══ Connection bar wrapper (collapsible) ═══ */
.connection-bar-wrapper {
  position: relative;
}

.connection-bar-wrapper.collapsed {
  display: none;
}

.connection-bar-toggle {
  width: 100%;
  height: 18px;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  background: var(--bg-panel);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  padding: 0;
  transition: color 0.15s, background 0.15s;
}

.connection-bar-toggle:hover {
  color: var(--primary);
  background: var(--bg-subtle);
}

.connection-bar-toggle svg {
  transition: transform 0.25s ease;
}

.connection-bar-toggle.collapsed svg {
  transform: rotate(180deg);
}

/* ═══ Connection panel ═══ */
.connection-panel-multi {
  grid-template-columns: auto 1.4fr 1fr 1fr 1fr auto;
}

.connection-panel {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 0.5rem 0.75rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: auto 1.5fr 1fr 1fr auto;
  gap: var(--space-2);
  align-items: end;
}

.connection-panel label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.connection-panel input,
.connection-panel select {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.6rem;
  font-size: 0.875rem;
  outline: none;
  background: var(--bg-subtle);
  min-height: 34px;
}

.connection-panel input:focus,
.connection-panel select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background: #fff;
}

/* ═══ Type bar ═══ */
.type-bar {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 0.35rem 0.75rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  display: none;
  align-items: center;
  gap: var(--space-2);
}

.type-bar.visible {
  display: flex;
  flex-wrap: wrap;
}

.type-bar label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.type-bar select {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.6rem;
  font-size: 0.875rem;
  outline: none;
  background: var(--bg-subtle);
  flex: 1;
  max-width: 300px;
  min-height: 34px;
}

.type-bar select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background: #fff;
}

.connection-info-card {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.94));
  color: #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 0.5rem 0.75rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) auto auto auto;
  gap: var(--space-2);
  align-items: center;
}

.connection-info-card strong {
  display: block;
  font-size: 0.95rem;
}

.connection-info-card div {
  font-size: 0.78rem;
}

.connection-info-card #connection-card-client-name {
  color: #94a3b8;
  margin-top: 2px;
}

.connection-info-card #connection-card-mode,
.connection-info-card #connection-card-plugin-version {
  justify-self: start;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-pill);
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.sync-btns {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ═══ Main Canvas (3-column layout) ═══ */
.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) 380px;
  gap: var(--space-3);
  min-height: 0;
}

.app-body.no-alice {
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
}

/* Columns */
.sidebar-app-col {
  min-height: 0;
}

.main-canvas {
  min-height: 0;
}

.copilot-panel {
  min-height: 0;
}

/* ═══ Settings overlay + drawer ═══ */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.settings-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 901;
  width: 520px;
  max-width: 92vw;
  background: #fff;
  box-shadow: -8px 0 30px rgba(15, 23, 42, 0.15);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.settings-drawer.open {
  transform: translateX(0);
}

.settings-drawer-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.settings-drawer-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.settings-drawer-body {
  flex: 1;
  overflow: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.settings-section h3 {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.settings-field label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.settings-field input,
.settings-field select {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
  outline: none;
  background: var(--bg-subtle);
  min-height: 34px;
}

.settings-field input:focus,
.settings-field select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background: #fff;
}

.settings-field .field-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.settings-field .field-help {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Checkbox aligned on a single row */
.settings-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-checkbox-row input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
}

.settings-checkbox-row label {
  font-size: 0.8125rem;
  color: var(--text-main);
  font-weight: 400;
  cursor: pointer;
}

/* Textarea */
.settings-field textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 0.5rem 0.6rem;
  font-size: 0.8125rem;
  outline: none;
  background: var(--bg-subtle);
  min-height: 80px;
  font-family: var(--font-mono);
  resize: vertical;
}

.settings-field textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background: #fff;
}

/* Pill toggles for post type visibility */
.settings-pill-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-pill-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-muted);
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}

.settings-pill-toggle.on {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: #bbf7d0;
}

.settings-pill-toggle:hover {
  border-color: var(--primary);
}

.settings-drawer-footer {
  padding: 0.6rem var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ═══ Site Manager ═══ */
.site-picker {
  display: flex;
  gap: var(--space-2);
  align-items: end;
}

.site-picker select {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.6rem;
  font-size: 0.875rem;
  outline: none;
  background: var(--bg-subtle);
  flex: 1;
}

.site-picker select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background: #fff;
}

.site-manager-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.site-manager-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 0.8125rem;
}

.site-manager-item .site-info { flex: 1; min-width: 0; }
.site-manager-item .site-name { font-weight: 500; }
.site-manager-item .site-url { font-size: 0.7rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-manager-item .site-actions { display: flex; gap: var(--space-1); }

.site-manager-item button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--space-1);
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
}

.site-manager-item button:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.site-manager-item button.delete-site:hover {
  color: var(--danger);
}

/* ═══ Responsive ═══ */
@media (max-width: 1200px) {
  .app-body {
    grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
  }
  .alice-sidebar-col { display: none; }
}

@media (max-width: 900px) {
  .connection-panel { grid-template-columns: 1fr; }
  .connection-info-card { grid-template-columns: 1fr; }
  .app-body { grid-template-columns: 1fr; }
}

/* ═══ Settings drawer subtitle ═══ */
.settings-drawer-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ═══ Settings mode tabs ═══ */
.settings-mode-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.settings-mode-tab {
  flex: 1;
  border: none;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.settings-mode-tab + .settings-mode-tab {
  border-left: 1px solid var(--border-subtle);
}

.settings-mode-tab.active {
  background: var(--primary);
  color: #fff;
}

.settings-mode-tab:hover:not(.active) {
  background: var(--bg-muted);
  color: var(--text-main);
}

/* ═══ Settings mode forms ═══ */
.settings-mode-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.field-hint-inline {
  font-size: 0.65rem;
  color: var(--text-faint);
  font-weight: 400;
}

/* ═══ Settings status card ═══ */
.settings-status-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}

.settings-status-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: 3px 0;
  font-size: 0.78rem;
}

.settings-status-label {
  color: var(--text-muted);
  font-weight: 500;
  min-width: 70px;
  flex-shrink: 0;
}

.settings-status-value {
  color: var(--text-main);
  word-break: break-all;
}

.settings-status-url {
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

/* Status indicator variants */
.settings-status-connected {
  color: var(--success);
  font-weight: 600;
}

.settings-status-failed {
  color: var(--danger);
  font-weight: 600;
}

.settings-status-pending {
  color: var(--text-muted);
}

/* ═══ Settings diagnostics ═══ */
.settings-diagnostics-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-diag-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 3px 0;
  font-size: 0.78rem;
  color: var(--text-main);
}

.settings-diag-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

.settings-diag-icon.check { color: var(--success); }
.settings-diag-icon.warn  { color: #d97706; }
.settings-diag-icon.error { color: var(--danger); }
.settings-diag-icon.na    { color: var(--text-faint); }

/* ═══ Settings feature badges ═══ */
.settings-feature-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.settings-feature-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.settings-feature-pill.on {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: #bbf7d0;
}

.settings-feature-pill.off {
  background: var(--bg-muted);
  color: var(--text-faint);
}

/* ═══ Settings actions row ═══ */
.settings-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ═══ Settings error display ═══ */
.settings-error-display {
  padding: var(--space-2) var(--space-3);
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  border: 1px solid #fecaca;
}

/* ═══ Settings status badge ═══ */
.settings-status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-muted);
  color: var(--text-muted);
}

/* ═══ Settings warnings ═══ */
.settings-warning {
  padding: var(--space-2) var(--space-3);
  background: var(--warning-bg);
  color: var(--warning-text);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  margin-top: var(--space-1);
}

/* ═══ Settings section dividers ═══ */
.settings-section + .settings-section {
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}

.admin-badge {
  display: none;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 600;
}

.admin-badge.active,
.btn-admin-exit.active {
  display: inline-flex;
}

.btn-admin-exit {
  display: none;
}

.hidden-by-admin-curtain {
  display: none !important;
}

.app-logo-trigger {
  border: 0;
  cursor: pointer;
  background: none;
  padding: 0;
}

.app-logo {
  height: 38px;
  width: auto;
}

.admin-unlock-error {
  min-height: 1.2rem;
  margin-top: 0.5rem;
  color: #b42318;
  font-size: 0.8rem;
}
