:root {
  --app-frame-safe-top: min(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)), 7dvh);
  --app-frame-safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --app-frame-header-height: 42px;
  --app-frame-empty-footer-height: 1px;
  --app-frame-keyboard-inset: 0px;
  --app-frame-wood: #6f4634;
  --app-frame-wood-deep: #3f2920;
  --app-frame-ivory: #fffaf2;
  --app-frame-ink: #2b201b;
}

html.uranus-app-frame-document,
html.uranus-app-frame-document body {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--app-frame-ivory);
}

.uranus-app-frame-host {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100svh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--app-frame-ivory);
}

.uranus-app-frame,
.uranus-app-frame *,
.uranus-app-frame *::before,
.uranus-app-frame *::after {
  box-sizing: border-box;
}

.uranus-app-frame {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows:
    calc(var(--app-frame-safe-top) + var(--app-frame-header-height))
    minmax(0, 1fr)
    auto;
  overflow: hidden;
  color: var(--app-frame-ink);
  background: var(--app-frame-ivory);
}

/* A: HEADER */
.uranus-app-frame__header {
  position: relative;
  z-index: 300;
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr) 27px;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: calc(var(--app-frame-safe-top) + 2px) 8px 4px;
  color: #fff7e8;
  background: linear-gradient(90deg, var(--app-frame-wood-deep), var(--app-frame-wood));
  border-bottom: 1px solid #2f1e17;
  box-shadow: 0 3px 12px rgba(63, 41, 32, .22);
}

.uranus-app-frame__header,
.uranus-app-frame__header *,
.uranus-app-frame__footer,
.uranus-app-frame__footer * {
  touch-action: manipulation;
}

.uranus-app-frame__header-leading,
.uranus-app-frame__header-main {
  min-width: 0;
}

.uranus-app-frame__header-main {
  overflow: hidden;
}

/* A共通：ページ名／対象名／月を持つヘッダー（介護記録・希望休） */
body.app-frame-tool-header .uranus-app-frame__header {
  grid-template-columns: minmax(107px, auto) minmax(0, 1fr) 27px;
}

.app-frame-tool-leading,
.app-frame-tool-heading {
  min-width: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

.app-frame-tool-leading {
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-frame-tool-back {
  width: 27px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 247, 232, .28);
  border-radius: 4px;
  color: #fff7e8;
  background: rgba(255, 247, 232, .1);
  font-size: 24px;
  line-height: 1;
  text-decoration: none;
}

.app-frame-tool-title {
  min-width: 0;
  overflow: hidden;
  color: #fff7e8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-frame-tool-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
}

.app-frame-tool-target {
  min-width: 0;
  max-width: 150px;
  height: 25px;
  flex: 1 1 auto;
  padding: 0;
  border: 0;
  outline: 0;
  color: #fff7e8;
  background: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 14px;
  font-weight: 900;
  appearance: none;
  -webkit-appearance: none;
}

.app-frame-tool-target:disabled {
  color: #fff7e8;
  opacity: 1;
}

.app-frame-tool-target option {
  color: #2b201b;
  background: #fffaf2;
}

.app-frame-tool-month {
  flex: 0 0 auto;
  color: #fff7e8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .app-frame-tool-heading { gap: 5px; }
  .app-frame-tool-target { max-width: 132px; }
}

.uranus-app-frame__menu {
  width: 27px;
  height: 25px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 4px 5px;
  border: 1px solid rgba(255, 247, 232, .28);
  border-radius: 4px;
  background: rgba(255, 247, 232, .1);
}

.uranus-app-frame__menu span {
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: #fff7e8;
}

.uranus-app-frame__menu[aria-expanded="true"] {
  background: rgba(255, 247, 232, .24);
}

/* A-4: HEADERに所属し、Bを押し下げずに重なるシャッター */
.uranus-app-frame__drawer {
  position: absolute;
  z-index: 310;
  top: calc(100% + 1px);
  left: 0;
  right: 0;
  max-height: min(62dvh, 520px);
  overflow: auto;
  padding: 0;
  color: var(--app-frame-ink);
  background: #fff7e8;
  border-bottom: 1px solid var(--app-frame-wood-deep);
  box-shadow: 0 8px 18px rgba(63, 41, 32, .22);
  clip-path: inset(0 0 100% 0);
  visibility: hidden;
  pointer-events: none;
  transition: clip-path .18s ease-out, visibility 0s linear .18s;
}

.uranus-app-frame[data-drawer-open="true"] .uranus-app-frame__drawer {
  clip-path: inset(0);
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

/* B: 各ページの自由枠。スクロールの所有者は常にここ。 */
.uranus-app-frame__body {
  position: relative;
  z-index: 100;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--app-frame-ivory);
}

.uranus-app-frame__body-content {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* C: 通常Footer。Bと同じ基本階層。 */
.uranus-app-frame__footer {
  position: relative;
  z-index: 100;
  min-width: 0;
  min-height: 0;
  background: var(--app-frame-ivory);
}

.uranus-app-frame[data-footer-mode="empty"] .uranus-app-frame__footer {
  height: var(--app-frame-empty-footer-height);
  background: rgba(111, 70, 52, .28);
}

.uranus-app-frame[data-footer-mode="empty"] .uranus-app-frame__footer-content {
  display: none;
}

.uranus-app-frame[data-footer-mode="content"] .uranus-app-frame__footer {
  padding-bottom: 0;
}

.uranus-app-frame__footer-content {
  min-width: 0;
  background: var(--app-frame-ivory);
}

/* D: 入力モード専用Frame。ネイティブキーボードより上、A〜Cより前面。 */
.uranus-app-frame__editor {
  position: fixed;
  z-index: 500;
  left: 0;
  right: 0;
  bottom: var(--app-frame-keyboard-inset);
  max-height: calc(100dvh - var(--app-frame-safe-top) - 8px);
  overflow: auto;
  color: var(--app-frame-ink);
  background: var(--app-frame-ivory);
  box-shadow: 0 -5px 18px rgba(63, 41, 32, .2);
  opacity: 0;
  transform: translateY(12px);
  visibility: hidden;
  pointer-events: none;
}

.uranus-app-frame[data-editor-open="true"] .uranus-app-frame__editor {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}

.uranus-app-frame__editor-content {
  min-width: 0;
}

/* スマホ版の寸法・操作規則はこの範囲に集約する。 */
@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .uranus-app-frame__header {
    grid-template-columns: 27px minmax(0, 1fr) 27px;
  }

  .uranus-app-frame__body-content {
    scrollbar-width: none;
  }

  .uranus-app-frame__body-content::-webkit-scrollbar {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .uranus-app-frame__drawer,
  .uranus-app-frame__editor {
    transition: none;
  }
}
