/* TheaCRM v2.8.567 – UI layout foundation r3
   Shared width, theme, button, back-action and mobile-modal rules.
   Loaded after the user theme so selected accent colors remain authoritative. */

:root {
  --thea-control-min-height: 40px;
  --thea-touch-min-height: 44px;
  --thea-action-radius: 10px;
  --thea-action-gap: .45rem;
}

/* Every rendered page remains inside the existing Flask/Jinja app shell. */
body.thea-app-shell #mainContent,
body.thea-app-shell #mainContent > * {
  min-width: 0;
}

/* Long entity names must wrap instead of increasing the page width. */
body.thea-app-shell #mainContent :is(
  h1,
  h2,
  h3,
  .page-title,
  .project-page-title,
  .thea-page-title,
  .card-title,
  .modal-title,
  .dropdown-item,
  .list-group-item,
  .table td,
  .table th
) {
  overflow-wrap: anywhere;
  word-break: normal;
}

body.thea-app-shell #mainContent :is(
  .d-flex,
  .row,
  .col,
  [class*="col-"],
  .card,
  .card-body,
  .thea-card,
  .thea-work-card
) > * {
  min-width: 0;
}

/* Dashboard already uses the available shell width. Apply the same rule to
   direct page wrappers which currently re-introduce Bootstrap max-widths. */
@media (min-width: 992px) {
  body.thea-app-shell #mainContent > :is(
    .container,
    .container-sm,
    .container-md,
    .container-lg,
    .container-xl,
    .container-xxl,
    .container-fluid,
    .responsive-container,
    .thea-page,
    .thea-work-page,
    .thea-directory-page,
    .thea-list-page,
    .thea-chat-page,
    .email-app-container,
    .email-page-container,
    .email-detail-container,
    .email-workflow-page,
    .thea-email-signature-page,
    .ai-prework-page,
    .ai-prework-form,
    .ai-prework-detail
  ),
  body.thea-app-shell #mainContent > [class*="max-w-"] {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* Theme contract: Bootstrap primary and historical success actions both use
   the user-selected TheaCRM accent. Warning, danger and info stay semantic. */
body.thea-app-shell :is(.btn-primary, .btn-success) {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--primary-color);
  --bs-btn-border-color: var(--primary-color);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--primary-hover);
  --bs-btn-hover-border-color: var(--primary-hover);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--primary-hover);
  --bs-btn-active-border-color: var(--primary-hover);
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: var(--primary-color);
  --bs-btn-disabled-border-color: var(--primary-color);
  background-color: var(--primary-color) !important;
  border-color: var(--primary-color) !important;
  color: #fff !important;
}

body.thea-app-shell :is(.btn-primary, .btn-success):is(:hover, :focus-visible, :active, .active) {
  background-color: var(--primary-hover) !important;
  border-color: var(--primary-hover) !important;
  color: #fff !important;
}

body.thea-app-shell :is(.btn-outline-primary, .btn-outline-success) {
  --bs-btn-color: var(--primary-color);
  --bs-btn-border-color: var(--primary-color);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--primary-color);
  --bs-btn-hover-border-color: var(--primary-color);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--primary-hover);
  --bs-btn-active-border-color: var(--primary-hover);
  color: var(--primary-color) !important;
  border-color: var(--primary-color) !important;
  background-color: transparent !important;
}

body.thea-app-shell :is(.btn-outline-primary, .btn-outline-success):is(:hover, :focus-visible, :active, .active) {
  color: #fff !important;
  border-color: var(--primary-hover) !important;
  background-color: var(--primary-hover) !important;
}

body.thea-app-shell :is(.text-primary, .text-success, .link-primary, .link-success) {
  color: var(--primary-color) !important;
}

body.thea-app-shell :is(.bg-primary, .bg-success) {
  background-color: var(--primary-color) !important;
  color: #fff;
}

body.thea-app-shell :is(.border-primary, .border-success) {
  border-color: var(--primary-color) !important;
}

/* Common button geometry without changing semantic variants. */
body.thea-app-shell .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--thea-action-gap);
  min-height: var(--thea-control-min-height);
  max-width: 100%;
  border-radius: var(--thea-action-radius);
  line-height: 1.2;
  white-space: normal;
  text-align: center;
}

body.thea-app-shell .btn.btn-sm {
  min-height: 36px;
}

body.thea-app-shell .btn:focus-visible,
body.thea-app-shell [role="button"]:focus-visible,
body.thea-app-shell a:focus-visible {
  outline: 3px solid rgba(var(--thea-primary-rgb), .28);
  outline-offset: 2px;
}

/* Back/cancel actions retain their current href/history behavior, but share
   one neutral visual treatment. The selectors include existing legacy names. */
body.thea-app-shell :is(
  .btn-secondary,
  .btn-outline-secondary,
  .btn-outline-brown,
  .email-detail-back-btn,
  .stock-back-link,
  .thea-chat-back,
  [title^="Zpět"],
  [aria-label^="Zpět"]
) {
  background-color: transparent !important;
  border: 1px solid #6c757d !important;
  color: #495057 !important;
  box-shadow: none !important;
}

body.thea-app-shell :is(
  .btn-secondary,
  .btn-outline-secondary,
  .btn-outline-brown,
  .email-detail-back-btn,
  .stock-back-link,
  .thea-chat-back,
  [title^="Zpět"],
  [aria-label^="Zpět"]
):is(:hover, :focus-visible, :active) {
  background-color: #f1f3f5 !important;
  border-color: #495057 !important;
  color: #212529 !important;
}

/* Generic near-fullscreen mobile modal fallback. Existing explicitly marked
   fullscreen modals keep their stronger rules from the current foundation. */
@media (max-width: 767.98px) {
  body.thea-app-shell .btn {
    min-height: var(--thea-touch-min-height);
  }

  body.thea-app-shell .btn.btn-sm {
    min-height: 40px;
  }

  body.thea-app-shell .modal:not(.thea-ui-mobile-fullscreen-modal) .modal-dialog {
    width: calc(100% - .7rem);
    max-width: none;
    margin: .35rem auto;
  }

  body.thea-app-shell .modal:not(.thea-ui-mobile-fullscreen-modal) .modal-content {
    max-height: calc(100dvh - .7rem);
    border-radius: 14px;
    overflow: hidden;
  }

  body.thea-app-shell .modal:not(.thea-ui-mobile-fullscreen-modal) .modal-body {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (prefers-color-scheme: dark) {
  body.thea-app-shell :is(
    .btn-secondary,
    .btn-outline-secondary,
    .btn-outline-brown,
    .email-detail-back-btn,
    .stock-back-link,
    .thea-chat-back,
    [title^="Zpět"],
    [aria-label^="Zpět"]
  ) {
    border-color: #77808a !important;
    color: #e0e5ea !important;
  }

  body.thea-app-shell :is(
    .btn-secondary,
    .btn-outline-secondary,
    .btn-outline-brown,
    .email-detail-back-btn,
    .stock-back-link,
    .thea-chat-back,
    [title^="Zpět"],
    [aria-label^="Zpět"]
  ):is(:hover, :focus-visible, :active) {
    background-color: #2a2f3a !important;
    border-color: #aeb7c0 !important;
    color: #fff !important;
  }
}


/* VAS-31 — global page header responsive contract */
.thea-page--with-header {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

.thea-page-header {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: .65rem;
  min-width: 0;
  width: 100%;
  margin: 0 0 .9rem !important;
  padding: .15rem 0 0;
}

.thea-page > .thea-page-header,
.thea-page--with-header > .thea-page-header,
.thea-page-header.thea-hero {
  padding: .15rem 0 0 !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.thea-page--with-header > :is(.thea-card, .thea-work-card):has(> .thea-page-header) {
  padding-top: .85rem !important;
}

.thea-page-header__lead {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  min-width: 0;
  flex: 1 1 auto;
}

.thea-page-header__copy {
  min-width: 0;
  flex: 1 1 auto;
}

.thea-page-header__icon {
  flex: 0 0 2.55rem;
  width: 2.55rem;
  height: 2.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: .85rem;
  background: var(--thea-primary-soft, rgba(25, 135, 84, .10));
  color: var(--thea-ui-primary, var(--primary-color, #2e7d32));
  font-size: 1.2rem;
  line-height: 1;
}

.thea-page-header__title {
  min-width: 0;
  max-width: 100%;
  margin: 0 !important;
  font-size: clamp(1.45rem, 2.2vw, 1.8rem) !important;
  line-height: 1.12 !important;
  font-weight: 800 !important;
  letter-spacing: -.025em;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  overflow-wrap: break-word !important;
  word-break: normal !important;
}

.thea-page-header__subtitle {
  display: block;
  width: 100%;
  max-width: 72ch;
  margin: .24rem 0 0 !important;
  color: var(--thea-ui-muted, #667085) !important;
  font-size: .92rem;
  line-height: 1.35;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  overflow-wrap: break-word !important;
  word-break: normal !important;
}

.thea-page-header__actions {
  display: flex !important;
  flex: 0 1 auto;
  flex-wrap: wrap !important;
  align-items: center;
  justify-content: flex-start;
  gap: .45rem !important;
  min-width: 0 !important;
  max-width: 100%;
  margin-left: 0 !important;
}

.thea-page-header__actions > .btn,
.thea-page-header__actions > a.btn,
.thea-page-header__actions > button.btn,
.thea-page-header__back {
  min-height: 40px;
}

.thea-page-header__back {
  flex: 0 0 auto;
}

.thea-page-header.thea-ui-stocklike-header,
.thea-page-header.stock-topbar {
  min-width: 0 !important;
}

.thea-page-header.thea-ui-stocklike-header .thea-ui-header-main,
.thea-page-header.stock-topbar .stock-title-wrap {
  min-width: 0 !important;
  flex: 1 1 auto !important;
}

.thea-page-header.thea-ui-stocklike-header .thea-ui-header-title-wrap,
.thea-page-header.stock-topbar .thea-page-header__copy {
  min-width: 0 !important;
}

.thea-page-header.thea-ui-stocklike-header .thea-ui-header-subtitle,
.thea-page-header.stock-topbar .stock-subtitle {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

@media (max-width: 767.98px) {
  .thea-page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: .55rem !important;
    padding-top: 0 !important;
  }

  .thea-page-header__lead,
  .thea-page-header__copy,
  .thea-page-header.thea-ui-stocklike-header .thea-ui-header-main,
  .thea-page-header.stock-topbar .stock-title-wrap {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .thea-page-header__actions,
  .thea-page-header .thea-ui-header-actions,
  .thea-page-header .stock-actions,
  .thea-page-header .thea-chat-list-actions,
  .thea-page-header .thea-list-header-actions {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    align-self: stretch !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
  }

  .thea-page-header.thea-ui-stocklike-header {
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
  }

  .thea-page-header.thea-ui-stocklike-header .thea-ui-header-subtitle,
  .thea-page-header .thea-page-header__subtitle,
  .thea-page-header.stock-topbar .stock-subtitle {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  .thea-page-header__actions > .btn,
  .thea-page-header__actions > a.btn,
  .thea-page-header__actions > button.btn,
  .thea-page-header__back {
    min-height: 42px;
  }
}

@media (min-width: 768px) {
  .thea-page-header {
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    gap: 1rem !important;
  }

  .thea-page-header__lead,
  .thea-page-header__copy {
    min-width: 0;
    flex: 1 1 auto;
  }

  .thea-page-header__actions {
    flex: 0 1 auto;
    max-width: 52%;
    justify-content: flex-end;
    margin-left: auto !important;
  }
}
