/**
 * TRN ERP — shared tools (tasks, calendar, storage, import) + U-patterns on app-shell.
 * Desktop Theme B (K/G/S/I) lives above the gates; mobile gates match trn-app-shell.css.
 * Loaded in layouts/app.blade.php immediately before trn-app-shell.css.
 */

/* ── Desktop Theme B: tasks / calendar / storage / imports ── */
.trn-tb-page.trn-page:not(.fund-work):not(.trn-talk):not(.trn-talk-iframe-page) {
  --tb-accent: var(--sd-accent, var(--trn-accent, #00c2f0));
}

.trn-tb-page:not(.fund-work) > .sd-module-toolbar {
  margin: 0 0 var(--tb-space-2, 16px);
  padding: 0.45rem 0.65rem;
  min-height: 0;
  border: 1px solid color-mix(in srgb, var(--tb-line, var(--trn-line)) 90%, transparent);
  border-radius: 14px;
  background: var(--tb-glass, color-mix(in srgb, var(--trn-surface, #fff) 88%, transparent));
  box-shadow: var(--tb-shadow, 0 8px 24px color-mix(in srgb, #000 8%, transparent));
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
}

.trn-tb-page:not(.fund-work) > .sd-module-toolbar::after {
  display: none;
}

html.trn-lowend .trn-tb-page:not(.fund-work) > .sd-module-toolbar,
html.update-slow .trn-tb-page:not(.fund-work) > .sd-module-toolbar {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: var(--tb-surface, var(--trn-surface, #fff));
}

.trn-tb-page:not(.fund-work) .filters.trn-filter-bar,
.trn-tb-page:not(.fund-work) form.filters.trn-filter-bar {
  margin-bottom: var(--tb-space-2, 16px);
  padding: var(--tb-space-2, 16px);
  border: 1px solid var(--tb-line, var(--trn-line));
  border-radius: var(--tb-radius, 16px);
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--tb-surface, var(--trn-surface, #fff)) 96%, #fff),
    color-mix(in srgb, var(--tb-surface, var(--trn-surface, #fff)) 90%, var(--tb-accent, var(--sd-accent)) 4%)
  );
  box-shadow: 0 1px 0 color-mix(in srgb, #fff 35%, transparent) inset;
}

html[data-theme="dark"] .trn-tb-page:not(.fund-work) .filters.trn-filter-bar,
html[data-theme="dark"] .trn-tb-page:not(.fund-work) form.filters.trn-filter-bar {
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--tb-surface, var(--trn-surface)) 94%, #1a2438),
    color-mix(in srgb, var(--tb-surface, var(--trn-surface)) 82%, #0d1524)
  );
  box-shadow: 0 1px 0 color-mix(in srgb, #fff 4%, transparent) inset;
}

.trn-tb-page:not(.fund-work) .trn-panel.trn-table-panel,
.trn-tb-page:not(.fund-work) .card.trn-panel {
  border-radius: var(--tb-radius, 16px);
  border-color: color-mix(in srgb, var(--tb-line, var(--trn-line)) 92%, transparent);
  box-shadow:
    0 1px 0 color-mix(in srgb, #fff 45%, transparent) inset,
    0 8px 24px color-mix(in srgb, #000 7%, transparent);
  overflow: clip;
}

.trn-tb-page:not(.fund-work) .trn-tasks-view-toggle {
  border-radius: 12px;
  border-color: color-mix(in srgb, var(--tb-line, var(--trn-line)) 95%, transparent);
  background: color-mix(in srgb, var(--tb-surface, var(--trn-surface)) 70%, transparent);
}

.trn-tb-page.trn-calendar-page:not(.fund-work) {
  --trn-cal-radius: var(--tb-radius, 16px);
  --trn-cal-radius-sm: var(--tb-radius-sm, 10px);
  --trn-cal-glass: var(--tb-glass, linear-gradient(165deg, rgba(255, 255, 255, 0.92), rgba(244, 247, 251, 0.82)));
  --trn-cal-glass-border: color-mix(in srgb, var(--tb-line, rgba(8, 17, 31, 0.08)) 100%, transparent);
  --trn-cal-shadow: var(--tb-shadow, 0 20px 48px rgba(8, 17, 31, 0.1));
}

.trn-tb-page.trn-calendar-page:not(.fund-work) .trn-calendar-filters,
.trn-tb-page.trn-calendar-page:not(.fund-work) .trn-calendar-main {
  border-radius: var(--tb-radius, 16px);
}

.trn-tb-page.trn-storage:not(.fund-work):not(.trn-storage--fund) > .trn-storage__brand {
  margin-bottom: 0.65rem;
  padding: 0.7rem 0.95rem;
  border-radius: var(--tb-radius, 16px);
  min-height: 0;
}

.trn-tb-page.trn-storage:not(.fund-work) .trn-storage-browser {
  border-radius: var(--tb-radius, 16px);
  border: 1px solid color-mix(in srgb, var(--st-line, var(--tb-line)) 92%, transparent);
  background: color-mix(in srgb, var(--st-surface, var(--tb-surface)) 96%, transparent);
  box-shadow: var(--tb-shadow, 0 8px 24px color-mix(in srgb, #000 7%, transparent));
}

.trn-tb-page.trn-wizard:not(.fund-work) .trn-wizard-stepper {
  border-radius: var(--tb-radius, 16px);
  border-color: color-mix(in srgb, var(--tb-line, var(--trn-line)) 90%, transparent);
  background: var(--tb-glass, var(--trn-surface-2));
  box-shadow: var(--tb-shadow, none);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
}

html.trn-lowend .trn-tb-page.trn-wizard:not(.fund-work) .trn-wizard-stepper,
html.update-slow .trn-tb-page.trn-wizard:not(.fund-work) .trn-wizard-stepper {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: var(--trn-surface-2);
}

@media (max-width: 960px) {
  body.sd-app {
    /* ── U01 empty state ── */
    .sd-empty-state img,
    .empty-state img {
      max-height: 120px;
      width: auto;
      height: auto;
    }

    .sd-empty-state strong,
    .empty-state strong {
      font-size: 1.25rem;
    }

    .empty-state__actions .btn {
      width: 100%;
      min-height: 44px;
    }

    /* ── U02 page header / module toolbar ── */
    .page-header {
      flex-direction: column;
      align-items: stretch;
      gap: 0.65rem;
    }

    .page-header .actions-row,
    .page-header .btn,
    .page-header a.btn {
      width: 100%;
    }

    .sd-module-toolbar {
      flex-wrap: wrap;
      gap: 0.65rem;
    }

    .sd-toolbar-actions {
      flex: 1 1 100%;
      flex-wrap: wrap;
      justify-content: flex-start;
      gap: 0.45rem;
    }

    /* ── U03 filters ── */
    .filters.trn-filter-bar,
    form.filters {
      display: flex;
      flex-wrap: wrap;
      gap: 0.65rem 0.75rem;
      align-items: flex-end;
      max-width: 100%;
    }

    .filters.trn-filter-bar > div,
  .filters.trn-filter-bar > .trn-filter-search {
      flex: 1 1 calc(50% - 0.5rem);
      min-width: 0;
    }

    .filters.trn-filter-bar .form-select,
    .filters.trn-filter-bar .form-control {
      width: 100%;
      min-width: 0;
      min-height: 48px;
      font-size: 16px;
    }

    /* ── K01 tasks list toolbar + view toggle ── */
    .trn-tasks-view-toggle {
      display: flex;
      width: 100%;
      max-width: 100%;
    }

    .trn-tasks-view-toggle__btn {
      flex: 1 1 0;
      justify-content: center;
      min-height: 44px;
    }

    .sd-toolbar-actions .trn-tasks-view-toggle {
      margin-right: 0;
    }

    .trn-tasks-board-page .page-header {
      flex-direction: column;
      align-items: stretch;
    }

    .trn-mobile-card .meta,
    .trn-mobile-card__title {
      min-width: 0;
      overflow-wrap: anywhere;
    }

  .trn-wizard .trn-mobile-card__title {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      gap: 0.25rem;
    }

    /* ── I01–I07 import wizard (L9 cards) ── */
    .trn-wizard .trn-list-table + .trn-mobile-cards,
    .trn-wizard [data-map-mobile],
    .trn-wizard [data-dup-mobile] {
      margin-top: 0.5rem;
    }

    .trn-wizard [data-map-mobile] .form-select,
    .trn-wizard [data-dup-mobile] .form-select {
      width: 100%;
      min-height: 48px;
      font-size: 16px;
    }

    .trn-wizard input[type="file"] {
      font-size: 16px;
      max-width: 100%;
    }

    .trn-wizard .trn-form-actions--sticky,
    .trn-wizard .actions-row.trn-form-actions--sticky {
      flex-direction: column-reverse;
      align-items: stretch;
      gap: 0.5rem;
    }

    .trn-wizard .trn-form-actions--sticky .btn,
    .trn-wizard .actions-row.trn-form-actions--sticky .btn {
      width: 100%;
      min-height: 44px;
    }

    .trn-import-act-links__item {
      min-height: 48px;
      display: flex;
      align-items: center;
    }

    /* ── G01 calendar filters as sheet trigger (collapsed default on phone in JS) ── */
    .trn-calendar-filters__head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.5rem;
    }

    #trnCalFiltersToggle {
      min-width: 44px;
      min-height: 44px;
    }

    /* ── S01 storage tree sheet (open via .is-tree-open on browser) ── */
    .trn-storage-browser.is-tree-open::before {
      content: '';
      position: fixed;
      inset: 0;
      z-index: 1048;
      background: rgba(4, 8, 14, 0.45);
    }

    .trn-storage-browser.is-tree-open .trn-storage-tree {
      display: block;
      position: fixed;
      z-index: 1049;
      left: 0;
      right: 0;
      bottom: var(--sd-chrome-bottom, 64px);
      top: auto;
      max-height: min(75dvh, 32rem);
      margin: 0;
      border-radius: 16px 16px 0 0;
      border-bottom: 0;
      box-shadow: 0 -12px 32px rgba(8, 17, 31, 0.22);
    }

    .trn-storage-tree-toggle {
      min-height: 44px;
    }

    .trn-storage-sidebar {
      bottom: var(--sd-chrome-bottom, 64px);
      max-height: min(calc(100dvh - var(--app-top-h, 56px) - var(--sd-chrome-bottom, 64px)), 70vh);
    }

    .trn-storage-crumbs {
      overflow-x: auto;
      flex-wrap: nowrap;
      scroll-snap-type: x proximity;
      -webkit-overflow-scrolling: touch;
    }

    .trn-storage-crumbs__chip:last-child {
      scroll-margin-inline-end: 12px;
    }

    /* Phone: list view, not 6-column grid */
    .trn-storage-grid {
      grid-template-columns: 1fr;
      gap: 0.35rem;
    }

    .trn-storage-tile {
      flex-direction: row;
      align-items: center;
      min-height: 48px;
      padding: 0.5rem 0.65rem;
    }
  }
}

@media (max-width: 720px) {
  body.sd-app .filters.trn-filter-bar > div,
  body.sd-app .filters.trn-filter-bar > .trn-filter-search {
    flex: 1 1 100%;
  }

  body.sd-app .trn-fullcalendar .fc-toolbar-chunk {
    width: 100%;
    justify-content: center;
  }

  body.sd-app .trn-fullcalendar .fc-toolbar-chunk:first-child {
    order: 1;
  }

  body.sd-app .trn-fullcalendar .fc-toolbar-chunk:nth-child(2) {
    order: 0;
    width: 100%;
  }

  body.sd-app .trn-fullcalendar .fc-toolbar-chunk:last-child {
    order: 2;
  }
}

/* Touch landscape — shared tools only (gate B) */
@media (min-width: 961px) and (max-width: 1366px) {
  html.trn-touch body.sd-app .sd-module-toolbar {
    flex-wrap: wrap;
  }

  html.trn-touch body.sd-app .trn-tasks-view-toggle__btn {
    min-height: 44px;
  }

  html.trn-touch body.sd-app .trn-storage-browser.is-tree-open .trn-storage-tree {
    left: 0;
    right: auto;
    width: min(320px, 100vw);
    bottom: var(--sd-chrome-bottom, 64px);
    max-height: calc(100dvh - var(--app-top-h, 56px) - var(--sd-chrome-bottom, 64px));
    border-radius: 0 16px 0 0;
  }
}