html {
  min-width: 0;
  background: var(--bg-app);
}

body {
  min-width: 0;
  overflow-wrap: break-word;
}

button,
input,
select,
textarea {
  font: inherit;
}

:where(button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

.main-content {
  container-name: main-content;
  container-type: inline-size;
}

.sidebar-nav .tab-btn { min-height: var(--touch-min); }
.mobile-bottom-nav { display: none; }

.login-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: calc(var(--space-6) + var(--safe-top)) calc(var(--space-4) + var(--safe-right)) calc(var(--space-6) + var(--safe-bottom)) calc(var(--space-4) + var(--safe-left));
  background: var(--bg-app);
}

.login-card {
  width: min(100%, 380px);
  padding: clamp(24px, 6vw, 32px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: 0 20px 35px -20px rgba(15, 23, 42, 0.35);
}

.login-brand { margin-bottom: var(--space-6); text-align: center; }
.login-logo { width: 64px; height: 64px; margin-bottom: var(--space-3); padding: var(--space-2); border-radius: var(--radius-md); background: rgba(99, 102, 241, 0.08); }
.login-title { margin: 0; color: var(--text-primary); font-size: 20px; font-weight: 800; }
.login-subtitle { margin: var(--space-1) 0 0; color: var(--text-secondary); font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: var(--space-4); }
.login-label { display: block; margin-bottom: 6px; color: var(--text-secondary); font-size: 12px; font-weight: 700; }
.login-input {
  width: 100%;
  min-height: var(--touch-min);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 16px;
}
.login-error { color: var(--accent-red); font-size: 13px; font-weight: 700; text-align: center; }
.login-submit { width: 100%; min-height: var(--touch-min); justify-content: center; border-radius: 10px; font-size: 16px; font-weight: 800; }

@media (max-width: 1079px) {
  button,
  summary,
  [role="button"] {
    min-height: var(--touch-min) !important;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  select,
  textarea {
    min-height: var(--touch-min);
    font-size: 16px;
  }
  .app-container { flex-direction: column; }
  .sidebar {
    position: sticky;
    inset: 0 0 auto;
    width: 100%;
    height: auto;
    padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
    border-right: 0;
    border-bottom: 1px solid var(--border);
    gap: 6px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
  }
  .sidebar-brand { display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 0; }
  .sidebar-brand .eyebrow { display: none; }
  .sidebar-brand h1 { margin: 0; font-size: 16px; }
  .sidebar-total { display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 0; padding: 6px 12px; border-radius: 8px; }
  .sidebar-total .total { margin: 0; font-size: 15px; }
  .sidebar-total .sub { margin: 0 !important; font-size: 11px; }
  .sidebar-nav { flex: none; flex-direction: row; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .sidebar-nav .tab-btn { flex: 0 0 auto; width: auto; min-height: var(--touch-min); padding: 8px 12px; border: 0 !important; border-bottom: 2px solid transparent !important; border-radius: 8px 8px 0 0; white-space: nowrap; }
  .sidebar-nav .tab-btn.on { padding-left: 12px; border-bottom-color: var(--accent-blue) !important; background: var(--bg-active-tab); }
  .sidebar-footer { display: none; }
  .main-content { width: 100%; margin-left: 0; }
  .main-header { padding: 16px; gap: 12px; }
  main, #main { padding: 16px calc(16px + var(--safe-right)) calc(40px + var(--safe-bottom)) calc(16px + var(--safe-left)); }
  body { overflow-x: clip; }
}

@media (max-width: 639px) {
  body { background: #fbf8f5; }
  .app-container { background: #fbf8f5; }
  .sidebar { display: none; }
  .main-header { align-items: flex-start; flex-direction: column; padding: calc(18px + var(--safe-top)) 18px 12px; border-bottom: 0; background: #fbf8f5; }
  .header-title h2 { color: #211d1b; font-size: 24px; letter-spacing: -0.035em; }
  .header-subtitle { display: none; }
  .header-controls { width: 100%; justify-content: space-between; }
  .profiles-wrapper { width: 100%; justify-content: space-between; padding: 4px; background: #f2ebe7; }
  .profiles-wrapper > .muted { margin-left: 8px; }
  .profiles .pf.on { color: #8f1d2c; }
  main, #main { padding: 12px calc(16px + var(--safe-right)) calc(104px + var(--safe-bottom)) calc(16px + var(--safe-left)); }
  .mobile-bottom-nav {
    position: fixed;
    z-index: 1100;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: calc(70px + var(--safe-bottom));
    padding: 6px calc(6px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(6px + var(--safe-left));
    border-top: 1px solid #e9dfd9;
    background: rgba(255, 253, 250, 0.96);
    box-shadow: 0 -10px 28px rgba(50, 33, 27, 0.08);
    backdrop-filter: blur(16px);
  }
  .mobile-nav-item {
    display: flex;
    min-width: 0;
    min-height: 58px !important;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    padding: 4px 2px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: #9a918c;
    font-size: 10px;
    font-weight: 700;
    text-align: center;
  }
  .mobile-nav-item svg { width: 21px; height: 21px; }
  .mobile-nav-item.on,
  .mobile-more.on > summary { color: #9f1d2d; }
  .mobile-nav-item.on svg,
  .mobile-more.on > summary svg { opacity: 1; stroke: currentColor; }
  .mobile-more { position: relative; min-width: 0; }
  .mobile-more > summary { width: 100%; list-style: none; cursor: pointer; }
  .mobile-more > summary::-webkit-details-marker { display: none; }
  .mobile-more[open] > summary { color: #9f1d2d; background: #f8e9e9; }
  .mobile-more-panel {
    position: absolute;
    right: 4px;
    bottom: calc(68px + var(--safe-bottom));
    display: grid;
    width: min(280px, calc(100vw - 24px));
    gap: 4px;
    padding: 14px;
    border: 1px solid #e8ddd7;
    border-radius: 20px;
    background: #fffdfa;
    box-shadow: 0 20px 50px rgba(45, 29, 24, 0.2);
  }
  .mobile-more-panel > strong { padding: 4px 8px 8px; color: #6e625d; font-size: 11px; }
  .mobile-more-panel button { display: flex; min-height: 46px; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: 12px; background: transparent; color: #3d3633; font-size: 13px; font-weight: 700; text-align: left; }
  .mobile-more-panel button.on { background: #f8e9e9; color: #8f1d2c; }
  .mobile-more-panel button.is-danger { color: #a21d33; }
}

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