/* Maha Training — enterprise full-viewport workspace */

.maha-enterprise {
  --maha-accent: #2563eb;
  --maha-accent-soft: rgba(37, 99, 235, 0.12);
  --maha-saffron: #ff9933;
  --maha-sidebar-w: min(340px, 28vw);
  --maha-page-pad: clamp(20px, 2.4vw, 40px);
}

.maha-body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(37, 99, 235, 0.08), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(255, 153, 51, 0.05), transparent 50%),
    var(--bg);
}

.maha-app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: var(--maha-page-pad);
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2vh, 28px);
  box-sizing: border-box;
}

/* ── Top bar ── */
.maha-topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) auto auto;
  align-items: center;
  gap: clamp(16px, 2vw, 32px);
  padding: clamp(14px, 1.6vw, 22px) clamp(18px, 2vw, 28px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 16px);
  background:
    linear-gradient(135deg, rgba(255, 153, 51, 0.05), transparent 42%),
    linear-gradient(180deg, var(--surface-elevated, var(--surface2)), var(--surface));
  box-shadow: var(--shadow-md, 0 12px 32px rgba(0, 0, 0, 0.32));
}

@media (max-width: 1080px) {
  .maha-topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .maha-topbar-meta,
  .maha-topbar-actions {
    justify-self: start;
  }
}

.maha-topbar-main {
  min-width: 0;
}

.maha-breadcrumb {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.maha-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.maha-breadcrumb a:hover {
  text-decoration: underline;
}

.maha-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.maha-brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  background: linear-gradient(145deg, var(--maha-saffron), #e67300);
  box-shadow: 0 8px 20px rgba(255, 153, 51, 0.22);
}

.maha-brand h1 {
  margin: 0;
  font-size: clamp(1.25rem, 1.6vw, 1.55rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.maha-tagline {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.maha-topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 12px;
}

.maha-stat-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 108px;
  padding: 12px 16px;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
}

.maha-stat-card strong {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.maha-stat-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.maha-stat-accent {
  border-color: rgba(37, 99, 235, 0.28);
  background: var(--maha-accent-soft);
}

.maha-stat-accent strong {
  font-size: 0.82rem;
  color: var(--accent-hover, #3b82f6);
}

.maha-topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.maha-ui-lang-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 8rem;
}

.maha-ui-lang-select {
  min-width: 8rem;
  font-size: 0.875rem;
}

.maha-btn-inline {
  width: auto !important;
  margin-top: 0 !important;
  padding: 10px 18px;
  font-size: 0.875rem;
}

.maha-alert {
  flex: 0 0 auto;
  margin: 0;
}

/* ── Shell: sidebar + workspace ── */
.maha-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--maha-sidebar-w) minmax(0, 1fr);
  gap: clamp(20px, 2.2vw, 36px);
}

@media (max-width: 920px) {
  .maha-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .maha-sidebar {
    max-height: 220px;
  }
}

/* ── Sidebar ── */
.maha-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 16px);
  padding: clamp(18px, 1.8vw, 24px);
  background: var(--surface);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.28));
}

.maha-sidebar-history {
  flex-shrink: 0;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.maha-new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.maha-new-chat-btn:hover {
  border-color: var(--maha-accent);
  background: var(--maha-accent-soft);
}

.maha-recent-label {
  margin: 4px 0 6px;
  padding-left: 4px;
}

.maha-history-groups {
  max-height: min(220px, 28vh);
  overflow-y: auto;
  margin: 4px 0 8px;
  padding-right: 2px;
}

.maha-sidebar .wb-sidebar-nav-item,
.maha-sidebar .wb-history-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary, var(--muted));
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.maha-sidebar .wb-sidebar-nav-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.maha-sidebar .wb-sidebar-nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maha-sidebar .wb-sidebar-nav-desc {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
}

.maha-sidebar .wb-history-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.maha-sidebar .wb-history-item.active {
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(37, 99, 235, 0.12);
  color: var(--text);
}

.maha-sidebar .wb-history-group-label {
  margin-top: 8px;
  padding-left: 4px;
}

.maha-sidebar .wb-history-empty,
.maha-sidebar .wb-muted-hint {
  padding: 8px 4px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  margin: 0;
}

.maha-history-all-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--maha-accent);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}

.maha-history-all-link:hover {
  background: var(--maha-accent-soft);
  text-decoration: underline;
}

.maha-sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 4px;
  flex-shrink: 0;
}

.maha-nav-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0;
}

.maha-sidebar-sub {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.maha-module-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.maha-subject-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.maha-subject-list::-webkit-scrollbar {
  width: 6px;
}

.maha-subject-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.maha-subject-btn {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 12px;
  width: 100%;
  padding: 14px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.maha-subject-btn:hover {
  border-color: rgba(37, 99, 235, 0.28);
  background: var(--maha-accent-soft);
}

.maha-subject-btn.active {
  border-color: rgba(37, 99, 235, 0.45);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.14), rgba(30, 64, 175, 0.08));
}

.maha-subject-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.maha-subject-btn.active .maha-subject-btn-icon {
  background: rgba(37, 99, 235, 0.18);
  border-color: rgba(37, 99, 235, 0.35);
}

.maha-subject-btn-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
}

.maha-subject-btn-mr {
  display: block;
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.35;
}

.maha-subject-btn-dur {
  font-size: 0.64rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  color: var(--muted);
  align-self: center;
}

/* ── Workspace ── */
.maha-workspace {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl, 16px);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-md, 0 12px 32px rgba(0, 0, 0, 0.32));
}

.maha-module-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(16px, 2vw, 28px);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent);
  min-height: 56px;
}

.maha-module-bar-tools {
  display: none;
}

.maha-subject-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 12px;
  font-size: 1.1rem;
  background: linear-gradient(145deg, rgba(255, 153, 51, 0.12), rgba(37, 99, 235, 0.1));
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.maha-module-bar-copy {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.maha-module-bar-copy h2 {
  margin: 0;
  font-size: clamp(0.95rem, 1.1vw, 1.08rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  white-space: nowrap;
  flex-shrink: 0;
}

.maha-module-bar-copy .hint {
  margin: 0;
  font-size: clamp(0.84rem, 1vw, 0.92rem);
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.maha-module-bar-copy .hint::before {
  content: "·";
  margin: 0 0.55em;
  color: var(--muted);
  font-weight: 400;
}

.maha-module-bar-copy .hint.hidden {
  display: none;
}

.maha-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 !important;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  color: #86efac;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.22);
}

.maha-meta::before {
  content: "⏱";
}

/* ── Thread ── */
.maha-thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: clamp(20px, 2.2vw, 36px) clamp(24px, 2.5vw, 40px);
  display: flex;
  flex-direction: column;
}

.maha-workspace.has-output .maha-thread {
  padding-bottom: clamp(16px, 1.5vw, 24px);
}

.maha-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  padding: clamp(32px, 4vh, 56px) clamp(24px, 3vw, 48px);
  overflow-y: auto;
  text-align: center;
  border: 1px dashed rgba(37, 99, 235, 0.22);
  border-radius: var(--radius-lg, 12px);
  background: var(--maha-accent-soft);
}

.maha-empty-state.hidden {
  display: none;
}

.maha-empty-icon {
  font-size: 1.75rem;
  margin-bottom: 14px;
  color: var(--accent);
}

.maha-empty-state h3 {
  margin: 0 0 12px;
  font-size: clamp(1.05rem, 1.3vw, 1.25rem);
  font-weight: 700;
}

.maha-empty-state > p {
  margin: 0;
  max-width: 52ch;
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.65;
}

.maha-empty-tips {
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  max-width: 420px;
}

.maha-empty-tips li {
  position: relative;
  padding: 8px 0 8px 22px;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
}

.maha-empty-tips li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* ── Output card ── */
.maha-output-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.maha-output-wrap:not(.hidden) {
  animation: maha-fade-in 0.25s ease;
}

.maha-output-wrap.hidden {
  display: none;
}

.maha-turn {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.maha-turn.is-collapsed .maha-output {
  max-height: 0;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  opacity: 0;
}

.maha-turn.is-collapsed .maha-turn-ask {
  display: none;
}

.maha-turns {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scroll-behavior: smooth;
}

.maha-turns::-webkit-scrollbar {
  width: 8px;
}

.maha-turns::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.maha-turn-ask {
  padding: 12px 16px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.55;
}

.maha-turn-ask-text {
  font-style: italic;
}

.maha-response-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.maha-edit-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}

.maha-edit-btn:hover {
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--accent);
}

@keyframes maha-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.maha-turn-label {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.maha-turn-expand-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.maha-turn-expand-btn:hover {
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--accent);
}

.maha-response-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.06));
  overflow: hidden;
}

.maha-response-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.maha-response-badge {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  color: #86efac;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.maha-prompt-echo {
  margin: 8px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
  font-style: italic;
}

.maha-prompt-echo.hidden {
  display: none;
}

.maha-copy-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}

.maha-copy-btn:hover {
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--accent);
}

.maha-export-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.maha-export-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.maha-export-btn:hover:not(:disabled) {
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--accent);
}

.maha-export-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.maha-export-btn.is-busy {
  opacity: 0.65;
  cursor: wait;
}

.maha-export-btn-primary {
  background: #1a2744;
  border-color: #1a2744;
  color: #fff;
  font-weight: 600;
}

.maha-export-btn-primary:hover:not(:disabled) {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.maha-output {
  flex: 0 0 auto;
  min-height: 120px;
  max-height: min(52vh, 480px);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.72;
  padding: clamp(20px, 2vw, 28px) clamp(22px, 2.2vw, 32px);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  transition: max-height 0.2s ease, opacity 0.15s ease, padding 0.2s ease;
}

.maha-turn.is-expanded .maha-output {
  max-height: min(72vh, 720px);
}

.maha-turn.is-latest .maha-output {
  max-height: min(58vh, 560px);
}

.maha-turn.is-latest.is-expanded .maha-output {
  max-height: min(78vh, 820px);
}

.maha-output.chat-response-formatted,
.maha-output.chat-response-rich-only {
  white-space: normal;
}

.maha-output.chat-response-formatted .chat-md h1 {
  font-size: 1.35rem;
  margin: 0 0 12px;
}

.maha-output.chat-response-formatted .chat-md h2 {
  font-size: 1.1rem;
  margin: 20px 0 10px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.maha-output.chat-response-formatted .chat-md h3 {
  font-size: 1rem;
  margin: 14px 0 8px;
}

.maha-output.chat-response-formatted .chat-md-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.88rem;
}

.maha-output.chat-response-formatted .chat-md-table td,
.maha-output.chat-response-formatted .chat-md-table th {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.maha-output.chat-response-formatted .chat-md-table th {
  background: rgba(37, 99, 235, 0.12);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

.maha-output .chat-table-shell {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.14);
  overflow: hidden;
}

.maha-output .chat-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.maha-output .chat-table-meta {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.maha-output .chat-table-expand-btn {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.1);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.maha-output .chat-table-expand-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.maha-output .chat-table-scroll {
  max-height: 240px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.maha-output .chat-table-shell.is-expanded .chat-table-scroll {
  max-height: min(68vh, 560px);
}

.maha-output .maha-loading-rich {
  color: var(--muted);
  font-style: italic;
}

.maha-output .maha-output-error {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
  color: #fca5a5;
}

.maha-output .maha-output-error strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.maha-output.is-streaming .chat-view-pane-rich-only::after {
  content: "▍";
  display: inline;
  margin-left: 2px;
  color: var(--accent);
  animation: maha-caret 1s step-end infinite;
}

@keyframes maha-caret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.maha-output.chat-response-formatted .chat-html-preview iframe {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.maha-output.chat-response-formatted .chat-view-tabs {
  margin: -4px 0 14px;
}

.maha-output.chat-response-formatted .chat-view-tab {
  font-size: 0.76rem;
  padding: 6px 14px;
}

.maha-output::-webkit-scrollbar {
  width: 8px;
}

.maha-output::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.maha-output.is-loading {
  color: var(--muted);
  font-style: italic;
}

.maha-output.is-loading::after {
  content: "";
  display: inline-block;
  width: 0.45em;
  animation: maha-dots 1.2s steps(4, end) infinite;
}

@keyframes maha-dots {
  0%, 20% { content: ""; }
  40% { content: "."; }
  60% { content: ".."; }
  80%, 100% { content: "..."; }
}

/* ── Composer ── */
.maha-composer {
  flex: 0 0 auto;
  padding: clamp(18px, 1.8vw, 28px) clamp(24px, 2.5vw, 40px) clamp(20px, 2vw, 32px);
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface2));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
}

.maha-composer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: clamp(20px, 2vw, 32px);
  align-items: end;
}

@media (max-width: 820px) {
  .maha-composer-grid {
    grid-template-columns: 1fr;
  }

  .maha-composer-side {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }
}

.maha-composer-main {
  min-width: 0;
}

.maha-composer-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  min-width: 180px;
}

.maha-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
}

.maha-body.sovereign-chat-page {
  --sovereign-composer-max-h: min(280px, 38vh);
}

.maha-topic {
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border);
  background: var(--bg);
  color: inherit;
  font: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 72px;
  max-height: 160px;
  margin-bottom: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Bottom composer — do not inherit standalone .maha-topic height rules */
.maha-composer-box .maha-topic.maha-topic-composer {
  min-height: var(--sovereign-composer-min-h, 46px) !important;
  max-height: var(--sovereign-composer-max-h, 280px) !important;
  height: auto !important;
  line-height: 1.45 !important;
  resize: none !important;
  margin-bottom: 0 !important;
  padding: 10px 52px 10px 12px !important;
  border: none !important;
  background: transparent !important;
  overflow-y: auto !important;
  color: var(--text, inherit) !important;
}

.maha-topic:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: var(--focus-ring);
}

.maha-transcript {
  margin-top: 8px;
  min-height: 72px;
  max-height: 140px;
}

.maha-transcript-block {
  display: block;
  margin-bottom: 10px;
}

.maha-composer-box {
  position: relative;
  margin-bottom: 6px;
}

.maha-composer-box .maha-topic-composer {
  margin-bottom: 0;
}

/* Send hidden while generating — must beat unified_chat_composer #maha-generate rule */
.maha-body.sovereign-chat-page #maha-generate.sovereign-composer-send-btn.is-generating {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

.maha-stop-btn {
  flex: 0 0 auto;
  align-self: center;
  min-width: 72px;
  padding: 0 14px;
  height: 40px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.14);
  color: #fecaca;
  cursor: pointer;
}

.maha-body.sovereign-chat-page #maha-stop.maha-stop-btn:not(.hidden) {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

.maha-stop-btn:hover {
  background: rgba(239, 68, 68, 0.28);
}

.maha-stop-btn.hidden {
  display: none !important;
}

.maha-response-stop-btn {
  margin-left: 8px;
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
  cursor: pointer;
}

.maha-response-stop-btn.hidden {
  display: none !important;
}

.maha-stopped-note {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px dashed rgba(239, 68, 68, 0.45);
  color: #fecaca;
  font-size: 0.82rem;
}

.maha-response-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.maha-attachment-bar {
  margin-bottom: 10px;
}

.maha-select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  color-scheme: dark;
  font-size: 0.875rem;
  line-height: 1.35;
  cursor: pointer;
}

.maha-select option {
  background-color: #ffffff;
  color: #0f172a;
}

.maha-select:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: var(--focus-ring);
}

.maha-check {
  font-size: 0.875rem;
}

.maha-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.maha-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.maha-toggle-ui {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.maha-toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}

.maha-toggle input:checked + .maha-toggle-ui {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
}

.maha-toggle input:checked + .maha-toggle-ui::after {
  transform: translateX(18px);
  background: #fff;
}

.maha-composer-actions {
  display: flex;
  flex-shrink: 0;
  gap: 10px;
}

.maha-composer-actions .btn-primary {
  min-width: 124px;
}

.maha-composer-actions .btn-secondary {
  min-width: 84px;
}

.maha-composer-actions .btn-primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.maha-body .alert.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.28);
  color: #fca5a5;
}

.maha-workspace.has-output .maha-empty-state {
  display: none;
}

.maha-tool-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.maha-tool-field .maha-select {
  min-width: 180px;
}

@media (max-width: 820px) {
  .maha-module-bar-tools {
    margin-left: 0;
    width: 100%;
    justify-content: stretch;
  }

  .maha-module-bar-tools .maha-tool-field {
    flex: 1 1 140px;
    max-width: none;
  }
}

.maha-svg-preview {
  margin: 12px 0 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}

.maha-generated-image {
  display: block;
  max-width: 100%;
  max-height: 420px;
  margin: 0 auto;
  border-radius: 8px;
}
