/* =========================================================
   Menus de edifícios ajustados ao ecrã
   Mantém Produzir/Recrutar e restantes ações sempre visíveis
   sem alterar a lógica dos edifícios.
   ========================================================= */

.workshop-modal,
.barracks-modal {
  /* v0.1.149 — mesma dimensão base dos painéis principais.
     O Recrutar/Oficina deixaram de ocupar quase o ecrã todo. */
  width: min(1100px, calc(100vw - 96px)) !important;
  height: min(76vh, 660px);
  max-height: calc(100vh - var(--gge-topbar-height, 46px) - 112px) !important;
  overflow: hidden !important;
  display: flex;
  flex-direction: column;
}

.workshop-modal > .modal-head,
.barracks-modal > .modal-head,
.workshop-modal > .modal-actions,
.barracks-modal > .modal-actions {
  flex: 0 0 auto;
}

.workshop-modal > .modal-body,
.barracks-modal > .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden !important;
}

/* ------------------------- Oficina ------------------------- */
.workshop-shell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0 !important;
  padding: 10px 12px !important;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(310px, .92fr);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas:
    "banner banner benefits"
    "banner banner order"
    "queue queue selected"
    "catalog catalog selected";
  gap: 8px 10px;
  overflow: hidden;
}

.workshop-shell > .workshop-banner { grid-area: banner; }
.workshop-shell > .upgrade-benefits-panel { grid-area: benefits; }
.workshop-shell > .building-upgrade-order { grid-area: order; }
.workshop-shell > .workshop-queue-section { grid-area: queue; }
.workshop-shell > .workshop-catalog-section { grid-area: catalog; }
.workshop-shell > .workshop-selected-panel { grid-area: selected; }

.workshop-banner {
  grid-template-columns: 58px 1fr 94px !important;
  gap: 10px !important;
  min-height: 92px;
  padding: 9px 11px !important;
}
.workshop-banner-crest { width: 50px !important; height: 50px !important; font-size: 27px !important; }
.workshop-banner h2 { font-size: 21px !important; }
.workshop-banner p { font-size: 12px; line-height: 1.25; }
.workshop-speed { padding: 6px !important; }
.workshop-speed strong { font-size: 20px !important; }

.workshop-shell > .upgrade-benefits-panel,
.workshop-shell > .building-upgrade-order {
  margin: 0 !important;
}
.workshop-shell .upgrade-benefits-panel {
  border-radius: 7px;
}
.workshop-shell .upgrade-benefits-panel > header {
  padding: 6px 8px !important;
  gap: 7px;
}
.workshop-shell .upgrade-benefits-panel > header small { display: none; }
.workshop-shell .upgrade-benefits-panel > header h3 { font-size: 12px; }
.workshop-shell .upgrade-level-badge { padding: 4px 7px; font-size: 11px; }
.workshop-shell .upgrade-benefit-row,
.workshop-shell .upgrade-benefits-panel.is-compact .upgrade-benefit-row {
  min-height: 28px !important;
  padding: 3px 7px !important;
  grid-template-columns: minmax(122px, 1.55fr) minmax(54px, .65fr) 16px minmax(54px, .65fr) minmax(52px, .65fr) !important;
  gap: 4px !important;
  font-size: 10px;
}
.workshop-shell .upgrade-benefit-name { gap: 4px; }
.workshop-shell .upgrade-benefit-name > span { width: 17px; font-size: 13px; }
.workshop-shell .upgrade-benefit-name small { display: none; }
.workshop-shell .upgrade-benefit-difference { padding: 3px 4px; }
.workshop-shell .building-upgrade-order {
  gap: 6px;
}
.workshop-shell .building-upgrade-order > div {
  min-width: 0;
  padding: 5px 7px;
  border-radius: 6px;
}
.workshop-shell .building-upgrade-order span { margin-bottom: 2px; font-size: 9px; }
.workshop-shell .building-upgrade-order strong,
.workshop-shell .building-upgrade-order .cost { font-size: 11px; }

.workshop-queue-section,
.workshop-catalog-section { margin-top: 0 !important; min-width: 0; }
.workshop-section-heading { margin-bottom: 4px !important; }
.workshop-section-heading h3 { font-size: 16px !important; }
.workshop-section-heading small { font-size: 9px; }
.workshop-section-heading > span { font-size: 10px !important; }
.workshop-queue-grid { gap: 5px !important; }
.workshop-queue-slot {
  min-height: 58px !important;
  gap: 5px !important;
  padding: 5px !important;
  border-width: 1px !important;
}
.workshop-queue-slot.is-empty > span { width: 21px !important; height: 21px !important; font-size: 11px; }
.workshop-queue-slot.is-empty small { font-size: 9px; }
.workshop-slot-icon { flex-basis: 36px !important; height: 40px !important; }
.workshop-slot-data { font-size: 10px; line-height: 1.1; }
.workshop-slot-data small { font-size: 9px; }
.workshop-cancel-item { width: 17px !important; height: 17px !important; font-size: 10px; }
.workshop-shell .siege-tool-icon-small { width: 34px; height: 34px; }

.workshop-tool-grid { gap: 6px !important; }
.workshop-tool-card {
  min-height: 126px !important;
  padding: 6px !important;
  border-width: 1px !important;
}
.workshop-tool-card-icon { height: 46px !important; margin-bottom: 4px !important; }
.workshop-shell .siege-tool-icon-card { width: 45px; height: 45px; }
.workshop-tool-card strong { font-size: 14px !important; }
.workshop-tool-card > small {
  min-height: 25px !important;
  margin-top: 1px !important;
  font-size: 9px;
  line-height: 1.2;
}
.workshop-tool-card-bottom { margin-top: 4px !important; font-size: 9px !important; gap: 3px !important; }
.workshop-stock-badge { padding: 2px 4px !important; font-size: 9px; }
.workshop-stock-badge b { font-size: 11px !important; }

.workshop-selected-panel {
  min-width: 0;
  height: 100%;
  align-self: stretch;
  grid-template-columns: 105px minmax(0, 1fr) !important;
  align-items: stretch;
  gap: 8px !important;
  margin: 0 !important;
  padding: 8px !important;
  overflow: hidden;
}
.workshop-selected-visual {
  min-height: 0 !important;
  height: 100%;
  gap: 4px !important;
}
.workshop-shell .siege-tool-icon-large { width: 88px; height: 88px; }
.workshop-selected-visual .workshop-stock-badge { white-space: normal; justify-content: center; }
.workshop-selected-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.workshop-selected-info h3 { font-size: 20px !important; }
.workshop-selected-info p { margin: 2px 0 5px !important; font-size: 11px; line-height: 1.2; }
.workshop-effect { padding: 5px 7px !important; font-size: 10px; }
.workshop-quantity-row { gap: 5px !important; margin: 7px 0 !important; }
.workshop-quantity-row > button { width: 31px !important; height: 31px !important; font-size: 18px !important; }
.workshop-quantity-row label span { margin-bottom: 2px !important; font-size: 9px !important; }
.workshop-quantity-row input { height: 31px !important; padding: 3px 6px !important; font-size: 14px !important; }
.workshop-production-summary { grid-template-columns: 105px 1fr !important; gap: 5px !important; margin-bottom: 7px !important; }
.workshop-production-summary > div { padding: 5px 6px !important; }
.workshop-production-summary span { font-size: 8px !important; }
.workshop-production-summary strong { margin-top: 2px !important; font-size: 13px !important; }
.workshop-production-summary .cost { font-size: 10px; }
.workshop-produce-btn { padding: 8px !important; font-size: 15px !important; }

/* ------------------------- Quartel ------------------------- */
.barracks-shell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0 !important;
  padding: 10px 12px !important;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(330px, .96fr);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas:
    "banner banner benefits"
    "banner banner order"
    "queue queue selected"
    "catalog catalog selected";
  gap: 8px 10px;
  overflow: hidden;
}
.barracks-shell > .barracks-banner { grid-area: banner; }
.barracks-shell > .upgrade-benefits-panel { grid-area: benefits; }
.barracks-shell > .building-upgrade-order { grid-area: order; }
.barracks-shell > .barracks-queue-section { grid-area: queue; }
.barracks-shell > .barracks-catalog-section { grid-area: catalog; }
.barracks-shell > .barracks-selected-panel { grid-area: selected; }

.barracks-banner {
  grid-template-columns: 58px 1fr 112px !important;
  gap: 10px !important;
  min-height: 92px;
  padding: 9px 11px !important;
}
.barracks-crest { width: 50px !important; height: 50px !important; font-size: 27px !important; }
.barracks-banner h2 { font-size: 22px !important; }
.barracks-banner p { font-size: 12px; line-height: 1.25; }
.barracks-level { padding: 5px !important; }
.barracks-level strong { font-size: 14px !important; }
.barracks-level-visual .barracks-level-preview { max-height: 38px; }

.barracks-shell > .upgrade-benefits-panel,
.barracks-shell > .building-upgrade-order { margin: 0 !important; }
.barracks-shell .upgrade-benefits-panel { border-radius: 7px; }
.barracks-shell .upgrade-benefits-panel > header { padding: 6px 8px !important; gap: 7px; }
.barracks-shell .upgrade-benefits-panel > header small { display: none; }
.barracks-shell .upgrade-benefits-panel > header h3 { font-size: 12px; }
.barracks-shell .upgrade-level-badge { padding: 4px 7px; font-size: 11px; }
.barracks-shell .upgrade-benefit-row,
.barracks-shell .upgrade-benefits-panel.is-compact .upgrade-benefit-row {
  min-height: 28px !important;
  padding: 3px 7px !important;
  grid-template-columns: minmax(122px, 1.55fr) minmax(54px, .65fr) 16px minmax(54px, .65fr) minmax(52px, .65fr) !important;
  gap: 4px !important;
  font-size: 10px;
}
.barracks-shell .upgrade-benefit-name { gap: 4px; }
.barracks-shell .upgrade-benefit-name > span { width: 17px; font-size: 13px; }
.barracks-shell .upgrade-benefit-name small { display: none; }
.barracks-shell .upgrade-benefit-difference { padding: 3px 4px; }
.barracks-shell .building-upgrade-order { gap: 6px; }
.barracks-shell .building-upgrade-order > div { min-width: 0; padding: 5px 7px; border-radius: 6px; }
.barracks-shell .building-upgrade-order span { margin-bottom: 2px; font-size: 9px; }
.barracks-shell .building-upgrade-order strong,
.barracks-shell .building-upgrade-order .cost { font-size: 11px; }

.barracks-queue-section,
.barracks-catalog-section { margin-top: 0 !important; min-width: 0; }
.barracks-section-heading { margin-bottom: 4px !important; }
.barracks-section-heading h3 { font-size: 16px !important; }
.barracks-section-heading small { font-size: 9px; }
.barracks-section-heading > span { font-size: 10px !important; }
.barracks-food-consumption { padding: 3px 5px !important; }
.barracks-queue-grid { gap: 5px !important; }
.barracks-queue-slot { min-height: 58px !important; gap: 5px !important; padding: 5px !important; border-width: 1px !important; }
.barracks-queue-slot.is-empty span { width: 21px !important; height: 21px !important; font-size: 11px; }
.barracks-queue-slot.is-empty small { font-size: 9px; }
.barracks-queue-icon { flex-basis: 34px !important; height: 39px !important; font-size: 22px !important; }
.barracks-queue-data { font-size: 10px; line-height: 1.1; }
.barracks-queue-data small { font-size: 9px; }
.barracks-extra-queue { padding: 3px 6px !important; font-size: 9px !important; }

.barracks-troop-grid { gap: 6px !important; }
.barracks-troop-card { min-height: 130px !important; padding: 6px !important; border-width: 1px !important; }
.barracks-card-level { left: 4px !important; top: 4px !important; padding: 2px 4px !important; font-size: 9px !important; }
.barracks-card-portrait { height: 48px !important; margin-bottom: 4px !important; }
.barracks-card-portrait span { font-size: 35px !important; }
.barracks-troop-card strong { font-size: 14px !important; }
.barracks-troop-card small { font-size: 9px; }
.barracks-card-stats { margin-top: 4px !important; padding-top: 4px !important; font-size: 9px !important; }

.barracks-selected-panel {
  min-width: 0;
  height: 100%;
  align-self: stretch;
  grid-template-columns: 105px minmax(0, 1fr) !important;
  align-items: stretch;
  gap: 8px !important;
  margin: 0 !important;
  padding: 8px !important;
  overflow: hidden;
}
.barracks-selected-portrait { min-height: 0 !important; height: 100%; gap: 3px !important; }
.barracks-selected-portrait > span { font-size: 67px !important; }
.barracks-selected-portrait b { font-size: 14px !important; }
.barracks-selected-portrait small { font-size: 9px; }
.barracks-selected-info { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.barracks-selected-info h3 { margin-bottom: 4px !important; font-size: 20px !important; }
.barracks-selected-stats { gap: 4px !important; }
.barracks-selected-stats > div,
.barracks-recruit-summary > div { padding: 4px 5px !important; }
.barracks-selected-stats span,
.barracks-recruit-summary span { font-size: 8px !important; }
.barracks-selected-stats strong,
.barracks-recruit-summary strong { margin-top: 1px !important; font-size: 12px !important; }
.barracks-quantity-row { gap: 5px !important; margin: 7px 0 !important; }
.barracks-quantity-row > button { width: 31px !important; height: 31px !important; font-size: 18px !important; }
.barracks-quantity-row label span { margin-bottom: 2px !important; font-size: 9px !important; }
.barracks-quantity-row input { height: 31px !important; padding: 3px 6px !important; font-size: 14px !important; }
.barracks-recruit-summary { gap: 4px !important; margin-bottom: 7px !important; }
.barracks-recruit-btn { padding: 8px !important; font-size: 15px !important; }

/* Menus normais dos restantes edifícios: conteúdo e botões cabem no ecrã. */
.modal:not(.workshop-modal):not(.barracks-modal) .upgrade-benefits-panel {
  max-height: 48vh;
}

/* Ajuste adicional para portáteis com pouca altura. */
@media (max-height: 760px) and (min-width: 850px) {
  .workshop-modal,
  .barracks-modal { height: min(82vh, 620px) !important; max-height: calc(100vh - 84px) !important; }
  .workshop-modal .modal-head,
  .barracks-modal .modal-head { padding-top: 6px !important; padding-bottom: 6px !important; }
  .workshop-modal .modal-actions,
  .barracks-modal .modal-actions { padding-top: 7px !important; padding-bottom: 7px !important; }
  .workshop-shell,
  .barracks-shell { padding: 7px 9px !important; gap: 6px 8px; }
}

/* Em janelas estreitas continua utilizável; apenas aqui é permitido scroll interno. */
@media (max-width: 849px) {
  .workshop-modal,
  .barracks-modal { width: calc(100vw - 18px) !important; height: 92vh !important; max-height: 92vh !important; }
  .workshop-modal > .modal-body,
  .barracks-modal > .modal-body { overflow: auto !important; }
  .workshop-shell,
  .barracks-shell {
    height: auto;
    min-height: 0 !important;
    display: block;
    overflow: visible;
  }
  .workshop-shell > *,
  .barracks-shell > * { margin-top: 9px !important; }
  .workshop-selected-panel,
  .barracks-selected-panel { height: auto; }
}


/* =========================================================
   v0.1.149 — Tamanho unificado dos painéis de edifícios
   Recrutar e Oficina usam agora a mesma escala visual dos
   restantes painéis, sem ocupar o ecrã todo em monitores largos.
   ========================================================= */
body.gge-layout-active .workshop-modal,
body.gge-layout-active .barracks-modal {
  width: min(1100px, calc(100vw - 96px)) !important;
  height: min(76vh, 660px) !important;
  max-height: calc(100vh - var(--gge-topbar-height, 46px) - 112px) !important;
  min-height: 0 !important;
}

body.gge-layout-active .workshop-modal > .modal-head,
body.gge-layout-active .barracks-modal > .modal-head {
  min-height: 40px !important;
  padding: 7px 14px !important;
}

body.gge-layout-active .workshop-modal > .modal-actions,
body.gge-layout-active .barracks-modal > .modal-actions {
  min-height: 48px !important;
  padding: 8px 14px !important;
}

body.gge-layout-active .workshop-modal > .modal-body,
body.gge-layout-active .barracks-modal > .modal-body {
  min-height: 0 !important;
  overflow: hidden !important;
}

body.gge-layout-active .workshop-shell,
body.gge-layout-active .barracks-shell {
  height: 100% !important;
  min-height: 0 !important;
  padding: 8px 10px !important;
  gap: 6px 8px !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(292px, .84fr) !important;
  grid-template-rows: 82px 58px 68px minmax(0, 1fr) !important;
}

body.gge-layout-active .workshop-banner,
body.gge-layout-active .barracks-banner {
  min-height: 0 !important;
  height: 82px !important;
  padding: 7px 9px !important;
  gap: 8px !important;
}
body.gge-layout-active .workshop-banner { grid-template-columns: 50px 1fr 82px !important; }
body.gge-layout-active .barracks-banner { grid-template-columns: 50px 1fr 90px !important; }
body.gge-layout-active .workshop-banner-crest,
body.gge-layout-active .barracks-crest { width: 44px !important; height: 44px !important; font-size: 24px !important; }
body.gge-layout-active .workshop-banner h2,
body.gge-layout-active .barracks-banner h2 { font-size: 19px !important; line-height: 1.05 !important; }
body.gge-layout-active .workshop-banner p,
body.gge-layout-active .barracks-banner p { font-size: 11px !important; line-height: 1.18 !important; }
body.gge-layout-active .workshop-speed,
body.gge-layout-active .barracks-level { padding: 4px !important; }
body.gge-layout-active .workshop-speed strong,
body.gge-layout-active .barracks-level strong { font-size: 12px !important; }
body.gge-layout-active .workshop-speed span,
body.gge-layout-active .barracks-level span { font-size: 8px !important; }

body.gge-layout-active .workshop-shell .upgrade-benefits-panel,
body.gge-layout-active .barracks-shell .upgrade-benefits-panel,
body.gge-layout-active .workshop-shell .building-upgrade-order,
body.gge-layout-active .barracks-shell .building-upgrade-order {
  min-height: 0 !important;
  overflow: hidden !important;
}
body.gge-layout-active .workshop-shell .upgrade-benefits-panel > header,
body.gge-layout-active .barracks-shell .upgrade-benefits-panel > header { padding: 4px 7px !important; }
body.gge-layout-active .workshop-shell .upgrade-benefit-row,
body.gge-layout-active .barracks-shell .upgrade-benefit-row,
body.gge-layout-active .workshop-shell .upgrade-benefits-panel.is-compact .upgrade-benefit-row,
body.gge-layout-active .barracks-shell .upgrade-benefits-panel.is-compact .upgrade-benefit-row {
  min-height: 24px !important;
  padding: 2px 6px !important;
  font-size: 9px !important;
}
body.gge-layout-active .workshop-shell .building-upgrade-order > div,
body.gge-layout-active .barracks-shell .building-upgrade-order > div { padding: 4px 6px !important; }

body.gge-layout-active .workshop-queue-section,
body.gge-layout-active .barracks-queue-section,
body.gge-layout-active .workshop-catalog-section,
body.gge-layout-active .barracks-catalog-section { margin-top: 0 !important; }
body.gge-layout-active .workshop-section-heading,
body.gge-layout-active .barracks-section-heading { margin-bottom: 3px !important; }
body.gge-layout-active .workshop-section-heading h3,
body.gge-layout-active .barracks-section-heading h3 { font-size: 15px !important; }
body.gge-layout-active .workshop-section-heading small,
body.gge-layout-active .barracks-section-heading small { font-size: 8px !important; }

body.gge-layout-active .workshop-queue-grid,
body.gge-layout-active .barracks-queue-grid { gap: 4px !important; }
body.gge-layout-active .workshop-queue-slot,
body.gge-layout-active .barracks-queue-slot {
  min-height: 46px !important;
  padding: 4px !important;
  gap: 4px !important;
}
body.gge-layout-active .workshop-queue-slot.is-empty > span,
body.gge-layout-active .barracks-queue-slot.is-empty span { width: 18px !important; height: 18px !important; font-size: 10px !important; }
body.gge-layout-active .workshop-queue-slot.is-empty small,
body.gge-layout-active .barracks-queue-slot.is-empty small { font-size: 8px !important; }
body.gge-layout-active .workshop-slot-icon,
body.gge-layout-active .barracks-queue-icon { flex-basis: 30px !important; height: 32px !important; font-size: 19px !important; }
body.gge-layout-active .workshop-slot-data,
body.gge-layout-active .barracks-queue-data { font-size: 9px !important; }
body.gge-layout-active .workshop-slot-data small,
body.gge-layout-active .barracks-queue-data small { font-size: 8px !important; }

body.gge-layout-active .workshop-tool-grid,
body.gge-layout-active .barracks-troop-grid { gap: 5px !important; }
body.gge-layout-active .workshop-tool-card,
body.gge-layout-active .barracks-troop-card {
  min-height: 104px !important;
  padding: 5px !important;
}
body.gge-layout-active .workshop-tool-card-icon,
body.gge-layout-active .barracks-card-portrait { height: 38px !important; margin-bottom: 3px !important; }
body.gge-layout-active .workshop-shell .siege-tool-icon-card { width: 38px !important; height: 38px !important; }
body.gge-layout-active .barracks-card-portrait span { font-size: 29px !important; }
body.gge-layout-active .workshop-tool-card strong,
body.gge-layout-active .barracks-troop-card strong { font-size: 13px !important; }
body.gge-layout-active .workshop-tool-card > small,
body.gge-layout-active .barracks-troop-card small { font-size: 8px !important; }
body.gge-layout-active .workshop-tool-card-bottom,
body.gge-layout-active .barracks-card-stats { margin-top: 3px !important; padding-top: 3px !important; font-size: 8px !important; }

body.gge-layout-active .workshop-selected-panel,
body.gge-layout-active .barracks-selected-panel {
  grid-template-columns: 88px minmax(0, 1fr) !important;
  gap: 7px !important;
  padding: 7px !important;
}
body.gge-layout-active .workshop-shell .siege-tool-icon-large { width: 72px !important; height: 72px !important; }
body.gge-layout-active .barracks-selected-portrait > span { font-size: 54px !important; }
body.gge-layout-active .workshop-selected-info h3,
body.gge-layout-active .barracks-selected-info h3 { font-size: 18px !important; }
body.gge-layout-active .workshop-selected-info p { font-size: 10px !important; }
body.gge-layout-active .barracks-selected-stats,
body.gge-layout-active .barracks-recruit-summary,
body.gge-layout-active .workshop-production-summary { gap: 4px !important; }
body.gge-layout-active .barracks-selected-stats > div,
body.gge-layout-active .barracks-recruit-summary > div,
body.gge-layout-active .workshop-production-summary > div { padding: 4px !important; }
body.gge-layout-active .barracks-quantity-row,
body.gge-layout-active .workshop-quantity-row { margin: 6px 0 !important; }
body.gge-layout-active .barracks-recruit-btn,
body.gge-layout-active .workshop-produce-btn { padding: 7px !important; font-size: 14px !important; }

@media (max-height: 760px) and (min-width: 850px) {
  body.gge-layout-active .workshop-modal,
  body.gge-layout-active .barracks-modal {
    height: calc(100vh - 92px) !important;
    min-height: 0 !important;
  }
}

/* v0.1.149 — Recrutar/Oficina usam a mesma posição vertical dos outros painéis. */
body.gge-layout-active .workshop-modal,
body.gge-layout-active .barracks-modal {
  max-height: var(--rdf-menu-panel-max-height, calc(100vh - 112px)) !important;
}
