/* Celular e tablet: toque, gavetas, barra de abas e telas cheias.
   Pontos de quebra iguais aos do DeviceService (C#): celular < 600 px, tablet 600–1100 px.
   O layout do editor vem das classes .editor--phone/.editor--tablet (decididas no C#); o resto usa media queries.
   Computador com mouse nao muda: tudo aqui depende dessas classes, de (pointer: coarse)/(hover: none) ou da largura. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 58px;
  --topbar-compact-h: 52px;
}

.editor { height: 100vh; height: 100dvh; position: relative; }
/* o titulo recebe o foco ao navegar (leitores de tela); o anel de foco nele so confunde */
h1:focus { outline: none; }
.hero__copy { min-width: 0; }
body:has(.editor) { overflow: hidden; overscroll-behavior: none; }

/* ---------- Toque: alvos de 44 px, sem realce cinza, sem menu de "copiar imagem" ---------- */
@media (pointer: coarse) {
  button, a, [role="button"], .palette__item, .template-card { -webkit-tap-highlight-color: transparent; }
  [data-help], .palette__item, .rail__item, .tabbar__item { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .icon-button { width: 44px; height: 44px; border-radius: 12px; }
  .icon-button--sm { width: 36px; height: 36px; }
  .tb { min-width: 40px; height: 40px; }
  .float-bar { height: 52px; }
  .float-bar__font { height: 40px; }
  .stepper { height: 40px; }
  .stepper button { width: 34px; }
  .menu__item { min-height: 44px; }
  .chip { height: 40px; }
  .pill-toggle { height: 36px; }
  .segmented__item { height: 38px; }
  .check { min-height: 36px; }
  .check input { width: 20px; height: 20px; }
  /* iOS da zoom na pagina ao focar campos com fonte menor que 16 px */
  .field__input, input, select, textarea { font-size: 16px; }
  .field__input { height: 44px; }
  .field__textarea { height: auto; }
  .swatch { width: 30px; height: 30px; }
  fluent-button, fluent-select, fluent-text-field, fluent-number-field { --base-height-multiplier: 10; }
  .record-nav { height: 46px; }
  .record-nav__input { height: 34px; }
  .hintbar__close { width: 32px; height: 32px; }
}
@media (hover: none) {
  .palette__item:hover, .template-card:hover, .design-card:hover { transform: none; box-shadow: none; }
  .palette__item:active, .template-card:active, .more-menu__item:active { transform: scale(.98); }
}

/* ---------- Tablet: trilho + canvas; painel e propriedades viram gavetas sobrepostas ---------- */
.editor.editor--tablet {
  grid-template-columns: 72px minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr) 34px;
  grid-template-areas: "top top" "rail canvas" "rail status";
}
.editor--tablet .sidepanel--drawer, .editor--tablet .inspector--drawer {
  position: absolute; z-index: 25; top: 56px; bottom: 34px; box-shadow: var(--shadow-3); border: 0;
}
.editor--tablet .sidepanel--drawer {
  left: 72px; width: min(320px, calc(100% - 72px - 56px)); border-radius: 0 16px 16px 0;
  animation: drawer-left .22s var(--ease);
}
.editor--tablet .inspector--drawer {
  right: 0; width: min(340px, calc(100% - 72px)); border-radius: 16px 0 0 16px;
  animation: drawer-right .22s var(--ease);
}
@keyframes drawer-left { from { transform: translateX(-24px); opacity: 0; } }
@keyframes drawer-right { from { transform: translateX(24px); opacity: 0; } }
.editor--tablet .rail__item { padding: 10px 2px; }
.editor--tablet .statusbar__cursor, .editor--phone .statusbar__cursor { display: none; }
.topbar--medium { gap: 6px; padding: 0 10px; }
.topbar--medium .topbar__title { width: clamp(120px, 20vw, 220px); }
.topbar--medium .avatar-button__name, .topbar--medium .avatar-button > svg { display: none; }
.topbar--medium .agent-chip { padding: 0 10px; }
.topbar--medium .save-state { font-size: 0; gap: 0; }
@media (max-width: 860px) {
  .topbar--medium .agent-chip__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .topbar--medium .agent-chip { width: 36px; padding: 0; justify-content: center; }
}

/* ---------- Celular: barra superior enxuta, canvas inteiro, abas embaixo, gaveta de baixo ---------- */
.editor.editor--phone {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "canvas" "tabs";
}
.topbar--compact {
  height: calc(var(--topbar-compact-h) + var(--safe-top)); padding: var(--safe-top) calc(6px + var(--safe-right)) 0 calc(2px + var(--safe-left));
  gap: 0;
}
.topbar--compact .icon-button { width: 40px; height: 40px; }
.topbar--compact .topbar__name { flex: 1; min-width: 0; gap: 4px; }
.topbar--compact .topbar__title { width: 100%; min-width: 0; font-size: 15px; padding: 6px 4px; text-overflow: ellipsis; }
.save-state--dot { font-size: 0; gap: 0; flex: none; }
.topbar__print {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; margin: 0 2px 0 4px; padding: 0 14px 0 12px; border: 0; border-radius: 12px;
  background: var(--c-accent); color: #fff; font: 650 14px var(--font-ui); cursor: pointer; flex: none;
  box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--c-accent) 70%, transparent);
}
.topbar__print:active { transform: translateY(1px); background: var(--c-accent-strong); }
@media (max-width: 359.98px) { .topbar__print span { display: none; } .topbar__print { padding: 0 10px; } }

.tabbar {
  grid-area: tabs; z-index: 40; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--c-surface); border-top: 1px solid var(--c-border-soft);
}
.tabbar__item {
  display: grid; justify-items: center; align-content: center; gap: 3px; min-height: var(--tabbar-h); padding: 6px 0 4px; border: 0; background: none;
  font: 600 10.5px var(--font-ui); letter-spacing: -.01em; color: var(--c-text-2); cursor: pointer; white-space: nowrap;
}
.tabbar__item > svg { width: 24px; height: 24px; padding: 3px 16px; box-sizing: content-box; border-radius: 999px; transition: background .2s var(--ease); }
.tabbar__item.is-active { color: var(--c-accent); }
.tabbar__item.is-active > svg { background: var(--c-accent-soft); }
.tabbar__item:active > svg { background: var(--c-surface-2); }

/* Gaveta de baixo: acima das abas; metade da tela ou tela cheia (ate a barra superior) */
.sheet {
  position: fixed; left: 0; right: 0; z-index: 35; bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  display: flex; flex-direction: column; background: var(--c-surface);
  border-radius: 20px 20px 0 0; box-shadow: 0 -16px 40px -16px rgba(10, 18, 26, .38), 0 -1px 0 var(--c-border-soft);
  transition: height .26s var(--ease), transform .26s var(--ease); animation: sheet-in .26s var(--ease);
}
.sheet--half { height: min(54dvh, 560px); }
.sheet--full { height: calc(100dvh - var(--topbar-compact-h) - var(--safe-top) - var(--tabbar-h) - var(--safe-bottom) + 8px); }
.sheet.is-dragging { transition: none; }
@keyframes sheet-in { from { transform: translateY(40%); opacity: .4; } }
.sheet__grip { flex: none; display: grid; place-items: center; height: 26px; touch-action: none; cursor: grab; }
.sheet__grip:focus-visible { outline-offset: -4px; }
.sheet__handle { width: 42px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--c-text) 22%, transparent); }
.sheet__content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.sheet .sidepanel, .sheet .inspector { flex: 1; min-height: 0; border: 0; background: transparent; }
.sheet .sidepanel__header, .sheet .inspector__header { padding: 0 8px 6px 18px; }
.sheet .sidepanel__body, .sheet .inspector__body { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: 28px; }
.sheet .palette { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.sheet .palette--text { grid-template-columns: 1fr; }
.sheet .mini-templates { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.sheet .uploads__grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.sheet .palette__item { cursor: pointer; }

.more-menu { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.more-menu__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 4px 16px 20px; }
.more-menu__item {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 0 16px; border: 1px solid var(--c-border-soft); border-radius: 16px;
  background: var(--c-surface); color: var(--c-text); font: 600 14px var(--font-ui); text-align: left; cursor: pointer;
  transition: transform .12s var(--ease), border-color .15s;
}
.more-menu__item > svg { flex: none; padding: 8px; box-sizing: content-box; border-radius: 12px; background: var(--c-accent-soft); }

/* Canvas no celular: dicas compactas, navegador de registros a esquerda, zoom no canto */
.editor--phone .canvas-hint {
  bottom: 56px; width: calc(100% - 32px); justify-content: center; white-space: normal; text-align: left; border-radius: 16px;
}
.editor--phone .record-nav { left: 8px; transform: none; max-width: calc(100% - 112px); top: 8px; }
.editor--phone .record-nav__row, .editor--phone .record-nav > .float-bar__sep { display: none; }
.record-nav__search-toggle { display: none; }
.editor--phone .record-nav__search-toggle { display: inline-grid; }
.editor--phone .record-nav__search { display: none; }
.editor--phone .record-nav--searching .record-nav__search { display: inline-flex; }
.editor--phone .record-nav--searching .record-nav__search input { width: 110px; }
/* no celular a barra de formatacao fica presa embaixo do canvas (nao cobre o objeto nem a alca de girar) */
.editor--phone .float-bar {
  top: auto !important; left: 50% !important; bottom: 50px; max-width: calc(100% - 12px);
  box-shadow: 0 10px 30px -10px rgba(10, 18, 26, .35);
}
.zoom-chip {
  position: absolute; z-index: 6; top: 8px; right: 8px; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px 0 10px;
  border-radius: 999px; border: 1px solid var(--c-border-soft); background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: var(--shadow-1); cursor: pointer;
  font: 650 12.5px var(--font-ui); font-variant-numeric: tabular-nums; color: var(--c-text);
}
.hintbar--compact { bottom: 8px; padding: 2px 2px 2px 12px; font-size: 11.5px; max-width: calc(100% - 16px); }
.hintbar--compact .hintbar__item + .hintbar__item::before { margin: 0 7px; }
.hintbar--compact .hintbar__close { width: 30px; height: 30px; margin-left: 2px; }

/* Menu de acoes do toque longo */
.action-scrim { position: fixed; inset: 0; z-index: 90; background: rgba(12, 18, 24, .38); animation: fade .15s; }
.action-sheet {
  position: fixed; z-index: 91; left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); bottom: calc(8px + var(--safe-bottom));
  max-width: 440px; margin: 0 auto; max-height: 72dvh; display: flex; flex-direction: column;
  background: var(--c-surface); border-radius: 20px; box-shadow: var(--shadow-3); animation: sheet-in .22s var(--ease);
}
.action-sheet__header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 6px 2px 18px; }
.action-sheet__header strong { font: 700 15px var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-sheet__list { display: grid; padding: 4px 8px 10px; overflow-y: auto; overscroll-behavior: contain; }
.action-sheet__item {
  display: flex; align-items: center; gap: 14px; min-height: 48px; padding: 0 12px; border: 0; border-radius: 12px; background: none;
  color: var(--c-text); font: 500 15px var(--font-ui); text-align: left; cursor: pointer;
}
.action-sheet__item:hover, .action-sheet__item:active { background: var(--c-surface-2); }
.action-sheet__item--danger { color: var(--c-danger); }

/* ---------- Telas estreitas (celular) fora do editor: menus, dialogos, inicio, login, avisos ---------- */
@media (max-width: 599.98px) {
  /* menus viram gaveta de acoes presa embaixo */
  .menu-scrim { background: rgba(12, 18, 24, .38); z-index: 94; animation: fade .15s; }
  .menu, .menu--left {
    position: fixed; left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); top: auto; bottom: calc(8px + var(--safe-bottom));
    z-index: 95; min-width: 0; max-height: 78dvh; overflow-y: auto; padding: 8px; border-radius: 20px; box-shadow: var(--shadow-3);
    animation: sheet-in .2s var(--ease);
  }
  .menu__item { min-height: 48px; font-size: 15px; gap: 14px; }
  .menu__item kbd { display: none; }
  .menu__header { padding: 8px 12px 10px; }

  /* dialogos em tela cheia, com rodape fixo e botoes largos */
  .modal-backdrop { padding: 0; place-items: stretch; backdrop-filter: none; }
  .modal {
    width: 100%; height: 100%; max-height: none; border-radius: 0; border: 0; animation: sheet-in .22s var(--ease);
    overflow: hidden;
  }
  .modal__header, .modal__footer { flex: none; }
  .modal__body { min-height: 0; }
  .modal__header {
    padding: calc(12px + var(--safe-top)) calc(8px + var(--safe-right)) 10px calc(16px + var(--safe-left));
    border-bottom: 1px solid var(--c-border-soft); align-items: center;
  }
  .modal__title { font-size: 18px; }
  .modal__subtitle { font-size: 12.5px; }
  .modal__body { flex: 1; padding: 14px calc(16px + var(--safe-right)) 24px calc(16px + var(--safe-left)); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .modal__footer {
    flex-wrap: wrap; padding: 10px calc(16px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(16px + var(--safe-left)); border-radius: 0;
  }
  .modal__footer > fluent-button { flex: 1 1 0; min-width: 0; }
  .field-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .format-tiles { grid-template-columns: repeat(2, 1fr); }
  .print-thumb { min-height: 120px; padding: 12px; }
  .print-thumb img { max-height: 170px; }
  .print-layout, .newlabel, .setup-layout, .data-editor { gap: 16px; }
  .stock-list { max-height: none; }
  .preview-stage { min-height: 260px; max-height: none; padding: 12px; }
  .preview-bar { gap: 8px; }
  .data-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .inline-form, .filter-bar { flex-direction: column; align-items: stretch; }
  .agent-row { flex-wrap: wrap; }
  .token-row { flex-direction: column; align-items: stretch; }
  .data-result { flex-direction: column; align-items: stretch; }

  /* inicio */
  .app-header { height: calc(56px + var(--safe-top)); padding: var(--safe-top) calc(10px + var(--safe-right)) 0 calc(14px + var(--safe-left)); gap: 8px; }
  .app-header .brand__name { font-size: 15px; }
  .app-header .agent-chip__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .app-header .agent-chip { width: 36px; height: 36px; padding: 0; justify-content: center; }
  .avatar-button__name, .avatar-button > svg { display: none; }
  .home { padding: 0 calc(14px + var(--safe-right)) calc(40px + var(--safe-bottom)) calc(14px + var(--safe-left)); }
  .hero { margin: 14px 0 22px; padding: 22px 16px 16px; border-radius: 20px; gap: 0; }
  .eyebrow { font-size: 11px; margin-bottom: 8px; }
  .hero__title { font-size: 27px; margin-bottom: 16px; }
  .hero__search { padding: 4px 4px 4px 12px; border-radius: 14px; }
  .ai-button { font-size: 0; gap: 0; width: 40px; padding: 0; justify-content: center; }
  .quick-chips { flex-wrap: nowrap; overflow-x: auto; margin: 14px -16px 0; padding: 0 16px 4px; scrollbar-width: none; scroll-snap-type: x proximity; }
  .quick-chips::-webkit-scrollbar { display: none; }
  .quick-chips .chip { flex: none; scroll-snap-align: start; }
  .draft-banner { flex-wrap: wrap; margin-bottom: 20px; }
  .section { margin-top: 26px; }
  .section__header { gap: 10px; margin-bottom: 12px; }
  .section__header h2 { font-size: 19px; }
  .folder-chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
  .folder-chips::-webkit-scrollbar { display: none; }
  .folder-chips .pill-toggle { flex: none; }
  .card-grid, .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .design-card__thumb { height: 116px; padding: 10px; }
  .design-card__thumb img { max-height: 94px; }
  .design-card__meta { padding: 8px 10px 10px; }
  .template-card { padding-bottom: 10px; border-radius: 14px; }
  .template-card__thumb { height: 116px; padding: 12px; }
  .template-card__thumb img { max-height: 92px; }
  .template-card__name { font-size: 13.5px; padding: 2px 10px 0; }
  .template-card__desc { font-size: 11.5px; padding: 0 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

  /* login */
  .login__panel { padding: 28px calc(22px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(22px + var(--safe-left)); align-content: start; }
  .login__title { font-size: 28px; margin-top: 8px; }
  .login__form { max-width: none; }
  .login__form .field__input { height: 50px; }
  .login__submit { height: 50px; --base-height-multiplier: 12; }

  /* avisos acima das abas; ajuda em tela cheia */
  .toast-host { bottom: calc(var(--tabbar-h) + 18px + var(--safe-bottom)); width: calc(100% - 24px); }
  .toast { min-width: 0; max-width: none; }
  .help-panel { width: 100vw; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }
}

/* Login em tela estreita: faixa de arte compacta no topo */
@media (max-width: 900px) {
  .login { grid-template-rows: auto 1fr; }
  .login__art { display: grid; height: calc(200px + var(--safe-top)); padding: var(--safe-top) 0 0; overflow: hidden; }
  .login__stack { transform: scale(.58); transform-origin: center; }
  .login__quote { display: none; }
}

/* Celular deitado: a faixa de arte do login atrapalha */
@media (max-height: 500px) and (pointer: coarse) {
  .login__art { display: none; }
}
