.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 76px;
  padding: max(14px, env(safe-area-inset-top)) clamp(18px, 5vw, 72px) 14px;
  border-bottom: 1px solid var(--outline-soft);
  background: rgba(248, 250, 253, 0.92);
  box-shadow: 0 12px 38px -34px rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(20px);
}

:root[data-theme="dark"] .app-header {
  background: rgba(17, 24, 39, 0.92);
}

.app-tabs {
  display: flex;
  flex: 1;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-tabs::-webkit-scrollbar {
  display: none;
}

.app-tabs button,
.app-bottom-nav button,
.quiet-button {
  border: 0;
  color: var(--text-muted);
  background: transparent;
  font: inherit;
}

.app-tabs button {
  min-height: 42px;
  flex: 0 0 auto;
  padding: 9px 13px;
  border-radius: 12px;
  font-weight: 750;
}

.app-tabs button.is-active {
  color: var(--primary);
  background: var(--surface-strong);
  box-shadow: var(--shadow-card);
}

.app-header-actions,
.app-hero-actions,
.button-row,
.wallet-toolbar,
.safety-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-theme-toggle {
  width: auto;
  min-height: 40px;
  padding: 0 11px;
}

.app-theme-toggle strong {
  display: none;
}

.app-main {
  width: min(1220px, calc(100% - 36px));
  margin: 0 auto;
  padding: 48px 0 88px;
}

.app-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 46vh;
  color: var(--text);
}

.app-loading p {
  margin: 5px 0 0;
  color: var(--text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 3px solid var(--outline);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: app-spin 800ms linear infinite;
}

@keyframes app-spin {
  to { transform: rotate(360deg); }
}

.app-view[hidden],
[hidden] {
  display: none !important;
}

.app-hero,
.section-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 28px;
}

.app-hero {
  padding: clamp(24px, 4vw, 50px);
  border: 1px solid var(--outline);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 94% 10%, rgba(0, 87, 184, 0.18), transparent 35%),
    var(--surface-panel);
  box-shadow: var(--shadow-panel);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-hero h1,
.section-intro h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  letter-spacing: -0.055em;
}

.app-hero p:not(.eyebrow),
.section-intro p:not(.eyebrow) {
  max-width: 680px;
  color: var(--text-muted);
  line-height: 1.65;
}

.workspace-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 26px 0 16px;
}

.workspace-toolbar > div {
  display: grid;
  flex: 1;
  gap: 4px;
}

.workspace-toolbar span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.widget-grid,
.wallet-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.widget-card {
  position: relative;
  grid-column: span 4;
  min-height: 210px;
  padding: 22px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-lg);
  color: var(--text);
  background: var(--surface-panel);
  box-shadow: var(--shadow-card);
  cursor: grab;
  touch-action: manipulation;
}

.widget-card[data-size="wide"] {
  grid-column: span 8;
}

.widget-card.is-dragging {
  opacity: 0.58;
  cursor: grabbing;
}

.widget-card h2 {
  margin: 20px 0 7px;
  font-size: 1.15rem;
}

.widget-card p {
  margin: 0 0 52px;
  color: var(--text-muted);
  line-height: 1.5;
}

.widget-icon {
  font-size: 1.55rem;
}

.widget-primary-action {
  position: absolute;
  right: 18px;
  bottom: 16px;
  color: var(--primary);
  font-weight: 800;
}

.widget-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 5px;
}

.widget-controls button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--text-muted);
  background: var(--surface-soft);
}

.widget-controls button:disabled {
  opacity: 0.35;
}

.wallet-toolbar {
  flex-wrap: wrap;
  margin: 26px 0 10px;
}

.wallet-toolbar label {
  color: var(--text-muted);
  font-weight: 750;
}

.wallet-toolbar select,
.feedback-form select,
.feedback-form input,
.feedback-form textarea,
.search-form input,
.safety-actions select,
.group-create-form input,
.group-item input,
.wallet-group-select {
  border: 1px solid var(--outline);
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface-strong);
  font: inherit;
}

.wallet-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  margin-top: 18px;
}

.wallet-card {
  display: flex;
  min-height: 280px;
  flex-direction: column;
  grid-column: auto;
  padding: 21px;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, #10243e, #275f92);
  box-shadow: var(--shadow-panel);
}

.wallet-card.is-pinned {
  outline: 3px solid rgba(75, 168, 255, 0.45);
}

.wallet-card:nth-child(3n + 2) {
  background: linear-gradient(135deg, #50334d, #a55d7d);
}

.wallet-card:nth-child(3n) {
  background: linear-gradient(135deg, #22534b, #488e75);
}

.wallet-card header,
.wallet-card footer,
.wallet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wallet-card header {
  justify-content: space-between;
}

.wallet-card h2 {
  margin: 36px 0 8px;
  font-size: 1.45rem;
}

.wallet-card > p {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
}

.wallet-card footer {
  align-items: stretch;
  flex-direction: column;
  margin-top: auto;
  padding-top: 28px;
}

.wallet-card button,
.wallet-card a,
.wallet-group-select {
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

.wallet-card button,
.wallet-card a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  font-weight: 750;
}

.wallet-group-select {
  width: 100%;
  padding: 7px 10px;
}

.wallet-group-select option {
  color: #111827;
}

.wallet-actions {
  flex-wrap: wrap;
}

.wallet-actions > * {
  flex: 1 1 auto;
}

.wallet-card .danger-card-action {
  color: #fff;
  background: rgba(120, 0, 0, 0.36);
}

.wallet-card[aria-busy="true"] {
  opacity: 0.68;
  pointer-events: none;
}

.search-form {
  display: flex;
  max-width: 760px;
  gap: 10px;
}

.search-form input {
  min-width: 0;
  flex: 1;
}

.recent-searches {
  max-width: 760px;
  margin-top: 18px;
}

.recent-searches > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.recent-searches button {
  border: 0;
  color: var(--primary);
  background: transparent;
  font: inherit;
  font-weight: 750;
}

.recent-search-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
}

.recent-search-list button {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-panel);
}

.safety-card {
  max-width: 820px;
  margin-top: 22px;
  padding: 22px;
  border: 1px solid rgba(190, 71, 91, 0.3);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 235, 239, 0.9), var(--surface-panel));
  box-shadow: var(--shadow-card);
}

:root[data-theme="dark"] .safety-card {
  background: linear-gradient(135deg, rgba(86, 34, 48, 0.72), var(--surface-panel));
}

.safety-card-copy {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.safety-card h2 {
  margin: 0;
  font-size: 1.18rem;
}

.safety-card p {
  margin: 7px 0 0;
  color: var(--text-muted);
  line-height: 1.55;
}

.safety-heart {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #bd3853;
  background: rgba(189, 56, 83, 0.12);
}

.safety-actions {
  flex-wrap: wrap;
  margin-top: 18px;
}

.safety-actions label {
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.quiet-button {
  min-height: 40px;
  padding: 8px 12px;
  font-weight: 750;
}

.search-notice {
  min-height: 24px;
  margin-top: 18px;
}

.search-results {
  display: grid;
  gap: 22px;
  margin-top: 14px;
}

.search-section-results {
  display: grid;
  gap: 12px;
}

.search-section-results > h2 {
  margin: 0;
  font-size: 1.08rem;
}

.search-result {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--outline);
  border-radius: 18px;
  background: var(--surface-panel);
}

.search-result > div {
  min-width: 0;
  flex: 1;
}

.search-result h3 {
  margin: 0 0 7px;
  font-size: 1.05rem;
}

.search-result p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--text-muted);
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.search-result a {
  margin-left: auto;
  color: var(--primary);
  font-weight: 800;
  white-space: nowrap;
}

.search-result small {
  color: var(--text-soft);
}

.settings-card {
  grid-column: span 6;
  padding: 22px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-lg);
  background: var(--surface-panel);
}

.settings-card h2 {
  margin: 0;
  font-size: 1.14rem;
}

.settings-card > p {
  color: var(--text-muted);
  line-height: 1.55;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 6px;
  font-weight: 750;
}

.switch-row input {
  width: 44px;
  height: 26px;
  accent-color: var(--primary);
}

.activity-log {
  max-height: 220px;
  margin: 10px 0 0;
  padding-left: 22px;
  overflow: auto;
  color: var(--text-muted);
  line-height: 1.75;
}

.activity-log li + li {
  margin-top: 4px;
}

.activity-log small {
  display: block;
  color: var(--text-soft);
}

.feedback-form {
  display: grid;
  gap: 10px;
}

.feedback-form textarea {
  min-height: 116px;
  resize: vertical;
}

.feedback-form .primary-button {
  justify-self: start;
}

.app-empty,
.inline-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--outline);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
}

.app-empty {
  padding: 46px 24px;
}

.app-empty p {
  color: var(--text-muted);
}

.app-empty .primary-button {
  display: inline-flex;
  margin-top: 8px;
}

.inline-state {
  min-height: 0;
  margin: 12px 0 0;
  padding: 14px;
}

.inline-state:empty {
  display: none;
}

.inline-state.is-error {
  border-style: solid;
  border-color: rgba(186, 26, 26, 0.3);
  color: #ba1a1a;
  background: rgba(186, 26, 26, 0.06);
}

.form-note {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.group-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: min(82dvh, 720px);
  padding: 22px;
  overflow: auto;
  border: 1px solid var(--outline);
  border-radius: 26px;
  color: var(--text);
  background: var(--surface-panel);
  box-shadow: 0 30px 100px -42px rgba(15, 23, 42, 0.7);
}

.group-dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
  backdrop-filter: blur(8px);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-head h2 {
  margin: 0;
}

.group-create-form {
  margin-top: 22px;
}

.group-create-form > label {
  display: block;
  margin-bottom: 8px;
  font-weight: 750;
}

.group-create-form > div {
  display: flex;
  gap: 8px;
}

.group-create-form input {
  min-width: 0;
  flex: 1;
}

.group-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.group-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--outline);
  border-radius: 16px;
  background: var(--surface-soft);
}

.app-toast {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 120;
  max-width: min(420px, calc(100vw - 36px));
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--outline);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface-panel);
  box-shadow: var(--shadow-panel);
}

.app-toast.is-error {
  color: #ba1a1a;
  border-color: rgba(186, 26, 26, 0.3);
}

.app-bottom-nav {
  display: none;
}

.app-tabs button,
.app-bottom-nav button,
.widget-controls button,
.wallet-card button,
.wallet-card a,
.recent-search-list button,
.quiet-button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 2px;
}

@media (hover: hover) {
  .app-tabs button:hover,
  .widget-controls button:hover,
  .recent-search-list button:hover {
    color: var(--primary);
    background: var(--surface-strong);
  }

  .wallet-card button:hover,
  .wallet-card a:hover {
    background: rgba(255, 255, 255, 0.26);
  }
}

@media (max-width: 900px) {
  .widget-card,
  .widget-card[data-size="wide"] {
    grid-column: span 6;
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }

  .app-header {
    gap: 12px;
    min-height: 62px;
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  }

  .app-tabs,
  .app-manage-link {
    display: none;
  }

  .app-header-actions {
    margin-left: auto;
  }

  .app-main {
    width: min(100% - 24px, 1220px);
    padding-top: 24px;
  }

  .app-hero,
  .section-intro {
    flex-direction: column;
  }

  .app-hero-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .app-hero-actions > * {
    min-height: 44px;
    flex: 1;
    text-align: center;
  }

  .workspace-toolbar {
    align-items: flex-start;
  }

  .widget-card,
  .widget-card[data-size="wide"],
  .settings-card {
    grid-column: span 12;
  }

  .widget-card {
    min-height: 198px;
  }

  .wallet-grid {
    grid-template-columns: 1fr;
  }

  .wallet-card {
    min-height: 270px;
  }

  .search-form {
    flex-direction: column;
  }

  .search-form .primary-button {
    width: 100%;
  }

  .search-result {
    flex-wrap: wrap;
  }

  .search-result a {
    margin-left: 0;
  }

  .safety-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .safety-actions label {
    margin-bottom: -5px;
  }

  .group-create-form > div,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .group-item {
    grid-template-columns: 1fr 1fr;
  }

  .group-item input {
    grid-column: 1 / -1;
  }

  .app-bottom-nav {
    position: fixed;
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    padding: 7px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 22px 70px -38px rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(22px);
  }

  :root[data-theme="dark"] .app-bottom-nav {
    border-color: rgba(148, 163, 184, 0.2);
    background: rgba(17, 24, 39, 0.92);
  }

  .app-bottom-nav button {
    display: grid;
    min-height: 50px;
    place-items: center;
    gap: 2px;
    border-radius: 17px;
    font-size: 0.72rem;
    font-weight: 850;
  }

  .app-bottom-nav button span {
    font-size: 1.05rem;
  }

  .app-bottom-nav button.is-active {
    color: var(--primary);
    background: rgba(0, 87, 184, 0.1);
  }

  .app-toast {
    right: 16px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    left: 16px;
    max-width: none;
  }
}

@media (max-width: 430px) {
  .app-hero {
    padding: 22px;
  }

  .workspace-toolbar,
  .wallet-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace-toolbar .small-action,
  .wallet-toolbar .small-action,
  .wallet-toolbar select {
    width: 100%;
  }

  .safety-card-copy {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
