/* Bitidea responsive layout, layered after the existing application styles.
   The original application bundle and API routes remain byte-for-byte intact. */

:root {
  --brand-blue: #1f449b;
  --app-font: "Noto Sans SC", "Source Han Sans CN", "PingFang SC",
    "Microsoft YaHei", Inter, system-ui, sans-serif;
}

.app-shell:not(.login-shell) {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

.workspace,
.view-stack,
.hero-grid > *,
.analytics-grid > *,
.recharge-layout > *,
.model-card-header > div,
.admin-main,
.admin-split > * {
  min-width: 0;
}

.workspace {
  width: 100%;
  padding: 20px 16px calc(108px + env(safe-area-inset-bottom));
}

.hero-title span,
.hero-subtitle span {
  white-space: normal;
  overflow-wrap: anywhere;
}

.model-tags span {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.model-meta {
  flex-wrap: wrap;
}

.endpoint-row code {
  min-width: 0;
  flex: 1;
}

.endpoint-row button {
  flex-shrink: 0;
}

/* Existing chart margins place the first tick slightly outside the SVG. */
.chart-panel .recharts-surface {
  overflow: visible;
}

.mobile-nav {
  width: 100%;
  max-width: none;
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}

.mobile-nav-item {
  min-width: 0;
  min-height: 56px;
}

.toast {
  left: 16px;
  right: 16px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  overflow-wrap: anywhere;
}

.login-shell {
  width: min(100%, 640px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

.login-page {
  min-height: 100vh;
  min-height: 100svh;
  padding: 24px 20px 40px;
}

.login-brand {
  padding: 32px 0;
}

.login-brand p {
  max-width: 32ch;
  line-height: 1.7;
}

.login-card {
  min-width: 0;
  padding: 24px;
}

.login-field input,
.custom-field input,
.admin-login-card input {
  min-width: 0;
  width: 100%;
  font-size: 16px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--brand-blue);
  outline-offset: 3px;
}

@media (max-width: 359px) {
  .workspace {
    padding-right: 12px;
    padding-left: 12px;
  }

  .hero-panel,
  .balance-panel,
  .payment-panel,
  .checkout-card,
  .chart-panel,
  .table-panel {
    padding: 16px;
  }

  .hero-panel h2 {
    font-size: 27px;
  }

  .login-page {
    padding-right: 16px;
    padding-left: 16px;
  }

  .login-card {
    padding: 20px;
  }

  .simple-user-card {
    gap: 12px;
    padding: 16px;
  }

  .simple-user-copy h2 {
    font-size: 21px;
  }
}

/* Tablet: use the available width while retaining touch navigation. */
@media (min-width: 768px) {
  .workspace {
    max-width: 1440px;
    margin: 0 auto;
    padding: 28px 28px calc(108px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: center;
    margin-bottom: 24px;
  }

  .view-stack {
    gap: 24px;
  }

  .hero-topline {
    flex-direction: row;
    align-items: center;
  }

  .hero-actions > button {
    flex: 0 1 auto;
  }

  .hero-panel h2 {
    font-size: 40px;
  }

  .section-heading {
    flex-direction: row;
    align-items: center;
  }

  .segmented-control {
    width: auto;
  }

  .segmented-control button {
    flex: 0 0 auto;
    padding: 0 16px;
  }

  .model-grid,
  .ability-grid,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid,
  .amount-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-card:nth-child(3) {
    grid-column: auto;
  }

  .invoice-row {
    grid-template-columns: 1.3fr 1.2fr 0.8fr 0.7fr 0.7fr;
    padding: 14px;
  }

  .account-layout {
    max-width: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .account-layout > .simple-user-card,
  .account-layout > .menu-card.single,
  .account-layout > .account-footer {
    grid-column: 1 / -1;
  }

  .foundation-row {
    grid-template-columns: 120px minmax(0, 1fr);
  }

  .contact-card {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .login-page {
    padding: 32px;
  }

  .login-brand {
    padding: 40px 0;
  }

  .login-card {
    padding: 32px;
  }
}

/* Desktop: persistent sidebar, full-width work area, and column layouts. */
@media (min-width: 1024px) {
  .app-shell:not(.login-shell) {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .app-shell > .sidebar {
    /* The previous mobile stylesheet hides this with !important. */
    display: flex !important;
    min-height: 100vh;
    height: 100svh;
    padding: 28px 18px;
    overflow-y: auto;
  }

  .mobile-nav {
    display: none;
  }

  .workspace {
    padding: 32px clamp(24px, 3vw, 48px) 48px;
  }

  .topbar {
    margin-bottom: 28px;
  }

  .topbar h1 {
    font-size: clamp(32px, 2.8vw, 42px);
  }

  .topbar .icon-button {
    display: inline-flex;
  }

  .hero-grid {
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.85fr);
    align-items: stretch;
    gap: 24px;
  }

  .hero-panel,
  .balance-panel {
    min-height: 330px;
    padding: 28px;
  }

  .hero-panel h2 {
    font-size: clamp(28px, 2.5vw, 42px);
  }

  .hero-topline {
    margin-bottom: 28px;
  }

  .hero-panel p {
    font-size: 15px;
  }

  .balance-panel strong,
  .balance-display strong,
  .checkout-card strong {
    font-size: 44px;
  }

  .model-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
  }

  .model-card {
    padding: 20px;
  }

  .recharge-layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.65fr);
    gap: 24px;
  }

  .analytics-grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr);
    gap: 24px;
  }

  .payment-panel,
  .checkout-card,
  .chart-panel,
  .table-panel,
  .settings-card,
  .copy-card,
  .foundation-card,
  .contact-card {
    padding: 24px;
  }

  .account-layout {
    column-gap: 24px;
  }

  .about-hero {
    padding: 40px 28px;
  }

  .toast {
    left: auto;
    right: 28px;
    bottom: 28px;
    max-width: min(420px, calc(100vw - 56px));
    text-align: left;
  }

  .login-shell {
    width: min(1100px, calc(100% - 64px));
    min-height: 0;
    margin: clamp(32px, 7vh, 80px) auto;
    border: 1px solid #1a161214;
    border-radius: 18px;
    box-shadow: 0 28px 90px #281f1820;
  }

  .login-page {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "heading form" "brand form";
    align-items: center;
    min-height: 680px;
    padding: 44px;
    gap: 28px 52px;
  }

  .login-topbar {
    grid-area: heading;
    align-self: start;
  }

  .login-brand {
    grid-area: brand;
    justify-items: start;
    text-align: left;
    padding: 0 0 48px;
    gap: 22px;
  }

  .login-logo {
    width: 88px;
    height: 88px;
  }

  .login-logo img {
    width: 64px;
  }

  .login-brand h2 {
    font-size: 48px;
  }

  .login-brand p {
    max-width: 26ch;
    font-size: 18px;
    line-height: 1.8;
  }

  .login-card {
    grid-area: form;
    align-self: center;
    width: 100%;
    max-width: 440px;
    justify-self: end;
    padding: 28px;
  }
}

@media (min-width: 1440px) {
  .app-shell:not(.login-shell) {
    grid-template-columns: 248px minmax(0, 1fr);
  }

  .model-grid,
  .ability-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Keep dense administrative forms inside their own responsive panels. */
.model-editor {
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
}

.admin-filter,
.admin-top-actions {
  flex-wrap: wrap;
}

@media (max-width: 1100px) {
  .admin-split {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .admin-login {
    padding: 20px 16px;
  }

  .admin-login-card {
    padding: 24px;
  }

  .admin-sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-brand {
    padding-bottom: 4px;
  }

  .admin-sidebar {
    padding: 16px;
    gap: 12px;
  }

  .admin-filter label,
  .admin-filter select,
  .admin-filter button {
    width: 100%;
  }

  .model-editor {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-drawer {
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .admin-toast {
    left: 16px;
    right: 16px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    overflow-wrap: anywhere;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-item,
  .mobile-nav-item,
  .primary-button,
  .secondary-button,
  .connect-button,
  .icon-button {
    transition: none;
  }
}
