/* Native-app feel for pages shown inside the Kajship Android/iOS shells
   (layouts/native.html.erb and layouts/auth.html+native.erb put
   `native-app` on <html>). Everything is scoped to that class, since
   Propshaft links every stylesheet on every page. */

/* ── Base behaviour ────────────────────────────────────────────────── */

.native-app {
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* App chrome is not selectable text; long-press on a link or image
   shouldn't pop the browser's context menu. */
.native-app body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.native-app input,
.native-app textarea,
.native-app [contenteditable],
.native-app .selectable {
  -webkit-user-select: text;
  user-select: text;
}

/* No 300ms tap delay, no double-tap zoom. */
.native-app a,
.native-app button,
.native-app label,
.native-app summary,
.native-app [role="button"] {
  touch-action: manipulation;
}
.native-app :focus-visible {
  outline: 2px solid var(--color-brand-500, #4468f0);
  outline-offset: 3px;
}

/* Form fields at 16px so focusing one never zooms the page (iOS). */
.native-app input,
.native-app select,
.native-app textarea {
  font-size: 16px;
}

/* Compact list controls stay attached to the content viewport while its
   results scroll. The shell header and bottom tabs remain outside this area. */
.native-app .native-sticky-controls {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--color-canvas);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.native-app.dark .native-sticky-controls {
  background: rgb(3 7 18 / 0.96);
}

.native-app .native-auth-sheet[open] {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: min(85dvh, 42rem);
  overflow-y: auto;
  border-radius: 1.5rem 1.5rem 0 0;
  animation: native-sheet-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.native-app .native-auth-sheet::backdrop {
  background: rgb(3 7 18 / 0.5);
  backdrop-filter: blur(3px);
}
.native-app.native-auth-screen .native-toast {
  top: calc(env(safe-area-inset-top, 0px) + 1rem) !important;
}
@keyframes native-sheet-in {
  from { opacity: 0.8; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}

/* Scrollbars are a desktop affordance. */
.native-app ::-webkit-scrollbar {
  display: none;
}
.native-app * {
  scrollbar-width: none;
}

/* ── Tappable feedback ─────────────────────────────────────────────── */

.native-app .tappable {
  transition: background-color 100ms ease, transform 100ms ease, opacity 100ms ease;
  -webkit-tap-highlight-color: transparent;
}
.native-app .tappable:active {
  background-color: rgb(0 0 0 / 0.05);
  transform: scale(0.98);
  opacity: 0.85;
}
.native-app.dark .tappable:active {
  background-color: rgb(255 255 255 / 0.08);
}

/* ── Snackbar / Toast ──────────────────────────────────────────────── */

@keyframes native-toast-in {
  from { opacity: 0; transform: translateY(-100%); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes native-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-100%); visibility: hidden; }
}
.native-app .native-toast {
  animation: native-toast-in 300ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards,
             native-toast-out 300ms cubic-bezier(0.2, 0.8, 0.2, 1) 3.5s forwards;
  cursor: pointer;
  top: calc(env(safe-area-inset-top, 0px) + 60px) !important;
}
.native-app .native-toast:active {
  animation: native-toast-out 200ms ease forwards;
}

/* ── Screen transitions ────────────────────────────────────────────── */

/* The main element is the native app's one scroll container. Avoid a
   page-wide animation here: Turbo can render both a cached preview and its
   fresh response during one visit, which looks like two page reloads. */
.native-app main {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ── Turbo progress bar ────────────────────────────────────────────── */

.native-app .turbo-progress-bar {
  height: 2px;
  background: linear-gradient(90deg, var(--color-brand-400, #6d8cf8), var(--color-brand-500, #4468f0));
  position: fixed;
  top: 0;
  z-index: 9999;
}

/* ── Reduced motion ────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .native-app .native-toast,
  .native-app .native-auth-sheet[open],
  .native-app .tappable {
    animation: none !important;
    transition: none !important;
  }
}

/* Native entry screens use inset field groups rather than desktop columns. */
.native-app .form-outline { margin: 8px 0 24px; }
.native-app .form-outline__label { display: block; margin: 0 4px 10px; color: var(--color-gray-500); font-size: 12px; font-weight: 600; }
.native-app .form-outline__label > svg { display: none; }
.native-app .form-outline ol { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.native-app .form-outline li { flex: 0 0 auto; }
.native-app .form-outline a { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; border-radius: 999px; background: var(--color-surface); color: var(--color-gray-700); font-size: 13px; font-weight: 600; }
.native-app .form-outline__number { color: var(--color-brand-600); }
.native-app .form-section { display: block; padding: 0; margin: 0 0 28px; border: 0; scroll-margin-top: 16px; }
.native-app .form-section > div:first-child:not(.card) { padding: 0 8px 12px; }
.native-app .form-section-title { font-size: 17px; letter-spacing: -.02em; }
.native-app .form-section-desc { margin-top: 4px; font-size: 13px; line-height: 1.5; }
.native-app .form-section > .card { border: 0; border-radius: 18px; box-shadow: none; overflow: hidden; padding: 0; background: var(--color-surface); }
.native-app .form-section .form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.native-app .form-section .form-grid > div { min-width: 0; grid-column: 1; padding: 16px; }
.native-app .form-section .form-grid > div + div { border-top: 1px solid var(--color-gray-200); }
.native-app .form-section .form-label { margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--color-gray-500); }
.native-app .form-section .form-input { min-height: 48px; border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; background: var(--color-canvas); font-size: 16px; box-shadow: none; }
.native-app .form-section textarea.form-input { min-height: 112px; resize: vertical; }
.native-app .form-section .form-input:focus { border-color: var(--color-brand-500); outline: 2px solid color-mix(in srgb, var(--color-brand-500) 15%, transparent); outline-offset: 0; }
.native-app .form-section .form-input[aria-invalid="true"] { border-color: var(--color-error-600); }
.native-app .form-section .form-input:disabled { opacity: .65; }
.native-app .form-hint { font-size: 12px; line-height: 1.5; margin-top: 6px; }
.native-app .form-actions { position: sticky; bottom: 0; margin: 16px 0 0; padding: 12px 4px; border: 0; gap: 10px; background: var(--color-canvas); box-shadow: 0 -8px 18px color-mix(in srgb, var(--color-canvas) 90%, transparent); }
.native-app .form-actions > p { display: none; }
.native-app .form-actions > .btn { min-height: 50px; border-radius: 14px; font-size: 15px; }
.native-app .form-actions > .btn-primary { flex: 1; }
.native-app .form-actions > .btn-secondary { border: 0; background: transparent; }

/* Edit dialogs are app screens with their own scrolling content and save bar. */
.native-app dialog.app-dialog[open] { display: flex; flex-direction: column; position: fixed; inset: 0; margin: 0; width: 100%; max-width: none; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; overflow: hidden; background: var(--color-canvas); }
.native-app dialog.app-dialog > form { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.native-app dialog.app-dialog[open]:not(:has(.app-dialog__body)) { overflow-y: auto; }
.native-app dialog.app-dialog:not(:has(.app-dialog__body)) > form { flex: 0 0 auto; }
.native-app .app-dialog__header { flex-shrink: 0; padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px 16px; background: var(--color-surface); }
.native-app .app-dialog__close { min-width: 44px; min-height: 44px; }
.native-app .app-dialog__body { padding: 20px 16px; }
.native-app .app-dialog__body.grid,
.native-app .app-dialog__body > .grid { grid-template-columns: minmax(0, 1fr); }
.native-app .app-dialog__body .form-input { min-height: 48px; border-radius: 12px; font-size: 16px; }
.native-app .app-dialog__footer { flex-shrink: 0; padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px); background: var(--color-surface); }
.native-app .app-dialog__footer .btn { min-height: 50px; border-radius: 14px; }
.native-app .app-dialog__footer .btn-primary { flex: 1; }

/* ── Native home dashboard ─────────────────────────────────────────── */

.native-app .native-home__greeting {
  min-height: 3.25rem;
}
.native-app .native-home__avatar {
  box-shadow: 0 0 0 3px var(--color-white), 0 4px 12px rgb(15 23 42 / 0.12);
}
.native-app.dark .native-home__avatar {
  box-shadow: 0 0 0 3px #111827, 0 4px 12px rgb(0 0 0 / 0.3);
}
.native-app .native-home__greeting-mark,
.native-app .native-home__balance-mark {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
}
.native-app .native-home__greeting-mark {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--color-brand-600);
  background: var(--color-brand-50);
}
.native-app.dark .native-home__greeting-mark {
  color: var(--color-brand-300);
  background: rgb(68 104 240 / 0.16);
}
.native-app .native-home__balance {
  isolation: isolate;
  box-shadow: 0 14px 28px rgb(18 30 65 / 0.16);
}
.native-app .native-home__balance-orbit {
  position: absolute;
  top: -5.5rem;
  right: -4.5rem;
  width: 14rem;
  height: 14rem;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: 50%;
  background: radial-gradient(circle, rgb(109 140 248 / 0.18) 0 35%, transparent 36% 52%, rgb(255 255 255 / 0.05) 53% 54%, transparent 55%);
  pointer-events: none;
}
.native-app .native-home__balance-orbit::after {
  position: absolute;
  inset: 1.35rem;
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: inherit;
  content: "";
}
.native-app .native-home__balance-mark {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid rgb(255 255 255 / 0.16);
  color: rgb(255 255 255 / 0.9);
  background: rgb(255 255 255 / 0.08);
}
.native-app .native-home__balance-amount {
  max-width: 100%;
  font-size: clamp(1.45rem, 7.2vw, 1.85rem);
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}
.native-app .native-home__balance-stat + .native-home__balance-stat {
  padding-inline-start: 0.6rem;
  border-inline-start: 1px solid rgb(255 255 255 / 0.13);
}
.native-app .native-home__action {
  -webkit-tap-highlight-color: transparent;
}
.native-app .native-home__action-icon {
  box-shadow: 0 5px 14px rgb(15 23 42 / 0.07), inset 0 0 0 1px rgb(15 23 42 / 0.035);
  transition: transform 140ms ease, box-shadow 140ms ease;
}
.native-app .native-home__action-icon svg {
  filter: drop-shadow(0 2px 4px color-mix(in srgb, var(--action-tint) 18%, transparent));
}
.native-app .native-home__action:active .native-home__action-icon {
  transform: translateY(1px) scale(0.94);
  box-shadow: 0 2px 6px rgb(15 23 42 / 0.06);
}
.native-app.dark .native-home__action-icon {
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.07);
}
.native-app .native-home__section-heading {
  min-height: 2.75rem;
}
.native-app .native-home__total-count {
  flex: 0 0 auto;
  padding: 0.35rem 0.6rem;
  border: 1px solid rgb(68 104 240 / 0.12);
  border-radius: 9999px;
  color: var(--color-brand-700);
  background: var(--color-brand-50);
  font-size: 0.7rem;
  font-weight: 700;
}
.native-app.dark .native-home__total-count {
  border-color: rgb(109 140 248 / 0.18);
  color: var(--color-brand-300);
  background: rgb(68 104 240 / 0.12);
}
.native-app .native-home__status-rail {
  scroll-snap-type: x proximity;
  overscroll-behavior-inline: contain;
}
.native-app .native-home__status {
  min-height: 8rem;
  border: 1px solid rgb(148 163 184 / 0.14);
  box-shadow: 0 3px 10px rgb(15 23 42 / 0.035);
  scroll-snap-align: start;
}
.native-app.dark .native-home__status {
  border-color: rgb(255 255 255 / 0.07);
  box-shadow: none;
}
@media (prefers-reduced-motion: reduce) {
  .native-app .native-home__action-icon {
    transition: none;
  }
}
