/* ENH-248 shared three-panel Table Play surface.
   The existing table renderer, action handlers and fit engine remain authoritative;
   this file owns the desktop composition and its communication workspace. */
body.table-mode {
  --table-v2-panel: #16231f;
  --table-v2-panel-ink: #f4fbf8;
  --table-v2-panel-line: #52645d;
  --table-v2-context: #12352e;
  --table-v2-communication: #f4efe4;
  --table-v2-communication-ink: #18211e;
  --table-v2-information: #fff8dd;
  --table-v2-information-ink: #18211e;
  --table-v2-button: #21483d;
  --table-v2-button-ink: #f4fff9;
}

/* At a live table, Menu is deliberately local: table actions, problem report,
   account commands and an explicit non-destructive return to the Lobby. */
body.table-mode #topbar-navigation > [data-nav] { display: none !important; }
body.table-mode #topbar-navigation > #tb-problem-report { display: block !important; }

body.table-mode #app.on,
body.table-mode #app.on:has(.felt[data-fit-layout]) {
  grid-template-columns: 180px minmax(0, 1fr) 280px;
  grid-template-rows: minmax(0, 1fr);
  gap: 6px;
}

body.table-mode #app.on:has(#table-workspace[data-phase=bidding]) {
  grid-template-columns: 190px minmax(0, 1fr) 280px;
}

body.table-mode #app.on > .rail,
body.table-mode #app.on:has(.felt[data-fit-layout]) > .rail {
  grid-column: 1;
  grid-row: 1;
  padding: 6px;
  color: var(--table-v2-panel-ink);
  border-color: var(--table-v2-panel-line);
  background: var(--table-v2-panel);
}

body.table-mode #app.on > .felt,
body.table-mode #app.on:has(.felt[data-fit-layout]) > #table-workspace {
  grid-column: 2;
  grid-row: 1;
}

.table-v2-fullscreen-strip { display: none; }

body.table-mode #table-communication {
  display: flex;
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  color: var(--table-v2-communication-ink);
  border: 1px solid #aebcb7;
  border-radius: 8px;
  background: var(--table-v2-communication);
}

body.table-mode #table-communication > header {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: stretch;
  gap: 6px;
  padding: 8px;
  color: var(--table-v2-panel-ink);
  border-bottom: 1px solid var(--table-v2-panel-line);
  background: var(--table-v2-panel);
}

body.table-mode #table-communication-chat-label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  min-width: 0;
  min-height: 42px;
  padding: 5px 8px;
  color: #f4d465;
  border: 2px solid #75613b;
  border-radius: 6px;
  background: #17130f;
}

body.table-mode #table-communication-chat-label img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

body.table-mode #table-communication-chat-label strong {
  font-size: 17px;
  letter-spacing: .02em;
}
body.table-mode #table-chat-service-state {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  color: #ffb2a8;
}
body.table-mode #table-chat-service-state[data-online="true"] { color: #a6efc1; }

body.table-mode #table-communication-notifications {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 42px;
  padding: 6px 9px;
  color: var(--gui-ink);
  border: 2px solid #9fb1aa;
  border-radius: 6px;
  background: var(--gui-surface);
  font: 750 16px/1.2 var(--gui-face), system-ui, sans-serif;
  text-align: center;
}

body.table-mode #table-communication-notifications > span:first-child { font-size: 22px; }
body.table-mode #table-communication-notifications.has-pending {
  border-color: #9c6800;
  background: #fff0c9;
  box-shadow: 0 0 0 2px #f4d77e;
}
body.table-mode #table-communication-notifications.has-new {
  outline: 3px solid #b98700;
  outline-offset: 1px;
}

body.table-mode #table-communication.chat-popover-open,
body.table-mode #table-communication.chat-popover-open #table-chat-slot { overflow: visible; }
body.table-mode #app:fullscreen:has(#table-communication.chat-popover-open) { overflow: visible; }

body.table-mode #table-chat-slot {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex: 1 1 auto;
}

body.table-mode #direct-chat-host {
  display: block;
  position: static;
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 0;
  flex: 1 1 auto;
  background: transparent;
}

body.table-mode #direct-chat-host kb-chat-panel { height: 100%; }
body.table-mode #table-chat-unavailable { margin: 10px; color: #5b6964; }

/* The information rail stays visually separate from the protected felt. */
body.table-mode #table-controls #board-panel {
  color: var(--table-v2-information-ink);
  border: 1px solid #d4bb64;
  background: var(--table-v2-information);
}
body.table-mode #table-controls #gui-play-actions {
  border-top-color: var(--table-v2-panel-line);
}
body.table-mode #table-controls #gui-play-actions button {
  min-height: 42px;
  padding: 7px 8px;
  color: var(--table-v2-button-ink);
  border: 1px solid #759288;
  border-radius: 5px;
  background: var(--table-v2-button);
  font-weight: 750;
}
body.table-mode #table-controls #gui-play-actions button:disabled {
  color: #b8c5c0;
  border-color: #52645d;
  background: #263b35;
}

body.table-mode[data-table-panel-side="right"] #app.on > .rail,
body.table-mode[data-table-panel-side="right"] #app.on:has(.felt[data-fit-layout]) > .rail {
  grid-column: 3;
}
body.table-mode[data-table-panel-side="right"] #table-communication { grid-column: 1; }
body.table-mode #table-controls #gui-play-actions button:focus-visible,
body.table-mode #table-communication button:focus-visible {
  outline: 3px solid #f4d465;
  outline-offset: 2px;
}

/* Native Fullscreen keeps the tracked logo and a clear exit action inside the
   fullscreen element. Escape remains the browser-native exit path. */
body.table-mode #app:fullscreen {
  box-sizing: border-box;
  display: grid !important;
  grid-template-columns: 180px minmax(0, 1fr) 280px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  width: 100%;
  height: 100%;
  padding: 6px;
  overflow: hidden;
  background: var(--gui-bg);
}
body.table-mode #app:fullscreen .table-v2-fullscreen-strip {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 1;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 4px 8px;
  color: #fff;
  border-radius: 5px;
  background: var(--table-v2-context);
}
body.table-mode #app:fullscreen .table-v2-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #f4d465;
}
body.table-mode #app:fullscreen .table-v2-brand img {
  width: 38px;
  height: 30px;
  object-fit: contain;
}
body.table-mode #app:fullscreen #table-v2-fullscreen-context {
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.table-mode #app:fullscreen #table-v2-fullscreen-exit {
  display: inline-block;
  min-height: 34px;
  padding: 5px 10px;
  color: #17231f;
  border: 1px solid #d6c36f;
  border-radius: 5px;
  background: #f4d465;
  font-weight: 800;
}
body.table-mode #app:fullscreen > .rail,
body.table-mode #app:fullscreen > #table-workspace,
body.table-mode #app:fullscreen > #table-communication {
  grid-row: 2;
}

@media (max-width: 1180px) {
  body.table-mode #app.on,
  body.table-mode #app.on:has(.felt[data-fit-layout]),
  body.table-mode #app.on:has(#table-workspace[data-phase=bidding]) {
    grid-template-columns: 150px minmax(0, 1fr) 220px;
  }
  body.table-mode #table-communication > header { padding: 6px; }
  body.table-mode #table-communication-chat-label { gap: 5px; padding-inline: 6px; }
  body.table-mode #table-communication-chat-label img { width: 27px; height: 27px; }
  body.table-mode #table-communication-chat-label strong { font-size: 17px; }
  body.table-mode #table-communication-notifications { padding-inline: 6px; }
}

/* The dedicated phone design is a later integration stage. On today's narrow
   browser surface, preserve the proven protected-table layout and suppress the
   optional communication rail rather than stealing space from hands. */
@media (max-width: 900px) {
  body.table-mode #app.on,
  body.table-mode #app.on:has(.felt[data-fit-layout]),
  body.table-mode #app.on:has(#table-workspace[data-phase=bidding]) {
    grid-template-columns: 150px minmax(0, 1fr);
  }
  body.table-mode #table-communication { display: none; }
  body.table-mode[data-table-panel-side="right"] #app.on > .rail,
  body.table-mode[data-table-panel-side="right"] #app.on:has(.felt[data-fit-layout]) > .rail { grid-column: 1; }
}

/* ENH-058 phone composition. This block intentionally follows the protected
   narrow-desktop rules above so a phone receives a vertically staged table:
   status strip, full-width play surface, and action bar. */
@media (max-width: 560px) {
  body.table-mode #app.on,
  body.table-mode #app.on:has(.felt[data-fit-layout]),
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto 116px;
    gap: 4px;
  }
  body.table-mode #app.on > .rail,
  body.table-mode #app.on:has(.felt[data-fit-layout]) > .rail,
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) > .rail,
  body.table-mode #app.on > .rail #table-controls,
  body.table-mode #app.on:has(.felt[data-fit-layout]) > .rail #table-controls,
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) > .rail #table-controls {
    display: contents;
  }
  body.table-mode #app.on > #table-workspace,
  body.table-mode #app.on:has(.felt[data-fit-layout]) > #table-workspace,
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) > #table-workspace {
    grid-column: 1;
    grid-row: 2;
  }
  body.table-mode[data-table-panel-side="right"] #app.on > .rail,
  body.table-mode[data-table-panel-side="right"] #app.on:has(.felt[data-fit-layout]) > .rail {
    grid-column: auto;
  }
  body.table-mode #table-controls #board-panel {
    grid-column: 1;
    grid-row: 1;
  }
  body.table-mode #table-controls #gui-play-actions {
    grid-column: 1;
    grid-row: 3;
  }
  body.table-mode #table-communication {
    display: flex;
    grid-column: 1;
    grid-row: 4;
    min-width: 0;
    min-height: 0;
    height: 116px;
    overflow: visible;
  }
  body.table-mode #table-communication > header {
    display: none;
  }
  body.table-mode #table-chat-slot {
    min-height: 0;
    height: 100%;
  }
  body.table-mode.phone-table-chat-hidden #app.on,
  body.table-mode.phone-table-chat-hidden #app.on:has(.felt[data-fit-layout]),
  body.table-mode.phone-table-chat-hidden #app.on:has(#table-workspace[data-phase="bidding"]),
  body.table-mode:not(.chat-enabled) #app.on,
  body.table-mode:not(.chat-enabled) #app.on:has(.felt[data-fit-layout]),
  body.table-mode:not(.chat-enabled) #app.on:has(#table-workspace[data-phase="bidding"]) {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  body.table-mode.phone-table-chat-hidden #table-communication,
  body.table-mode:not(.chat-enabled) #table-communication {
    display: none;
  }
}

/* Reference2 landscape phone composition.  This must follow the desktop
   three-panel breakpoints above: the right edge is the compact command rail,
   not the optional communication workspace. */
@media (max-height: 560px) and (min-width: 561px) and (max-width: 1000px) {
  body.table-mode #app.on,
  body.table-mode #app.on:has(.felt[data-fit-layout]),
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) {
    grid-template-columns: minmax(0, 1fr) 92px;
    grid-template-rows: 34px minmax(0, 1fr);
    gap: 2px;
  }
  body.table-mode #app.on > .rail,
  body.table-mode #app.on:has(.felt[data-fit-layout]) > .rail,
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) > .rail,
  body.table-mode #app.on > .rail #table-controls,
  body.table-mode #app.on:has(.felt[data-fit-layout]) > .rail #table-controls,
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) > .rail #table-controls {
    display: contents;
  }
  body.table-mode #app.on > #table-workspace,
  body.table-mode #app.on:has(.felt[data-fit-layout]) > #table-workspace,
  body.table-mode #app.on:has(#table-workspace[data-phase="bidding"]) > #table-workspace {
    grid-column: 1;
    grid-row: 2;
  }
  body.table-mode #table-controls #board-panel {
    grid-column: 1;
    grid-row: 1;
  }
  body.table-mode #table-controls #gui-play-actions {
    grid-column: 2;
    grid-row: 1 / 3;
  }
  body.table-mode #table-communication { display: none; }
  body.table-mode[data-table-panel-side="right"] #app.on > .rail,
  body.table-mode[data-table-panel-side="right"] #app.on:has(.felt[data-fit-layout]) > .rail {
    grid-column: auto;
  }
}
