:root {
  --shell-max-w: 1320px;
  --font-base: 15px;
  --font-family-base: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  --topbar-h: 62px;
  --subnav-h: 60px;
  --pagebar-h: 62px;

  --bg-page: #1a1f27;
  --bg-topbar: #15171c;
  --bg-subnav: #101318;
  --bg-content: #131924;

  --border: #2d3440;
  --border-strong: rgba(230, 185, 61, 0.56);

  --accent: #e6b93d;
  --accent-2: #f0c84b;
  --accent-dim: rgba(230, 185, 61, 0.16);
  --accent-glow: rgba(230, 185, 61, 0.08);

  --text: #f3f4f6;
  --text-muted: #b6c2d1;
  --text-faint: #8a96a8;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition: 0.18s ease;

  --shell-bg: var(--bg-page);
  --shell-text: var(--text);
  --shell-surface: #15171c;
  --shell-border: var(--border);

  --blue: var(--accent);
  --blue-dim: var(--accent-dim);
  --blue-glow: var(--accent-glow);
}

* {
  box-sizing: border-box;
}

html,
body.app-body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

body.app-body {
  background: var(--bg-page);
  color: var(--text);
  font-family: var(--font-family-base);
  font-size: var(--font-base);
  line-height: 1.5;
  overflow-x: hidden;
  overflow-y: auto;
}

body.app-body button,
body.app-body input,
body.app-body select,
body.app-body textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* Force new top-shell layout over legacy rules in styles.css */
body.app-body .app-shell {
  width: min(var(--shell-max-w), calc(100vw - 20px)) !important;
  height: auto !important;
  min-height: calc(100vh - 24px) !important;
  display: flex !important;
  flex-direction: column !important;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
  padding-left: 0 !important;
  margin: 12px auto !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  overflow: visible !important;
  background: var(--bg-content) !important;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

body.app-body .app-main {
  margin-left: 0 !important;
  grid-column: auto !important;
  grid-row: auto !important;
  width: 100% !important;
}

body.app-body .shell-header,
body.app-body .app-topbar,
body.app-body .app-content {
  display: block;
}

body.app-body .app-shell,
body.app-body .shell-header,
body.app-body .app-main,
body.app-body .app-content {
  visibility: visible !important;
  opacity: 1 !important;
}

.app-shell {
  width: min(var(--shell-max-w), calc(100vw - 20px));
  height: auto;
  display: flex;
  flex-direction: column;
  margin: 12px auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: visible;
  background: var(--bg-content);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}

.shell-header {
  border: 0;
  border-radius: 0;
  margin: 0;
  overflow: hidden;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 90;
}

.shell-announcement {
  padding: 10px 14px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--border-strong);
  color: #fff;
}

.shell-announcement strong {
  font-weight: 900;
}

.shell-announcement-warning {
  background: #f59e0b;
  color: #fff7e6;
}

.shell-announcement-danger {
  background: #b91c1c;
}

.shell-announcement-success {
  background: #166534;
}

.shell-announcement-info {
  background: #1d4ed8;
}

.shell-topbar {
  min-height: var(--topbar-h);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-strong);
}

.shell-brand-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.shell-brand-wrap-warning {
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  background: rgba(230, 185, 61, 0.08);
}

.topbar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
}

.shell-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.shell-brand-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e6b93d, #bb8d17);
  color: #101318;
  font-size: 13px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.shell-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.shell-brand-name {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-brand-sub {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.shell-context {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.shell-context-tabs {
  min-width: 0;
  flex: 0 1 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
}

.shell-context-tabs::-webkit-scrollbar {
  display: none;
}

.shell-context-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap !important;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
}

.shell-context-actions::-webkit-scrollbar {
  display: none;
}

.shell-context-actions > * {
  flex-shrink: 0;
}

.topbar-btn {
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: all var(--transition);
}

.topbar-btn:hover,
.topbar-btn:focus-visible {
  background: var(--accent-dim);
  border-color: var(--border-strong);
  color: var(--accent);
  outline: none;
}

.shell-link {
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
}

.shell-link:hover {
  color: var(--text);
}

.shell-inline-form {
  display: inline;
  margin: 0;
}

.shell-link-button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.shell-main-nav {
  min-height: var(--subnav-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--bg-subnav);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.shell-main-nav::-webkit-scrollbar {
  display: none;
}

.nav-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  color: var(--text);
  border: 1px solid transparent;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  transition: all var(--transition);
}

.nav-item:hover,
.nav-item:focus-visible,
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-strong);
  outline: none;
}

.shell-nav-support {
  margin-left: auto;
}

.app-main {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.app-topbar {
  min-height: var(--pagebar-h);
  border: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: rgba(17, 21, 30, 0.9);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
}

.topbar-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  white-space: nowrap;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.topbar-tabs {
  min-width: 0;
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
}

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

.topbar-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.topbar-tab:hover,
.topbar-tab.active,
.topbar-tab.is-active {
  background: var(--accent-dim);
  border-color: var(--border-strong);
  color: var(--accent);
}

.topbar-spacer {
  flex: 1;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-content {
  min-height: 0;
  flex: 1;
  overflow: visible;
  border: 0;
  background: var(--bg-content);
  padding: 16px;
  font-size: 13px;
}

.app-content h1 {
  font-size: 1.75rem;
}

.app-content h2 {
  font-size: 1.4rem;
}

.app-content h3 {
  font-size: 1.1rem;
}

.app-content::-webkit-scrollbar {
  width: 8px;
}

.app-content::-webkit-scrollbar-thumb {
  background: rgba(230, 185, 61, 0.35);
  border-radius: 10px;
}

.app-panel,
.glass-panel,
.table-shell {
  background: rgba(255, 255, 255, 0.03) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
}

.app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.app-content select,
.app-content textarea {
  background: rgba(255, 255, 255, 0.04) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: var(--radius-sm) !important;
  font-size: 0.95rem !important;
}

.app-content input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):focus,
.app-content select:focus,
.app-content textarea:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(230, 185, 61, 0.22) !important;
}

.app-content table,
.app-content .nice-table {
  width: 100%;
  border-collapse: collapse;
  background: transparent !important;
}

.app-content th {
  color: var(--text-faint) !important;
  border-bottom: 1px solid var(--border) !important;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.app-content td {
  color: var(--text-muted) !important;
  border-bottom: 1px solid rgba(230, 185, 61, 0.08) !important;
}

.app-content tr:hover td {
  background: var(--accent-glow) !important;
}

@media (max-width: 1180px) {
  .topbar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .shell-topbar {
    padding: 10px 12px;
    min-height: auto;
    display: flex;
    flex-wrap: wrap;
  }

  .shell-context {
    width: 100%;
    order: 3;
  }

  .shell-context-tabs,
  .shell-context-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .shell-topbar-actions {
    width: 100%;
    justify-content: flex-end;
    order: 2;
  }

  .shell-main-nav {
    display: none;
  }

  .app-shell.nav-open .shell-main-nav {
    display: flex;
    flex-wrap: wrap;
    padding: 10px 12px;
    height: auto;
  }

  .shell-nav-support {
    margin-left: 0;
  }
}

@media (max-width: 760px) {
  body.app-body .app-shell,
  .app-shell {
    width: calc(100vw - 10px) !important;
    height: auto !important;
    min-height: calc(100vh - 10px) !important;
    margin: 6px auto !important;
    border-radius: 12px !important;
  }

  .app-main {
    padding: 0;
  }

  .topbar-title {
    font-size: 22px;
  }

  .topbar-divider,
  .topbar-tabs,
  .topbar-spacer {
    display: none;
  }

  .app-content {
    padding: 12px;
  }
}
