.ui-layer {
  position: fixed;
  inset: 0;
  z-index: 1300;
}

.ui-layer[hidden] {
  display: none;
}

.ui-overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 27, 58, 0.48);
  backdrop-filter: blur(7px);
}

.ui-panel {
  position: absolute;
  left: 50%;
  width: min(calc(100% - 24px), 520px);
  transform: translateX(-50%) translateY(18px);
  border: 1px solid rgba(215, 199, 179, 0.9);
  border-radius: 22px;
  background: rgba(255, 250, 242, 0.98);
  box-shadow: 0 24px 60px rgba(26, 27, 58, 0.22);
  color: var(--color-text);
  max-height: min(calc(100dvh - 24px), 620px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body[data-theme='dark'] .ui-panel {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(36, 37, 31, 0.98);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}

.ui-panel[hidden] {
  display: none;
}

.ui-modal {
  top: 50%;
  max-width: 440px;
  transform: translate(-50%, -50%) scale(0.98);
}

.ui-sheet {
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  width: min(calc(100% - 20px), 560px);
  max-height: calc(100dvh - 32px);
}

.ui-panel-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-2);
  background: rgba(255, 250, 242, 0.98);
}

body[data-theme='dark'] .ui-panel-header {
  background: rgba(36, 37, 31, 0.98);
}

.ui-sheet,
.ui-sheet-form {
  touch-action: pan-y;
}

.ui-sheet input,
.ui-sheet select,
.ui-sheet button,
.ui-modal button {
  touch-action: manipulation;
}

.ui-panel-title {
  font-size: var(--font-size-base);
  line-height: 1.2;
}

.ui-panel-body {
  margin: 0;
  padding: var(--space-3) var(--space-4) 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.ui-sheet-form {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.ui-panel-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  padding: var(--space-4);
}

.ui-panel-actions .btn {
  width: 100%;
}

.ui-field {
  display: grid;
  gap: var(--space-2);
}

.ui-close-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: rgba(26, 27, 58, 0.06);
  color: var(--color-text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

/* Shared read-only Execution Energy value language. */
.energy-change-badge,
.energy-change {
  display: inline-flex;
  min-width: 46px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 7px;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.energy-change-badge.is-consume,
.energy-change.is-consume {
  background: #fde3e0;
  color: #a93c37;
}

.energy-change-badge.is-recover,
.energy-change.is-recover {
  background: #dff2e4;
  color: #267345;
}

.energy-change-badge.is-none,
.energy-change.is-none {
  background: color-mix(in srgb, var(--color-text-muted) 10%, transparent);
  color: var(--color-text-muted);
}

body[data-theme='dark'] .energy-change-badge.is-consume,
body[data-theme='dark'] .energy-change.is-consume {
  background: rgba(255, 117, 111, 0.16);
  color: #ffaaa5;
}

body[data-theme='dark'] .energy-change-badge.is-recover,
body[data-theme='dark'] .energy-change.is-recover {
  background: rgba(92, 190, 120, 0.16);
  color: #8ddd9f;
}

/*
 * Shared input-sheet primitives.
 *
 * Feature sheets keep their own widths and fields, while these classes make
 * the interaction contract consistent: reachable header, internal scrolling,
 * and a primary action that stays above the mobile safe area. Optional fields
 * should normally expand inline; a second sheet is reserved for a genuinely
 * long, searchable, or multi-select task.
 */
.ui-form-sheet {
  max-height: min(82dvh, 720px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 72px 96px;
  -webkit-overflow-scrolling: touch;
}

/* Opt-in structured sheet: fixed header/action areas with one scrolling body. */
.ui-form-sheet.is-structured {
  overflow: hidden;
}

.ui-form-sheet-layout,
.ui-form-sheet-view {
  min-height: 0;
  height: 100%;
}

.ui-form-sheet-layout {
  display: block;
}

.ui-form-sheet-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.ui-form-sheet-view[hidden] {
  display: none;
}

.ui-form-sheet-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.ui-form-sheet.is-structured .ui-form-sheet-header,
.ui-form-sheet.is-structured .ui-form-sheet-actions {
  position: relative;
  inset: auto;
  z-index: 2;
}

.ui-form-sheet-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-surface);
}

.ui-form-sheet-actions {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--color-surface) 96%, transparent);
  box-shadow: 0 -10px 24px rgba(26, 27, 58, 0.08);
  backdrop-filter: blur(14px);
}

.ui-form-sheet-actions .btn {
  width: 100%;
  min-height: 48px;
}

.ui-progressive-disclosure {
  border-width: 0 0 1px;
  border-style: solid;
  border-color: var(--border);
  background: transparent;
}

.ui-progressive-disclosure > summary {
  min-height: 52px;
  cursor: pointer;
}

body[data-theme='dark'] .ui-form-sheet-actions {
  background: color-mix(in srgb, var(--color-surface) 96%, transparent);
  box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.24);
}

.ui-close-button:hover {
  background: rgba(255, 94, 91, 0.12);
}

body[data-theme='dark'] .ui-close-button {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
}

.ui-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: min(280px, calc(100vw - 28px));
  padding: 8px 10px;
  border: 1px solid rgba(216, 200, 179, 0.9);
  border-radius: 10px;
  background: rgba(26, 27, 58, 0.96);
  color: #fff;
  box-shadow: 0 12px 28px rgba(26, 27, 58, 0.22);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  white-space: normal;
  word-break: keep-all;
}

.ui-tooltip[hidden] {
  display: none;
}

.ui-modal-open .ui-modal {
  transform: translate(-50%, -50%) scale(1);
}

.ui-sheet-open .ui-sheet {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 479px) {
  .ui-panel-actions {
    grid-template-columns: 1fr;
  }
}
