/* Aisma Theme Layer
   Safe update surface for global theme tokens and Bricks layout chrome.
   Keep business module layouts in aisma.css. */

:root {
  --aisma-theme-topbar-height: 72px;
  --aisma-theme-bottom-height: 76px;
  --aisma-theme-page-max: 1180px;
  --aisma-theme-pad-x: clamp(16px, 4vw, 40px);
  --aisma-theme-header-bg: var(--aisma-glass);
  --aisma-theme-footer-bg: var(--aisma-glass);
  --aisma-theme-control-bg: var(--aisma-control);
  --aisma-pwa-theme-color: var(--aisma-page-bg);
  --ar-topbar-bg: var(--aisma-theme-header-bg);
  --ar-topbar-border: var(--aisma-line);
  --ar-topbar-shadow: var(--aisma-shadow);
  --ar-text: var(--aisma-text);
  --ar-muted: var(--aisma-muted);
  --ar-logo: var(--aisma-text);
  --logo-accent: var(--aisma-accent);
}

html[data-aisma-theme="light"] {
  color-scheme: light;
  --aisma-pwa-theme-color: var(--aisma-page-bg-light, #f5f5f7);
}

html[data-aisma-theme="dark"] {
  color-scheme: dark;
  --aisma-pwa-theme-color: var(--aisma-page-bg-dark, #050507);
}

html[data-aisma-theme] {
  background: var(--aisma-page-bg);
}

html[data-aisma-theme] body {
  background: var(--aisma-page-bg);
  color: var(--aisma-text);
}

html.aisma-pwa-standalone,
html.aisma-pwa-standalone body {
  min-height: 100%;
  background: var(--aisma-page-bg);
}

body.aisma-pwa-standalone {
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

.aisma-theme-page,
.aisma-bricks-theme-page {
  min-height: 100svh;
  background: var(--aisma-page-bg);
  color: var(--aisma-text);
}

.aisma-theme-page :where(a),
.aisma-bricks-theme-page :where(a) {
  color: inherit;
  text-decoration: none;
}

.aisma-theme-shell,
.aisma-bricks-theme-shell {
  width: min(100% - (var(--aisma-theme-pad-x) * 2), var(--aisma-theme-page-max));
  margin-inline: auto;
}

.aisma-theme-surface,
.aisma-bricks-theme-surface {
  border: 1px solid var(--aisma-line);
  border-radius: max(18px, var(--aisma-radius));
  background: var(--aisma-glass);
  color: var(--aisma-text);
  box-shadow: var(--aisma-shadow), inset 0 1px 0 var(--aisma-inner-light);
  -webkit-backdrop-filter: saturate(180%) blur(var(--aisma-blur));
  backdrop-filter: saturate(180%) blur(var(--aisma-blur));
}

.aisma-theme-topbar,
.aisma-bricks-theme-topbar,
.ar-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: var(--aisma-theme-topbar-height);
  border: 1px solid var(--aisma-line);
  border-radius: max(18px, var(--aisma-radius));
  background: var(--aisma-theme-header-bg);
  color: var(--aisma-text);
  padding: 10px 18px;
  box-shadow: var(--aisma-shadow), inset 0 1px 0 var(--aisma-inner-light);
  -webkit-backdrop-filter: saturate(180%) blur(var(--aisma-blur));
  backdrop-filter: saturate(180%) blur(var(--aisma-blur));
}

.aisma-theme-bottom-nav,
.aisma-bricks-theme-bottom-nav {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: var(--aisma-theme-bottom-height);
  border: 1px solid var(--aisma-line);
  background: var(--aisma-theme-footer-bg);
  color: var(--aisma-text);
  padding: 8px;
  box-shadow: var(--aisma-shadow), inset 0 1px 0 var(--aisma-inner-light);
  -webkit-backdrop-filter: saturate(180%) blur(var(--aisma-blur));
  backdrop-filter: saturate(180%) blur(var(--aisma-blur));
}

.aisma-theme-text {
  color: var(--aisma-text);
}

.aisma-theme-muted {
  color: var(--aisma-muted);
}

.aisma-theme-accent {
  color: var(--aisma-accent);
}

.aisma-theme-button,
.aisma-theme-icon-button,
.aisma-bricks-theme-button,
.aisma-bricks-theme-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--aisma-line);
  border-radius: 999px;
  background: var(--aisma-theme-control-bg);
  color: var(--aisma-text);
  box-shadow: inset 0 1px 0 var(--aisma-inner-light);
  text-decoration: none;
}

.aisma-theme-button,
.aisma-bricks-theme-button {
  gap: 8px;
  padding: 0 15px;
  font-weight: 760;
}

.aisma-theme-icon-button,
.aisma-bricks-theme-icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
}

.aisma-theme-button:hover,
.aisma-theme-icon-button:hover,
.aisma-bricks-theme-button:hover,
.aisma-bricks-theme-icon-button:hover {
  border-color: color-mix(in srgb, var(--aisma-accent) 32%, var(--aisma-line));
  background: color-mix(in srgb, var(--aisma-accent) 10%, var(--aisma-control));
  color: var(--aisma-accent);
}

.aisma-theme-button:focus-visible,
.aisma-theme-icon-button:focus-visible,
.aisma-bricks-theme-button:focus-visible,
.aisma-bricks-theme-icon-button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--aisma-accent) 52%, transparent);
  outline-offset: 3px;
}

.aisma-desktop-only {
  display: revert;
}

.aisma-mobile-only {
  display: none !important;
}

@media (max-width: 720px) {
  .aisma-desktop-only {
    display: none !important;
  }

  .aisma-mobile-only {
    display: revert !important;
  }

  .aisma-theme-shell,
  .aisma-bricks-theme-shell {
    width: min(100% - 20px, 560px);
  }

  .aisma-theme-topbar,
  .aisma-bricks-theme-topbar,
  .ar-topbar {
    min-height: calc(58px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    border-radius: 0 0 24px 24px;
  }

  .aisma-theme-bottom-nav,
  .aisma-bricks-theme-bottom-nav {
    position: fixed;
    right: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 14px;
    z-index: 1000;
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
    border-radius: 28px;
  }

  body:has(.aisma-theme-bottom-nav),
  body:has(.aisma-bricks-theme-bottom-nav) {
    padding-bottom: calc(var(--aisma-theme-bottom-height) + env(safe-area-inset-bottom) + 24px);
  }

  body.aisma-has-mobile-bottom-nav {
    padding-bottom: calc(var(--aisma-theme-bottom-height) + env(safe-area-inset-bottom) + 24px);
  }

  html.aisma-pwa-standalone .aisma-theme-page,
  html.aisma-pwa-standalone .aisma-bricks-theme-page {
    min-height: 100svh;
  }

  html.aisma-pwa-standalone .aisma-theme-topbar,
  html.aisma-pwa-standalone .aisma-bricks-theme-topbar,
  html.aisma-pwa-standalone .ar-topbar {
    position: sticky;
    top: 0;
    z-index: 1002;
    border-top-width: 0;
    border-radius: 0 0 26px 26px;
  }

  html.aisma-pwa-standalone .aisma-theme-bottom-nav,
  html.aisma-pwa-standalone .aisma-bricks-theme-bottom-nav {
    bottom: max(10px, env(safe-area-inset-bottom));
  }
}
