/* Adaptive application shell. Mobile UI is driven by logical viewport and input
   capabilities; JavaScript adds .is-mobile-ui early, with media-only fallbacks. */

html.is-mobile-ui {
  --sidebar: 0px;
  height: 100%;
  overflow: hidden;
}

html.is-mobile-ui .sidebar {
  display: none;
}

html.is-mobile-ui .main-content {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  margin-inline-start: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: calc(66px + env(safe-area-inset-top)) 12px calc(80px + env(safe-area-inset-bottom));
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

html.is-mobile-ui .main-content::-webkit-scrollbar {
  display: none;
}

html.is-mobile-ui .mobile-header {
  display: flex;
}

html.is-mobile-ui .bottom-nav {
  display: grid;
}

html.is-mobile-ui body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  font-size: 14px;
}

html.is-mobile-ui .app-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

html.is-mobile-ui .content-frame {
  width: 100%;
}

html.is-mobile-ui .page-heading {
  align-items: flex-start;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 14px;
}

html.is-mobile-ui .page-heading h1 {
  font-size: clamp(27px, 7vw, 34px);
}

html.is-mobile-ui .heading-actions {
  width: 100%;
}

body.profile-menu-open,
body.avatar-crop-open { overflow: hidden; }

/* Keep form controls at iOS' non-zooming text size while surrounding UI remains compact. */
html.is-mobile-ui.is-touch-ui input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
html.is-mobile-ui.is-touch-ui select,
html.is-mobile-ui.is-touch-ui textarea { font-size: 16px; }

html.is-mobile-ui .settings-layout,
html.is-mobile-ui .dashboard-grid,
html.is-mobile-ui .form-layout,
html.is-mobile-ui .detail-layout,
html.is-mobile-ui .catalog-grid,
html.is-mobile-ui .auth-layout {
  grid-template-columns: 1fr;
}

html.is-mobile-ui .auth-visual { display: none; }
html.is-mobile-ui .auth-main { min-height: 100dvh; padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom)); }
html.is-mobile-ui .field-grid,
html.is-mobile-ui .field-grid-three,
html.is-mobile-ui .facts { grid-template-columns: 1fr; }
html.is-mobile-ui .form-sticky,
html.is-mobile-ui .catalog-form { position: static; }
html.is-mobile-ui .settings-nav { position: static; display: flex; overflow-x: auto; }
html.is-mobile-ui .settings-nav a { flex: 0 0 auto; white-space: nowrap; }

.mobile-header {
  position: fixed;
  z-index: 30;
  inset: 0 0 auto;
  height: calc(56px + env(safe-area-inset-top));
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: calc(7px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 7px max(12px, env(safe-area-inset-left));
  overflow: visible;
  border-bottom-color: rgba(79, 91, 84, .12);
  background: rgba(250, 248, 242, .9);
  box-shadow: 0 5px 20px rgba(31, 45, 39, .045);
}

.mobile-header .brand-compact {
  flex: 0 1 auto;
  min-width: 0;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}

.mobile-header .brand-compact .brand-mark {
  width: 35px;
  height: 35px;
  flex-basis: 35px;
  border: 0;
  border-radius: 11px;
  background: var(--ink);
  font-size: 17px;
}

.mobile-header .brand-compact strong {
  font-size: 14px;
  letter-spacing: .1em;
}

.mobile-brand-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
  line-height: 1.1;
}

.mobile-brand-copy small {
  overflow: hidden;
  color: var(--ink-faint);
  font-size: 9px;
  font-weight: 690;
  letter-spacing: .04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-account {
  position: relative;
  z-index: 2;
  min-width: 0;
  margin-inline-start: auto;
}

.mobile-profile-trigger {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 2px 1px 2px 8px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}

.mobile-profile-trigger[aria-expanded="true"] {
  background: rgba(54, 94, 80, .08);
}

.mobile-profile-name {
  max-width: min(30vw, 156px);
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
  line-height: 1.2;
  text-align: start;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  --avatar-bg: #c7a76c;
  --avatar-fg: #24362e;
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  overflow: hidden;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, .88);
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--avatar-fg);
  box-shadow: 0 5px 13px rgba(31, 45, 39, .18), 0 0 0 1px rgba(31, 45, 39, .08);
  font-weight: 850;
  isolation: isolate;
}

.user-avatar-header {
  width: 43px;
  height: 43px;
  flex-basis: 43px;
  margin: 0;
  font-size: 15px;
}

.user-avatar[data-avatar-tone="0"] { --avatar-bg: #d7b982; --avatar-fg: #344036; }
.user-avatar[data-avatar-tone="1"] { --avatar-bg: #a9c8ba; --avatar-fg: #24473b; }
.user-avatar[data-avatar-tone="2"] { --avatar-bg: #d7a994; --avatar-fg: #59372d; }
.user-avatar[data-avatar-tone="3"] { --avatar-bg: #b5bed7; --avatar-fg: #343d59; }
.user-avatar[data-avatar-tone="4"] { --avatar-bg: #d6c990; --avatar-fg: #514a27; }
.user-avatar[data-avatar-tone="5"] { --avatar-bg: #bdadd2; --avatar-fg: #49365d; }
.user-avatar[data-avatar-tone="6"] { --avatar-bg: #98c8ca; --avatar-fg: #244a4c; }
.user-avatar[data-avatar-tone="7"] { --avatar-bg: #c4c99d; --avatar-fg: #404829; }

.user-avatar-fallback {
  position: relative;
  z-index: 0;
  line-height: 1;
}

.user-avatar img {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-menu-backdrop {
  position: fixed;
  z-index: 42;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(21, 31, 27, .18);
  backdrop-filter: blur(1px);
}

.profile-popover {
  position: fixed;
  z-index: 43;
  top: calc(61px + env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: min(320px, calc(100vw - 20px));
  overflow: hidden;
  padding: 8px;
  border: 1px solid rgba(62, 77, 69, .12);
  border-radius: 18px;
  background: rgba(255, 253, 248, .98);
  box-shadow: 0 22px 55px rgba(31, 45, 39, .2), 0 3px 10px rgba(31, 45, 39, .08);
  transform-origin: top right;
  animation: profile-popover-in .18s cubic-bezier(.2, .8, .2, 1);
}

@keyframes profile-popover-in {
  from { opacity: 0; transform: translateY(-7px) scale(.975); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.profile-popover-summary {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 8px 9px 12px;
  border-bottom: 1px solid var(--line);
}

.profile-popover-summary .user-avatar {
  width: 39px;
  height: 39px;
  flex-basis: 39px;
  box-shadow: 0 3px 9px rgba(31, 45, 39, .12);
}

.profile-popover-summary > span:last-child {
  display: grid;
  min-width: 0;
  line-height: 1.35;
}

.profile-popover-summary strong,
.profile-popover-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-popover-summary strong { font-size: 13px; }
.profile-popover-summary small { color: var(--ink-faint); font-size: 10px; }

.profile-popover-item,
.profile-popover-language,
.profile-popover-logout button {
  display: grid;
  width: 100%;
  min-height: 44px;
  grid-template-columns: 23px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 680;
  text-align: start;
}

.profile-popover-item:hover,
.profile-popover-item:focus-visible,
.profile-popover-logout button:hover,
.profile-popover-logout button:focus-visible {
  background: var(--paper);
}

.profile-popover-language {
  grid-template-columns: 23px minmax(54px, 1fr) auto;
  margin-block: 4px 1px;
}

.profile-popover-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: var(--green-deep);
}

.profile-popover-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

.language-switcher {
  display: flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
}

.language-switcher button {
  min-width: 32px;
  min-height: 27px;
  padding: 0 5px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.language-switcher button[aria-checked="true"] {
  background: var(--surface-strong);
  color: var(--green-deep);
  box-shadow: 0 1px 5px rgba(31, 45, 39, .1);
}

.profile-popover-logout {
  margin: 5px 0 0;
  padding-top: 5px;
  border-top: 1px solid var(--line);
}

.profile-popover-logout button {
  grid-template-columns: 23px minmax(0, 1fr);
  background: #fbefed;
  color: #9a4642;
  cursor: pointer;
}

.profile-popover-logout .profile-popover-icon { color: #a64c47; }

.bottom-nav {
  position: fixed;
  z-index: 31;
  inset: auto 0 0;
  height: calc(64px + env(safe-area-inset-bottom));
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, .97);
  padding-bottom: env(safe-area-inset-bottom);
  backdrop-filter: blur(15px);
  box-shadow: 0 -7px 24px rgba(31, 45, 39, .055);
}

.bottom-nav.is-member { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.bottom-nav.is-member .bottom-add { grid-column: 3; }
.bottom-nav.is-member .member-status-link { grid-column: 5; }

.bottom-nav a { display: grid; justify-items: center; gap: 2px; color: var(--ink-faint); }
.bottom-nav a > span { font-size: 19px; line-height: 1; }
.bottom-nav small { max-width: 100%; overflow: hidden; font-size: 9px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.bottom-nav a.is-active { color: var(--green); }
.bottom-nav .bottom-add .bottom-add-icon {
  position: relative;
  overflow: hidden;
  display: grid;
  width: 54px;
  height: 54px;
  margin-top: -31px;
  place-items: center;
  border: 1px solid rgba(226, 205, 151, .72);
  border-radius: 18px;
  background-color: #244f40;
  background-image:
    radial-gradient(circle at 34% 28%, rgba(255, 246, 207, .16), transparent 34%),
    repeating-conic-gradient(from 45deg at 50% 50%, rgba(232, 211, 157, .08) 0 12.5%, transparent 0 25%),
    linear-gradient(145deg, #3f715e 0%, #2f604f 45%, #1c4035 100%);
  color: #f3e4b7;
  box-shadow:
    inset 0 0 0 3px rgba(20, 49, 39, .5),
    inset 0 0 0 4px rgba(231, 211, 157, .22),
    0 13px 29px rgba(33, 68, 55, .34),
    0 3px 9px rgba(42, 77, 64, .24);
  transform: translateY(0);
  transition: box-shadow .2s ease, transform .2s ease;
}
.bottom-nav .bottom-add .bottom-add-icon::before {
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(240, 221, 169, .38);
  border-radius: 11px;
  background:
    linear-gradient(90deg, currentColor 0 5px, transparent 0) 0 0 / 10px 1px no-repeat,
    linear-gradient(currentColor 0 5px, transparent 0) 0 0 / 1px 10px no-repeat,
    linear-gradient(270deg, currentColor 0 5px, transparent 0) 100% 100% / 10px 1px no-repeat,
    linear-gradient(0deg, currentColor 0 5px, transparent 0) 100% 100% / 1px 10px no-repeat;
  color: rgba(240, 221, 169, .34);
  content: "";
  pointer-events: none;
}
.bottom-nav .bottom-add .bottom-add-icon::after {
  position: absolute;
  inset: -50% 35% -50% -25%;
  background: linear-gradient(90deg, transparent, rgba(255, 247, 218, .18), transparent);
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: rotate(24deg) translateX(-120%);
}
.bottom-nav .bottom-add:active .bottom-add-icon {
  box-shadow: inset 0 0 0 3px rgba(20, 49, 39, .5), inset 0 0 0 4px rgba(231, 211, 157, .2), 0 7px 16px rgba(42, 77, 64, .28);
  transform: translateY(2px) scale(.96);
}
.bottom-add-glyph { position: relative; z-index: 1; width: 39px; height: 39px; overflow: visible; }
.bottom-add-glyph-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 2px rgba(11, 35, 27, .5));
  transition: d .64s cubic-bezier(.34, -.12, .22, 1.22), stroke .24s ease;
}
.bottom-add.is-launching .bottom-add-icon,
.bottom-add.is-arriving .bottom-add-icon { animation: bottom-add-seal-pulse .74s cubic-bezier(.2, .8, .2, 1) both; }
.bottom-add.is-launching .bottom-add-icon::after,
.bottom-add.is-arriving .bottom-add-icon::after { animation: bottom-add-seal-glint .72s ease-out both; }
.bottom-add.is-smiling .bottom-add-glyph-stroke { stroke: #ffe9aa; }

@keyframes bottom-add-seal-pulse {
  0% { transform: translateY(0) rotate(0) scale(1); }
  34% { transform: translateY(1px) rotate(-3deg) scale(.94); }
  72% { transform: translateY(-2px) rotate(2deg) scale(1.055); }
  100% { transform: translateY(0) rotate(0) scale(1); }
}
@keyframes bottom-add-seal-glint {
  0% { opacity: 0; transform: rotate(24deg) translateX(-120%); }
  28% { opacity: 1; }
  100% { opacity: 0; transform: rotate(24deg) translateX(235%); }
}

/* Profile */
.profile-page { max-width: 920px; }
.profile-page-heading { margin-bottom: 18px; }
.profile-layout { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 16px; }
.profile-identity-card, .profile-security-card { padding: 20px; }

.profile-avatar-editor {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 19px;
  border-bottom: 1px solid var(--line);
}

.user-avatar-profile {
  width: 88px;
  height: 88px;
  flex-basis: 88px;
  border-width: 3px;
  font-size: 27px;
}

.profile-avatar-actions { display: grid; min-width: 0; gap: 2px; }
.profile-avatar-actions strong { font-size: 15px; }
.profile-avatar-actions small { color: var(--ink-faint); font-size: 11px; line-height: 1.45; }
.profile-inline-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.profile-inline-actions form { margin: 0; }
.profile-avatar-delete { color: var(--danger); }
.profile-name-block { display: grid; gap: 4px; padding-top: 17px; }
.profile-name-block > span { color: var(--ink-faint); font-size: 11px; font-weight: 720; }
.profile-name-block > small { overflow: hidden; color: var(--ink-faint); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.profile-name-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.profile-name-row > strong { padding-top: 3px; font-size: 18px; overflow-wrap: anywhere; }

.profile-name-editor { position: relative; flex: 0 0 auto; }
.profile-name-editor summary {
  padding: 5px 8px;
  border-radius: 8px;
  color: var(--green-deep);
  cursor: pointer;
  font-size: 11px;
  font-weight: 760;
  list-style: none;
}
.profile-name-editor summary::-webkit-details-marker { display: none; }
.profile-name-editor[open] summary { background: var(--green-soft); }
.profile-name-form {
  position: absolute;
  z-index: 5;
  top: calc(100% + 7px);
  right: 0;
  display: grid;
  width: min(310px, calc(100vw - 42px));
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-strong);
  box-shadow: var(--shadow-md);
}
.profile-name-form input { width: 100%; }

.profile-section-heading { padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.profile-section-heading h2 { margin-bottom: 3px; font-size: 17px; }
.profile-section-heading span { color: var(--ink-faint); font-size: 11px; }
.profile-secondary-nav { display: grid; }
.profile-secondary-nav a {
  display: grid;
  min-height: 65px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}
.profile-secondary-nav a:last-child { border-bottom: 0; padding-bottom: 0; }
.profile-secondary-nav a > span:first-child { display: grid; gap: 2px; }
.profile-secondary-nav strong { font-size: 13px; }
.profile-secondary-nav small { color: var(--ink-faint); font-size: 10px; }
.profile-secondary-nav a > span:last-child { color: var(--ink-faint); font-size: 24px; font-weight: 300; }
.profile-avatar-upload { display: none; }

.avatar-crop-layer { position: fixed; z-index: 80; inset: 0; }
.avatar-crop-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(17, 27, 23, .55); backdrop-filter: blur(4px); }
.avatar-crop-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(430px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 26px 70px rgba(13, 24, 19, .3);
  transform: translate(-50%, -50%);
  animation: crop-dialog-in .2s cubic-bezier(.2, .8, .2, 1);
}
@keyframes crop-dialog-in { from { opacity: 0; transform: translate(-50%, -47%) scale(.97); } }
.avatar-crop-dialog > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.avatar-crop-dialog h2 { margin-bottom: 2px; font-size: 18px; }
.avatar-crop-dialog header span { color: var(--ink-faint); font-size: 11px; }
.avatar-crop-close { display: grid; width: 32px; height: 32px; flex: 0 0 32px; place-items: center; border: 0; border-radius: 50%; background: var(--paper-deep); cursor: pointer; font-size: 20px; }
.avatar-crop-canvas-wrap { position: relative; width: min(100%, 350px); margin: 0 auto; overflow: hidden; border-radius: 50%; background: #17231e; box-shadow: 0 0 0 5px var(--paper-deep); touch-action: none; }
.avatar-crop-canvas-wrap::after { position: absolute; inset: 0; border: 1px solid rgba(255,255,255,.45); border-radius: 50%; content: ""; pointer-events: none; }
.avatar-crop-canvas-wrap canvas { display: block; width: 100%; height: auto; cursor: grab; touch-action: none; }
.avatar-crop-canvas-wrap canvas:active { cursor: grabbing; }
.avatar-zoom-field { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 11px; margin-top: 18px; color: var(--ink-faint); font-size: 11px; font-weight: 720; }
.avatar-zoom-field input { width: 100%; accent-color: var(--green); }
.avatar-crop-actions { display: grid; grid-template-columns: 1fr 1.45fr; gap: 9px; margin-top: 16px; }

@media (max-width: 900px), (max-width: 1366px) and (hover: none) and (pointer: coarse), (max-width: 1366px) and (any-hover: none) and (any-pointer: coarse) {
  :root { --sidebar: 0px; }
  .sidebar { display: none; }
  .main-content { margin-inline-start: 0; padding: calc(66px + env(safe-area-inset-top)) 12px calc(80px + env(safe-area-inset-bottom)); }
  .mobile-header { display: flex; }
  .bottom-nav { display: grid; }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-main { min-height: 100dvh; padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom)); }
  .profile-layout { grid-template-columns: 1fr; gap: 10px; }
  .profile-identity-card, .profile-security-card { padding: 15px; }
  .profile-page-heading { margin-bottom: 12px; }
}

@media (max-width: 480px) {
  .mobile-header { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
  .mobile-header .brand-compact { gap: 7px; }
  .mobile-brand-copy strong { font-size: 13px; }
  .mobile-profile-name { max-width: 34vw; }
  .profile-avatar-editor { align-items: flex-start; gap: 13px; }
  .user-avatar-profile { width: 72px; height: 72px; flex-basis: 72px; font-size: 23px; }
  .profile-avatar-actions small { max-width: 190px; }
  .avatar-crop-dialog { padding: 15px; border-radius: 18px; }
}

@media (max-width: 350px) {
  .mobile-brand-copy strong { display: none; }
  .mobile-brand-copy small { font-size: 10px; }
  .mobile-profile-name { max-width: 31vw; }
}

@media (prefers-reduced-motion: reduce) {
  .profile-popover,
  .avatar-crop-dialog,
  .bottom-add.is-launching .bottom-add-icon,
  .bottom-add.is-arriving .bottom-add-icon,
  .bottom-add.is-launching .bottom-add-icon::after,
  .bottom-add.is-arriving .bottom-add-icon::after { animation: none; }
  .bottom-add-glyph-stroke { transition: none; }
}
