/* shell.css — iOS Shell Components */

/* === Title Bar === */
.title-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  flex-direction: column;
  background: var(--color-title-bar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 100;
  transition: border-color 0.2s ease;
  border-bottom: 1px solid transparent;
}

.title-bar--scrolled {
  border-bottom-color: var(--color-divider);
}

/* Main row: back | title | right */
.title-bar__main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding-left: 4px;
  padding-right: 4px;
  position: relative;
}

.title-bar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.title-bar__back:active { opacity: 0.5; }
.title-bar__back svg { width: 22px; height: 22px; }
.title-bar__back--hidden { visibility: hidden; }

.title-bar__title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 17px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
  text-align: center;
}

.title-bar__menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.title-bar__menu:active { opacity: 0.5; }
.title-bar__menu svg { width: 22px; height: 22px; }

.title-bar__right {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Right slot: inline page-specific controls next to title */
.title-bar__right-slot:empty { display: none; }
.title-bar__right-slot select {
  padding: 4px 8px;
  font-size: 14px;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}

/* Accessory: full-width second row below main */
.title-bar__accessory {
  padding: 0 12px 8px;
}
.title-bar__accessory:empty { display: none; }

.title-bar__accessory select {
  padding: 4px 8px;
  font-size: 14px;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  -webkit-appearance: none;
  appearance: none;
}

/* Project filter bar — sticky like segmented-control */
.project-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-surface);
  border-bottom: 0.5px solid var(--color-divider);
}

.project-filter__search {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  font-size: 15px;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
  color: var(--color-text);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.project-filter__search:focus {
  background: var(--color-bg-card);
  box-shadow: 0 0 0 1px var(--color-primary);
}

@media (max-width: 768px) {
  .project-filter {
    position: fixed;
    top: var(--title-bar-height, calc(44px + env(safe-area-inset-top, 0px)));
    left: 0;
    right: 0;
    z-index: 50;
  }
  .project-filter-spacer {
    height: 52px;
  }
}

@media (min-width: 769px) {
  .project-filter {
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .project-filter-spacer {
    display: none;
  }
}

/* Calendar accessory nav */
.calendar-accessory {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  justify-content: center;
}

.calendar-accessory__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: 8px;
}
.calendar-accessory__btn:active {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}

.calendar-accessory__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  min-width: 140px;
  text-align: center;
}

.calendar-accessory__today {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-primary);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.calendar-accessory__today:active {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}

/* Desktop: TitleBar hide */
@media (min-width: 769px) {
  .title-bar { display: none; }
}

/* === Tab Bar (Bottom Navigation) === */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(49px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--color-tab-bar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--color-divider);
  z-index: 100;
}

.tab-bar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 49px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  position: relative;
  color: var(--color-text-muted);
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s ease;
}

.tab-bar__item--active {
  color: var(--color-primary);
}

.tab-bar__item:active {
  transform: scale(0.92);
}

.tab-bar__item svg {
  width: 24px;
  height: 24px;
}

.tab-bar__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-primary);
  margin-top: 3px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tab-bar__item--active .tab-bar__dot {
  opacity: 1;
}

/* Desktop: TabBar hide */
@media (min-width: 769px) {
  .tab-bar { display: none; }
}

/* === Context Menu === */
.context-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(0,0,0,0.15);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.context-menu-backdrop--visible { opacity: 1; pointer-events: auto; }

.context-menu {
  position: fixed;
  top: calc(var(--title-bar-height, 44px) + 4px);
  right: 8px;
  min-width: 220px;
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: var(--shadow-elevated);
  border: 0.5px solid var(--color-divider);
  z-index: 111;
  overflow: hidden;
  transform: scale(0.9) translateY(-8px);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  transform-origin: top right;
  pointer-events: none;
}
.context-menu--visible { transform: scale(1) translateY(0); opacity: 1; pointer-events: auto; }

.context-menu__section {
  border-bottom: 0.5px solid var(--color-divider);
}
.context-menu__section:last-child { border-bottom: none; }

.context-menu__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.context-menu__item:active { background: var(--color-bg-subtle); }
.context-menu__item--danger { color: var(--color-error); }

.context-menu__user {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* === Bottom Sheet === */
.bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0);
  transition: background 0.3s ease;
  pointer-events: none;
}
.bottom-sheet-backdrop--visible { background: rgba(0,0,0,0.4); pointer-events: auto; }

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-radius: 12px 12px 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), max-height 0.3s ease;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.bottom-sheet--visible { transform: translateY(0); }
.bottom-sheet--compact { max-height: 35vh; }
.bottom-sheet--half { max-height: 55vh; }
.bottom-sheet--full { max-height: 92vh; }
.bottom-sheet--dragging { transition: none !important; }

.bottom-sheet__handle {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
  cursor: grab;
  flex-shrink: 0;
}
.bottom-sheet__handle-bar {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--color-text-muted);
  opacity: 0.3;
}

.bottom-sheet__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 12px;
  font-size: 17px;
  font-weight: 600;
  color: var(--color-text);
  flex-shrink: 0;
}

.bottom-sheet__close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-bg-subtle);
  border: none;
  font-size: 16px;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-overflow-scrolling: touch;
}

.bottom-sheet__footer {
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 0.5px solid var(--color-divider);
  flex-shrink: 0;
}

/* Desktop: centered modal instead of bottom sheet */
@media (min-width: 769px) {
  .bottom-sheet {
    position: fixed;
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    transition: transform 0.25s ease, opacity 0.25s ease, max-height 0.3s ease;
  }
  .bottom-sheet--visible {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  .bottom-sheet--compact { max-width: 480px; }
  .bottom-sheet--full { max-width: calc(100vw - 64px); height: calc(100vh - 64px); max-height: none; }
  .bottom-sheet--full .bottom-sheet__body { overflow: hidden; display: flex; flex-direction: column; }
  .bottom-sheet__handle { display: none; }
}

/* === Segmented Control === */
.segmented-control {
  position: sticky;
  top: var(--title-bar-height, calc(44px + env(safe-area-inset-top, 0px)));
  z-index: 50;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--color-surface);
  border-bottom: 0.5px solid var(--color-divider);
  padding: 0 16px;
  -webkit-overflow-scrolling: touch;
}
.segmented-control::-webkit-scrollbar { display: none; }

@media (max-width: 768px) {
  .segmented-control {
    position: fixed;
    top: var(--title-bar-height, calc(44px + env(safe-area-inset-top, 0px)));
    left: 0;
    right: 0;
  }
  /* Spacer to push content below fixed segmented control */
  .segmented-control-spacer {
    height: 38px;
  }
}

@media (min-width: 769px) {
  .segmented-control { top: 0; }
}

.segmented-control__item {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 15px;
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.segmented-control__item--active {
  color: var(--color-text);
  font-weight: 600;
}

.segmented-control__indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--color-primary);
  border-radius: 1px;
  transition: transform 0.25s ease, width 0.25s ease;
  pointer-events: none;
}

/* === Grouped List (iOS Table Style) === */
.grouped-section-header {
  padding: 8px 0 6px;
}

.grouped-card {
  background: var(--color-surface);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.grouped-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}
.grouped-list__item:active {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.grouped-list__divider {
  height: 0.5px;
  background: var(--color-divider);
  margin-left: 16px;
}

.grouped-list__left { flex: 1; min-width: 0; }
.grouped-list__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grouped-list__subtitle {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grouped-list__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 12px;
}
.grouped-list__date {
  font-size: 13px;
  color: var(--color-text-muted);
}
.grouped-list__amount {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
}

/* === Grouped Form (iOS Settings Style) === */
.grouped-form__group {
  background: var(--color-surface);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.grouped-form__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  min-height: 40px;
}

.grouped-form__divider {
  height: 0.5px;
  background: var(--color-divider);
  margin-left: 16px;
}

.grouped-form__row--stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.grouped-form__label {
  font-size: 15px;
  color: var(--color-text);
  flex-shrink: 0;
}

.grouped-form__input {
  text-align: right;
  border: none;
  background: none;
  font-size: 15px;
  color: var(--color-text-muted);
  padding: 0;
  min-width: 0;
  flex: 1;
  font-family: inherit;
}
.grouped-form__input:focus {
  color: var(--color-text);
  outline: none;
}

.grouped-form__input--color {
  width: 60px;
  height: 36px;
  padding: 2px;
  cursor: pointer;
  text-align: left;
  flex: 0;
}

.grouped-form__hint {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: normal;
}

.grouped-form__input--stacked {
  text-align: left;
  background: var(--color-bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.grouped-form__textarea {
  text-align: left;
  background: var(--color-bg);
  border-radius: 8px;
  padding: 10px 12px;
  border: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--color-text);
  resize: vertical;
  min-height: 60px;
  width: 100%;
}
.grouped-form__textarea:focus {
  outline: none;
}

.grouped-form__select-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-text-muted);
  font-size: 15px;
  position: relative;
}

.grouped-form__select {
  appearance: none;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--color-text-muted);
  text-align: right;
  padding-right: 18px;
  font-family: inherit;
  cursor: pointer;
}
.grouped-form__select:focus {
  color: var(--color-text);
  outline: none;
}

.grouped-form__suffix {
  font-size: 13px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  margin-left: 4px;
}

.grouped-form__toggle {
  position: relative;
  width: 51px;
  height: 31px;
  background: var(--color-bg-subtle);
  border-radius: 16px;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.grouped-form__toggle--active {
  background: var(--color-primary);
}
.grouped-form__toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.grouped-form__toggle--active .grouped-form__toggle-knob {
  transform: translateX(20px);
}

/* === Micro-Animations === */

/* Button tap scale */
.btn:active {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}

/* Tab bar item tap — defined above in .tab-bar__item:active */

/* Card tap feedback — transition already on .grouped-list__item */

/* Bottom sheet spring animation (keyframe definition) */
@keyframes sheetSpring {
  0% { transform: translateY(100%); }
  70% { transform: translateY(-2%); }
  100% { transform: translateY(0); }
}

/* === Page Transitions === */

/* Forward slide */
.page-enter {
  transform: translateX(100%);
}
.page-enter-active {
  transform: translateX(0);
  transition: transform 350ms cubic-bezier(0.25, 0.1, 0.25, 1);
}
.page-exit {
  /* Starting state for old page */
}
.page-exit-active {
  transform: translateX(-30%);
  opacity: 0.5;
  transition: all 350ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Backward slide */
.page-enter-back {
  transform: translateX(-30%);
  opacity: 0.5;
}
.page-enter-back-active {
  transform: translateX(0);
  opacity: 1;
  transition: all 350ms cubic-bezier(0.25, 0.1, 0.25, 1);
}
.page-exit-back {
  /* Starting state */
}
.page-exit-back-active {
  transform: translateX(100%);
  transition: transform 350ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Crossfade (tab switches, desktop) */
.page-crossfade-exit {
  opacity: 0;
  position: absolute;
}
.page-crossfade-enter {
  opacity: 0;
}
.page-crossfade-enter-active {
  opacity: 1;
  transition: opacity 150ms ease;
}

/* === Grouped Detail (Read-Only Key-Value) === */
.grouped-detail__value {
  font-size: 15px;
  color: var(--color-text-muted);
  text-align: right;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grouped-detail__value--empty {
  opacity: 0.5;
}
.grouped-detail__action {
  margin-left: 8px;
  flex-shrink: 0;
}

/* === Grouped Columns (2-Column Desktop Grid) === */
@media (min-width: 769px) {
  .grouped-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
  }
  .grouped-columns > .grouped-columns__full {
    grid-column: 1 / -1;
  }
}

/* === Status Filter === */
.status-filter__trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 9999px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  border: none;
  cursor: pointer;
  background: var(--color-primary);
  color: white;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-filter__trigger:active {
  transform: scale(0.95);
}
.status-filter__trigger svg {
  opacity: 0.7;
}

/* Bottom sheet content */
.status-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}

/* Group toggle bar — evenly distributed, distinct style */
.status-filter__groups {
  display: flex;
  width: 100%;
  gap: 6px;
  background: var(--color-bg-subtle);
  border-radius: 10px;
  padding: 3px;
}
.status-filter__group-btn {
  flex: 1;
  padding: 7px 0;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  color: var(--color-text-muted);
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-align: center;
}
.status-filter__group-btn--active {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.status-filter__group-btn:active {
  transform: scale(0.97);
}

.status-filter__divider {
  width: 100%;
  height: 0.5px;
  background: var(--color-divider);
  margin: 2px 0;
}

/* Individual phase chips */
.status-filter__chip {
  border-radius: 9999px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  border: none;
  cursor: pointer;
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
  transition: background 0.2s ease, color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.status-filter__chip--active {
  background: var(--color-primary);
  color: white;
}
.status-filter__chip:active {
  transform: scale(0.95);
}

/* === Section Header with Action Button === */
.grouped-section-header--with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 6px;
}
.grouped-section-header--with-action .btn {
  text-transform: none;
  letter-spacing: normal;
}

/* === Grouped Card Utilities === */
.grouped-card__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 4px;
  flex-wrap: wrap;
}
.grouped-card__header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.grouped-card .empty-state {
  padding: var(--spacing-md);
}

.grouped-card__info {
  padding: 2px 16px 4px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.grouped-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px 12px;
}

.grouped-card__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.grouped-card__table th,
.grouped-card__table td {
  padding: 6px 16px;
  text-align: left;
}
.grouped-card__table th {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 12px;
  text-transform: uppercase;
}
.grouped-card__table td {
  color: var(--color-text);
}
.grouped-card__table .text-right {
  text-align: right;
}
.grouped-card__table tbody tr {
  border-top: 0.5px solid var(--color-divider);
}
