:root {
  --shell-bg: #f5f7fb;
  --shell-surface: #ffffff;
  --shell-border: #dde4f2;
  --shell-text: #0f172a;
  --shell-muted: #5f6f89;
  --shell-accent: #2563eb;
  --shell-accent-soft: #e7efff;
  --shell-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--shell-font);
  background: var(--shell-bg);
  color: var(--shell-text);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.app-shell-overlay {
  display: none;
}

.app-shell-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #0f1a2f;
  color: #e6edf9;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  padding: 20px 14px;
  overflow-y: auto;
}

.app-shell-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #f4f8ff;
  text-decoration: none;
  font-weight: 700;
  margin-bottom: 22px;
}

.app-shell-brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-shell-brand-icon svg {
  width: 18px;
  height: 18px;
}

.app-shell-nav {
  display: grid;
  gap: 6px;
}

.app-shell-link {
  display: block;
  color: #d7e1f4;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.94rem;
  transition: background-color var(--motion-fast, 140ms) var(--motion-ease, ease), color var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-link.sub {
  font-size: 0.88rem;
  font-weight: 500;
  padding-left: 24px;
}

.app-shell-link:hover,
.app-shell-link.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.app-shell-group {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 6px;
  transition: border-color var(--motion-fast, 140ms) var(--motion-ease, ease), background-color var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-group summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 8px 8px 10px;
  font-weight: 600;
  font-size: 0.94rem;
  color: #d7e1f4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: color var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-group summary::-webkit-details-marker { display: none; }

.app-shell-group-label {
  line-height: 1.2;
}

.app-shell-group-chevron {
  width: 16px;
  height: 16px;
  opacity: 0.9;
  transition: transform var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-group[open] .app-shell-group-chevron {
  transform: rotate(180deg);
}

.app-shell-subgroup {
  margin: 4px 4px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  overflow: visible;
  padding: 4px;
}

.app-shell-subgroup summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #d7e1f4;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 9px;
  transition: background-color var(--motion-fast, 140ms) var(--motion-ease, ease), color var(--motion-fast, 140ms) var(--motion-ease, ease), border-color var(--motion-fast, 140ms) var(--motion-ease, ease);
  border: 1px solid transparent;
}

.app-shell-subgroup summary::-webkit-details-marker { display: none; }

.app-shell-subgroup-label {
  line-height: 1.2;
}

.app-shell-subgroup-chevron {
  width: 14px;
  height: 14px;
  opacity: 0.9;
  transition: transform var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-subgroup[open] .app-shell-subgroup-chevron {
  transform: rotate(180deg);
}

.app-shell-subgroup summary:hover,
.app-shell-subgroup summary.active {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.app-shell-subgroup:focus-within summary {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.app-shell-subgroup[open] summary {
  border-color: rgba(160, 180, 214, 0.38);
}

.app-shell-subgroup-links {
  display: grid;
  gap: 4px;
  padding: 6px 0 2px;
}

.app-shell-link.sub.nested {
  padding-left: 34px;
  font-size: 0.84rem;
  border-radius: 9px;
}

.app-shell-link.sub.nested.active {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.app-shell-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-shell-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
}

.app-shell-menu-btn {
  display: none;
  border: 1px solid var(--shell-border);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.app-shell-menu-btn svg {
  width: 16px;
  height: 16px;
}

.app-shell-title {
  font-size: 1rem;
  font-weight: 700;
  margin-right: auto;
  min-width: 0;
}

.app-shell-topbar-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: fit-content;
}

.app-shell-credits {
  position: relative;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 999px;
  padding: 8px 13px;
  background: linear-gradient(135deg, #4f46e5, #2563eb);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  border: none;
  transition: transform var(--motion-fast, 140ms) var(--motion-ease, ease), box-shadow var(--motion-mid, 200ms) var(--motion-ease, ease);
}

.app-shell-credits:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.28);
}

.app-shell-credits-total {
  white-space: nowrap;
}

.app-shell-credits-tooltip {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 206px;
  background: #f8fbff;
  color: #27364f;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
  border: 1px solid #cfd9ea;
  display: none;
  z-index: 18;
}

.app-shell-credits:hover .app-shell-credits-tooltip,
.app-shell-credits:focus-visible .app-shell-credits-tooltip,
.app-shell-credits.is-open .app-shell-credits-tooltip {
  display: block;
}

.credit-tip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  padding: 3px 2px;
  color: #4f627f;
}

.credit-tip-row strong {
  color: #1c2a42;
  font-size: 0.79rem;
}

.credit-tip-row.total {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid #d7e2f0;
  font-weight: 700;
}

.app-shell-signin,
.app-shell-account-btn {
  border: 1px solid var(--shell-border);
  background: #fff;
  color: var(--shell-text);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.app-shell-account {
  position: relative;
}

.app-shell-account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-shell-account-btn .avatar {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--shell-accent-soft);
  color: var(--shell-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
}

.app-shell-account-btn svg {
  width: 14px;
  height: 14px;
}

.app-shell-account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  background: #fff;
  border: 1px solid var(--shell-border);
  border-radius: 12px;
  box-shadow: 0 22px 40px rgba(15, 23, 42, 0.14);
  display: none;
  padding: 8px;
  transform: translateY(8px);
  opacity: 0;
  transition: opacity var(--motion-fast, 140ms) var(--motion-ease, ease), transform var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-account-menu.visible {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.app-shell-email {
  font-size: 0.78rem;
  color: var(--shell-muted);
  padding: 8px;
  border-bottom: 1px solid var(--shell-border);
  margin-bottom: 4px;
}

.app-shell-account-item {
  width: 100%;
  text-align: left;
  display: block;
  text-decoration: none;
  color: var(--shell-text);
  border: none;
  background: transparent;
  font: inherit;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background-color var(--motion-fast, 140ms) var(--motion-ease, ease), color var(--motion-fast, 140ms) var(--motion-ease, ease);
}

.app-shell-account-item:hover {
  background: var(--shell-accent-soft);
}

.app-shell-account-item.danger {
  color: #b91c1c;
}

.app-shell-page {
  padding: 22px;
}

.shell-footer {
  margin-top: auto;
  border-top: 1px solid var(--shell-border);
  padding: 14px 22px 18px;
  text-align: center;
}

.shell-footer-text {
  margin: 0;
  font-size: 0.86rem;
  color: #5b667b;
}

.shell-footer-text a {
  color: #3f4b63;
  text-decoration: none;
  font-weight: 600;
}

.shell-footer-text a:hover {
  color: #1f2937;
}

.shell-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 16px;
}

.shell-modal-overlay[hidden] {
  display: none;
}

.shell-modal {
  width: min(640px, 100%);
  background: #fff;
  border: 1px solid var(--shell-border);
  border-radius: 16px;
  box-shadow: 0 20px 44px rgba(15, 23, 42, 0.22);
  padding: 20px;
  position: relative;
}

.shell-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--shell-border);
  background: #fff;
  color: var(--shell-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.shell-modal h2 {
  margin: 0 0 8px 0;
}

.shell-modal-subtitle {
  margin: 0 0 16px 0;
  color: var(--shell-muted);
  font-size: 0.95rem;
}

.shell-export-grid {
  display: grid;
  gap: 8px;
}

.shell-export-option {
  border: 1px solid var(--shell-border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}

.shell-export-option input {
  width: 16px;
  height: 16px;
}

.shell-modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.shell-modal-action {
  width: auto;
  border: 1px solid var(--shell-border);
}

.shell-modal-primary {
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #2563eb);
  color: #fff;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}

.app-shell-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 18px);
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
}

.app-shell-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.app-shell-toast.error {
  background: #7f1d1d;
}

.app-shell-toast.success {
  background: #0f7a4a;
}

.shell-panel {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(244, 249, 255, 0.86));
  border: 1px solid rgba(195, 207, 233, 0.82);
  border-radius: 16px;
  padding: 18px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
  }

  .app-shell.sidebar-open .app-shell-sidebar {
    transform: translateX(0);
  }

  .app-shell-menu-btn {
    display: inline-flex;
  }

  .app-shell-overlay {
    border: 0;
    background: rgba(15, 23, 42, 0.45);
    position: fixed;
    inset: 0;
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .app-shell.sidebar-open .app-shell-overlay {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .app-shell-topbar {
    display: flex;
    flex-wrap: wrap;
  }

  .app-shell-title {
    flex: 1 1 auto;
  }

  .app-shell-credits-tooltip {
    right: -6px;
  }
}
