/*
 * UI integration and responsive input layout.
 * Loaded last so the application can keep its existing data model while the
 * WordPress page, navigation and settings forms read as one continuous tool.
 */

html,
body {
  height: auto;
  min-height: 0;
  overflow-x: hidden;
}

body {
  overflow-y: hidden;
  background: #fff;
}

.app {
  display: block;
  min-height: 0;
  background: #fff;
}

/* Application toolbar. */
.appbar {
  min-height: 0;
  grid-template-columns: auto minmax(240px, 1fr) auto;
  gap: 20px;
  padding: 16px 24px;
  background: #fff;
  border-top: 0;
  border-bottom: 1px solid var(--line-soft);
  box-shadow: none;
}

.app-brand {
  height: auto;
  padding-left: 0;
}

.app-brand__product {
  font-size: 15px;
}

.project-name {
  flex-wrap: nowrap;
  gap: 7px 10px;
}

.project-name label {
  width: auto;
  flex: 0 0 auto;
}

.project-name input {
  min-width: 180px;
}

.app-actions {
  grid-column: auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.save-state {
  width: auto;
  margin: 0 4px 0 0;
  text-align: left;
}

/* The former left rail is now a full-width workflow navigator. */
.shell {
  display: block;
  min-height: 0;
}

.sidebar {
  display: block;
  min-height: 0;
  overflow: visible;
  background: #f7fbfa;
  border-right: 0;
  border-bottom: 1px solid var(--line-soft);
}

.sidebar__context {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 13px 24px 10px;
  background: transparent;
  border-bottom: 0;
}

.context-label {
  width: auto;
  margin: 0;
}

.context-month {
  font-size: 18px;
}

.context-meta {
  margin: 0;
}

.sidebar__label,
.sidebar__privacy {
  display: none;
}

.sidebar nav {
  margin-top: 2px;
  padding: 12px 24px 16px;
  background: linear-gradient(180deg, #e8f5f1 0%, #f2f9f7 100%);
  border-top: 1px solid #cfe6df;
  border-bottom: 1px solid #cfe6df;
}

.nav-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
}

.nav-group-label {
  display: none;
}

.nav-button {
  position: relative;
  min-height: 70px;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px;
  margin: 0;
  padding: 10px 11px;
  color: #214e49;
  background: #fff;
  border: 1px solid #b8d9d1;
  border-radius: 11px;
  box-shadow: 0 2px 5px rgba(20, 76, 69, .07);
  transition: border-color .16s ease, background-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.nav-button:hover {
  color: #075f57;
  background: #f8fffc;
  border-color: #69bcae;
  box-shadow: 0 5px 12px rgba(20, 76, 69, .12);
  transform: translateY(-1px);
}

.nav-button[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(135deg, #117f75 0%, #0a6c64 100%);
  border-color: #075f57;
  box-shadow: 0 7px 15px rgba(9, 91, 82, .22);
}

.nav-button__icon {
  width: 30px;
  height: 30px;
  color: #08766c;
  background: #dff2ed;
  border-radius: 8px;
}

.nav-button[aria-selected="true"] .nav-button__icon {
  color: #08665e;
  background: #fff;
}

.nav-button__copy strong {
  font-size: 13px;
}

.nav-button__copy small {
  margin-top: 3px;
  line-height: 1.35;
}

.nav-button__state {
  position: absolute;
  top: 5px;
  right: 7px;
}

.nav-button[aria-selected="true"] .nav-button__copy strong,
.nav-button[aria-selected="true"] .nav-button__copy small,
.nav-button[aria-selected="true"] .nav-button__state {
  color: #fff;
}

.nav-button:focus-visible {
  outline: 3px solid rgba(13, 126, 116, .28);
  outline-offset: 3px;
}

/* Keep the staff-code picker in the part of a tall embedded app that is
   currently visible in the WordPress page, not at the iframe's midpoint. */
.allowed-code-dialog {
  position: absolute;
  inset: auto auto auto 50%;
  top: var(--allowed-code-dialog-top, 1rem);
  margin: 0;
  transform: translateX(-50%);
  max-height: min(44rem, calc(var(--allowed-code-visible-height, 100vh) - 2rem));
  overflow: hidden;
}

.allowed-code-dialog__panel {
  display: flex;
  flex-direction: column;
  max-height: min(44rem, calc(var(--allowed-code-visible-height, 100vh) - 2rem));
  min-height: 0;
}

.allowed-code-dialog__panel > :not(.allowed-code-dialog__options) {
  flex-shrink: 0;
}

.allowed-code-dialog__options {
  flex: 1 1 auto;
  min-height: 0;
  grid-auto-rows: max-content;
  align-content: start;
  max-height: min(24rem, calc(var(--allowed-code-visible-height, 100vh) - 17rem));
}

/* The application content uses the page canvas instead of another panel. */
.main {
  overflow: visible;
  background: #fff;
}

.main__inner {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 25px 28px 38px;
}

.production-start {
  margin-bottom: 20px;
}

.screen-header {
  margin-bottom: 18px;
}

.screen-header h1:focus {
  outline: 0;
}

/* Tabs wrap into a readable grid; they no longer require sideways scrolling. */
.subnav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 7px;
  margin-bottom: 22px;
  padding: 7px;
  overflow: visible;
  background: #edf5f2;
  border-radius: 10px;
}

.subnav button {
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  color: #245d56;
  background: rgba(255, 255, 255, .88);
  border: 1px solid #c1dbd4;
  box-shadow: 0 2px 5px rgba(23, 63, 66, .06);
  white-space: normal;
  line-height: 1.35;
  transition: color .16s ease, background-color .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.subnav button:hover {
  color: #075f57;
  background: #f8fffc;
  border-color: #6eb8aa;
  box-shadow: 0 4px 9px rgba(23, 63, 66, .11);
  transform: translateY(-1px);
}

.subnav button[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(135deg, #117f75 0%, #0a6c64 100%);
  border-color: #075f57;
  box-shadow: 0 5px 12px rgba(9, 91, 82, .2);
}

/* Use headings, whitespace and one separator instead of nested framed cards. */
.workspace-card {
  margin: 0 0 10px;
  padding: 23px 4px 30px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  box-shadow: none;
}

[data-subpanel] > .workspace-card:last-child,
.workspace-card:last-child {
  border-bottom-color: transparent;
}

.workspace-card + .workspace-card,
.mf-panel .workspace-card + .workspace-card {
  margin-top: 8px;
}

.card-head {
  margin-bottom: 20px;
  padding: 0 0 13px;
  border-bottom: 1px solid var(--line-soft);
}

.monthly-settings,
.special-rules {
  border-top: 0;
}

.settings-tip {
  border-left: 3px solid #8fcbbb;
  border-radius: 5px;
}

/* Nested editable records are identified by a soft background, not another box. */
.planning-row,
.mf-night-day,
.mf-break-rule,
.mf-occurrence,
.special-rule-card {
  border: 0;
  border-left: 3px solid #b2d9cf;
  border-radius: 7px;
  background: #f6faf9;
  box-shadow: none;
}

.planning-choice,
.staff-final-weekdays,
.special-rule-detail {
  border-color: #dceae6;
  border-radius: 7px;
  box-shadow: none;
}

/* Table chrome is removed. Real schedule matrices retain their own scroll area. */
.table-wrap:has(> .responsive-form-table) {
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.responsive-form-table {
  background: transparent;
}

.responsive-form-table th {
  position: static;
}

.table-guide {
  margin-bottom: 12px;
}

.shift-wrap,
#shiftTableHost,
#shift-table-host,
.allowed-code-dialog__matrix {
  scrollbar-color: #83b8ab #edf4f1;
  scrollbar-width: auto;
}

.workflow-footer {
  margin-top: 18px;
  padding-top: 20px;
}

/* Editable records stay readable even when desktop tables have many columns. */
@media all {
  .table-wrap:has(> .responsive-form-table) {
    overflow: visible;
  }

  .responsive-form-table,
  .responsive-form-table tbody {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .responsive-form-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .responsive-form-table tbody {
    display: grid;
    gap: 14px;
  }

  .responsive-form-table tbody > tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px 20px;
    padding: 17px 18px;
    background: #f6faf9;
    border-left: 3px solid #aad5ca;
    border-radius: 8px;
  }

  .responsive-form-table tbody > tr:hover {
    background: #f2f8f6;
  }

  .responsive-form-table tbody > tr > :is(th, td) {
    position: static !important;
    display: grid;
    grid-template-columns: minmax(96px, .62fr) minmax(0, 1.38fr);
    align-items: center;
    gap: 8px 12px;
    min-width: 0;
    width: auto;
    min-height: 40px;
    padding: 0 !important;
    white-space: normal;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  .responsive-form-table tbody > tr > :is(th, td)::before {
    content: attr(data-label);
    color: #456760;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.45;
  }

  .responsive-form-table tbody > tr > .responsive-select-cell {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: start;
  }

  .responsive-form-table tbody > tr > .responsive-select-cell::before {
    white-space: nowrap;
  }

  .responsive-form-table :is(input:not([type="checkbox"]), select, textarea) {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .responsive-form-table .day-scope-control,
  .responsive-form-table .coverage-time-fields,
  .responsive-form-table .level-requirement-fields {
    width: 100%;
    min-width: 0;
  }

  /* Old JSON compatibility cells stay hidden in both table and card layouts. */
  .responsive-form-table:has(#staffBody) th:nth-child(5),
  .responsive-form-table:has(#staffBody) th:nth-child(9),
  .responsive-form-table:has(#staffBody) td:nth-child(5),
  .responsive-form-table:has(#staffBody) td:nth-child(9) {
    display: none !important;
  }
}

@media (max-width: 900px) {
  .responsive-form-table .level-requirement-fields {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .appbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 16px;
    padding: 13px 18px 15px;
  }

  .app-brand {
    grid-column: 1;
    grid-row: 1;
  }

  .app-actions {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .project-name {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .project-name input {
    flex: 1;
  }

  .sidebar__context {
    padding: 12px 18px 9px;
  }

  .sidebar nav {
    padding: 0 18px 15px;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .main__inner {
    width: 100%;
    padding: 22px 20px 34px;
  }

  .subnav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .appbar {
    grid-template-columns: 1fr;
  }

  .app-brand,
  .app-actions,
  .project-name {
    grid-column: 1;
  }

  .app-brand {
    grid-row: 1;
  }

  .project-name {
    grid-row: 2;
    flex-wrap: wrap;
  }

  .project-name label {
    width: 100%;
  }

  .app-actions {
    grid-row: 3;
    width: 100%;
    justify-self: stretch;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .save-state {
    width: 100%;
  }

  .sidebar__context {
    gap: 6px 11px;
  }

  .nav-button {
    min-height: 62px;
    grid-template-columns: 28px minmax(0, 1fr);
    padding: 8px;
  }

  .nav-button__icon {
    width: 27px;
    height: 27px;
  }

  .nav-button__copy small,
  .nav-button__state {
    display: none;
  }

  .main__inner {
    padding: 20px 16px 30px;
  }

  .subnav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 6px;
  }

  .workspace-card {
    padding: 19px 0 25px;
  }

  .responsive-form-table tbody > tr {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 15px;
  }

  .responsive-form-table tbody > tr > :is(th, td) {
    grid-column: auto;
  }

  .responsive-form-table tbody > tr > .responsive-select-cell {
    grid-column: 1 / -1;
  }

  .workflow-footer__actions,
  .workflow-footer__actions .btn {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .appbar {
    padding-inline: 14px;
  }

  .sidebar__context,
  .sidebar nav {
    padding-inline: 14px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main__inner {
    padding-inline: 13px;
  }

  .responsive-form-table tbody > tr > :is(th, td) {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .responsive-form-table tbody > tr > .responsive-select-cell {
    display: flex;
  }
}
