:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --danger: #b91c1c;
}

/* Modern wide shell overrides */
.app {
  grid-template-columns: 1fr;
}

.sidebar {
  display: none;
}

.content {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.topbar-left {
  flex: 0 0 auto;
}

.topbar-left h2 {
  font-size: 16px;
}

.topbar-right {
  flex: 0 0 auto;
}

.version-chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.top-tabs {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  overflow-x: auto;
}

.top-tab {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 12px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.top-tab:hover,
.top-tab.active {
  background: #eef2ff;
  color: #1d4ed8;
}

.view {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.btn,
.card,
.stat-card,
.empty-state,
input,
textarea,
select,
.upload-modal,
.selected-files span,
.token-stat-card,
.token-table-card,
.history-stat,
.history-period-card,
.history-bubble {
  border-radius: 8px;
}

@media (max-width: 900px) {
  html,
  body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    touch-action: manipulation;
    background: #f4f2f0;
  }

  .app {
    height: 100dvh;
    overflow: hidden;
  }

  .topbar,
  .sidebar {
    display: none;
  }

  .content {
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: 1fr;
    padding-top: calc(64px + env(safe-area-inset-top, 0px));
    overflow: hidden;
    background: #f4f2f0;
  }

  .view,
  .history-view,
  .token-view {
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .mobile-nav,
  .mobile-nav.open {
    position: fixed;
    inset: 0 0 auto;
    z-index: 900;
    display: block;
    padding: env(safe-area-inset-top, 0px) 0 0;
    border: 0;
    background: #1a3c6e;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.12);
    backdrop-filter: none;
  }

  .mobile-menu-bar {
    position: relative;
    z-index: 930;
    min-height: 64px;
    display: grid;
    grid-template-columns: 36px 42px minmax(0, 1fr) auto 40px;
    gap: 8px;
    align-items: center;
    padding: 10px 10px 12px;
  }

  .mobile-back-btn,
  .mobile-menu-toggle {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    cursor: pointer;
  }

  .mobile-back-btn:active,
  .mobile-menu-toggle:active {
    background: rgba(255, 255, 255, 0.12);
  }

  .mobile-back-btn svg,
  .mobile-menu-toggle svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-menu-toggle svg {
    stroke-width: 0;
  }

  .mobile-avatar-wrap {
    position: relative;
    width: 40px;
    height: 40px;
  }

  .mobile-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
  }

  .mobile-avatar svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: rgba(255, 255, 255, 0.86);
    stroke-width: 1.6;
    stroke-linecap: round;
  }

  .mobile-avatar circle {
    fill: rgba(255, 255, 255, 0.22);
  }

  .mobile-online-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border: 2.5px solid #1a3c6e;
    border-radius: 999px;
    background: #4ade80;
  }

  .mobile-header-text {
    min-width: 0;
    display: grid;
    gap: 1px;
    color: #fff;
    text-decoration: none;
  }

  .mobile-header-text span {
    overflow: hidden;
    color: #fff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.18;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-text small {
    overflow: hidden;
    color: rgba(255, 255, 255, 0.58);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-version-chip {
    min-height: 26px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    padding: 0 7px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 910;
    display: block;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .mobile-nav.open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-links {
    position: fixed;
    top: calc(68px + env(safe-area-inset-top, 0px));
    right: 10px;
    left: auto;
    z-index: 940;
    width: min(82vw, 240px);
    height: auto;
    max-height: calc(100dvh - 88px - env(safe-area-inset-top, 0px));
    display: grid;
    grid-auto-rows: max-content;
    gap: 0;
    overflow: hidden auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.08);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.88) translateY(-6px);
    transform-origin: top right;
    transition:
      opacity 180ms cubic-bezier(0.22, 0.68, 0, 1.2),
      transform 180ms cubic-bezier(0.22, 0.68, 0, 1.2);
  }

  .mobile-nav.open .mobile-menu-links {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
  }

  .mobile-menu-panel-head {
    display: grid;
    gap: 2px;
    padding: 13px 16px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .mobile-menu-panel-head span {
    color: #1e293b;
    font-size: 15px;
    font-weight: 800;
  }

  .mobile-menu-panel-head small {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    text-transform: none;
  }

  .mobile-menu-links .mobile-link {
    min-height: 46px;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    gap: 12px;
    border: 0;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
    border-radius: 0;
    padding: 0 16px;
    background: #fff;
    color: #1e1e1e;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .mobile-menu-links .mobile-link::before {
    width: 18px;
    color: #1a3c6e;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
  }

  .mobile-menu-links .mobile-link[data-nav="chat"]::before {
    content: "C";
  }

  .mobile-menu-links .mobile-link[data-nav="history"]::before {
    content: "H";
  }

  .mobile-menu-links .mobile-link[data-nav="documents"]::before {
    content: "D";
  }

  .mobile-menu-links .mobile-link[data-nav="training"]::before {
    content: "T";
  }

  .mobile-menu-links .mobile-link[data-nav="tokens"]::before {
    content: "#";
  }

  .mobile-menu-links .mobile-link[data-nav="users"]::before {
    content: "U";
  }

  .mobile-menu-links .mobile-logout::before {
    content: "X";
  }

  .mobile-menu-links .mobile-link:last-child {
    border-bottom: 0;
  }

  .mobile-menu-links .mobile-link:active,
  .mobile-menu-links .mobile-link:hover,
  .mobile-menu-links .mobile-link.active {
    background: #f4f2f0;
    color: #1a3c6e;
  }
}

/* Last-pass native mobile shell override */
@media (max-width: 900px) {
  html,
  body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    touch-action: manipulation;
    background: #f4f2f0;
  }

  .app {
    height: 100dvh;
    overflow: hidden;
  }

  .topbar,
  .sidebar {
    display: none;
  }

  .content {
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: 1fr;
    padding-top: calc(64px + env(safe-area-inset-top, 0px));
    overflow: hidden;
    background: #f4f2f0;
  }

  .view,
  .history-view,
  .token-view {
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .mobile-nav,
  .mobile-nav.open {
    position: fixed;
    inset: 0 0 auto;
    z-index: 900;
    display: block;
    padding: env(safe-area-inset-top, 0px) 0 0;
    border: 0;
    background: #1a3c6e;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.12);
    backdrop-filter: none;
  }

  .mobile-menu-bar {
    position: relative;
    z-index: 930;
    min-height: 64px;
    display: grid;
    grid-template-columns: 36px 42px minmax(0, 1fr) auto 40px;
    gap: 8px;
    align-items: center;
    padding: 10px 10px 12px;
  }

  .mobile-back-btn,
  .mobile-menu-toggle {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    cursor: pointer;
  }

  .mobile-back-btn svg,
  .mobile-menu-toggle svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-menu-toggle svg {
    stroke-width: 0;
  }

  .mobile-avatar-wrap {
    position: relative;
    width: 40px;
    height: 40px;
  }

  .mobile-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
  }

  .mobile-avatar svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: rgba(255, 255, 255, 0.86);
    stroke-width: 1.6;
    stroke-linecap: round;
  }

  .mobile-avatar circle {
    fill: rgba(255, 255, 255, 0.22);
  }

  .mobile-online-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border: 2.5px solid #1a3c6e;
    border-radius: 999px;
    background: #4ade80;
  }

  .mobile-header-text {
    min-width: 0;
    display: grid;
    gap: 1px;
    color: #fff;
    text-decoration: none;
  }

  .mobile-header-text span {
    overflow: hidden;
    color: #fff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.18;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-text small {
    overflow: hidden;
    color: rgba(255, 255, 255, 0.58);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-version-chip {
    min-height: 26px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    padding: 0 7px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 910;
    display: block;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .mobile-nav.open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-links {
    position: fixed;
    top: calc(68px + env(safe-area-inset-top, 0px));
    right: 10px;
    left: auto;
    z-index: 940;
    width: min(82vw, 240px);
    height: auto;
    max-height: calc(100dvh - 88px - env(safe-area-inset-top, 0px));
    display: grid;
    grid-auto-rows: max-content;
    gap: 0;
    overflow: hidden auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.08);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.88) translateY(-6px);
    transform-origin: top right;
    transition:
      opacity 180ms cubic-bezier(0.22, 0.68, 0, 1.2),
      transform 180ms cubic-bezier(0.22, 0.68, 0, 1.2);
  }

  .mobile-nav.open .mobile-menu-links {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
  }

  .mobile-menu-panel-head {
    display: grid;
    gap: 2px;
    padding: 13px 16px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .mobile-menu-panel-head span {
    color: #1e293b;
    font-size: 15px;
    font-weight: 800;
  }

  .mobile-menu-panel-head small {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    text-transform: none;
  }

  .mobile-menu-links .mobile-link {
    min-height: 46px;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    gap: 12px;
    border: 0;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
    border-radius: 0;
    padding: 0 16px;
    background: #fff;
    color: #1e1e1e;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .mobile-menu-links .mobile-link::before {
    width: 18px;
    color: #1a3c6e;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
  }

  .mobile-menu-links .mobile-link[data-nav="chat"]::before {
    content: "C";
  }

  .mobile-menu-links .mobile-link[data-nav="history"]::before {
    content: "H";
  }

  .mobile-menu-links .mobile-link[data-nav="documents"]::before {
    content: "D";
  }

  .mobile-menu-links .mobile-link[data-nav="training"]::before {
    content: "T";
  }

  .mobile-menu-links .mobile-link[data-nav="tokens"]::before {
    content: "#";
  }

  .mobile-menu-links .mobile-link[data-nav="users"]::before {
    content: "U";
  }

  .mobile-menu-links .mobile-logout::before {
    content: "X";
  }

  .mobile-menu-links .mobile-link:last-child {
    border-bottom: 0;
  }

  .mobile-menu-links .mobile-link:active,
  .mobile-menu-links .mobile-link:hover,
  .mobile-menu-links .mobile-link.active {
    background: #f4f2f0;
    color: #1a3c6e;
  }
}

/* Final native mobile shell overrides */
@media (max-width: 900px) {
  html,
  body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    touch-action: manipulation;
    background: #f4f2f0;
  }

  .app {
    height: 100dvh;
    overflow: hidden;
  }

  .topbar,
  .sidebar {
    display: none;
  }

  .content {
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: 1fr;
    padding-top: calc(64px + env(safe-area-inset-top, 0px));
    overflow: hidden;
    background: #f4f2f0;
  }

  .view,
  .history-view,
  .token-view {
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .mobile-nav,
  .mobile-nav.open {
    position: fixed;
    inset: 0 0 auto;
    z-index: 900;
    display: block;
    padding: env(safe-area-inset-top, 0px) 0 0;
    border: 0;
    background: #1a3c6e;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.12);
    backdrop-filter: none;
  }

  .mobile-menu-bar {
    position: relative;
    z-index: 930;
    min-height: 64px;
    display: grid;
    grid-template-columns: 36px 42px minmax(0, 1fr) auto 40px;
    gap: 8px;
    align-items: center;
    padding: 10px 10px 12px;
  }

  .mobile-back-btn,
  .mobile-menu-toggle {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    cursor: pointer;
  }

  .mobile-back-btn:active,
  .mobile-menu-toggle:active {
    background: rgba(255, 255, 255, 0.12);
  }

  .mobile-back-btn svg,
  .mobile-menu-toggle svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-menu-toggle svg {
    stroke-width: 0;
  }

  .mobile-avatar-wrap {
    position: relative;
    width: 40px;
    height: 40px;
  }

  .mobile-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
  }

  .mobile-avatar svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: rgba(255, 255, 255, 0.86);
    stroke-width: 1.6;
    stroke-linecap: round;
  }

  .mobile-avatar circle {
    fill: rgba(255, 255, 255, 0.22);
  }

  .mobile-online-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border: 2.5px solid #1a3c6e;
    border-radius: 999px;
    background: #4ade80;
  }

  .mobile-header-text {
    min-width: 0;
    display: grid;
    gap: 1px;
    color: #fff;
    text-decoration: none;
  }

  .mobile-header-text span {
    overflow: hidden;
    color: #fff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.18;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-text small {
    overflow: hidden;
    color: rgba(255, 255, 255, 0.58);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-version-chip {
    min-height: 26px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    padding: 0 7px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 910;
    display: block;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .mobile-nav.open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-links {
    position: fixed;
    top: calc(68px + env(safe-area-inset-top, 0px));
    right: 10px;
    left: auto;
    z-index: 940;
    width: min(82vw, 240px);
    height: auto;
    max-height: calc(100dvh - 88px - env(safe-area-inset-top, 0px));
    display: grid;
    grid-auto-rows: max-content;
    gap: 0;
    overflow: hidden auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.08);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.88) translateY(-6px);
    transform-origin: top right;
    transition:
      opacity 180ms cubic-bezier(0.22, 0.68, 0, 1.2),
      transform 180ms cubic-bezier(0.22, 0.68, 0, 1.2);
  }

  .mobile-nav.open .mobile-menu-links {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
  }

  .mobile-menu-panel-head {
    display: grid;
    gap: 2px;
    padding: 13px 16px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .mobile-menu-panel-head span {
    color: #1e293b;
    font-size: 15px;
    font-weight: 800;
  }

  .mobile-menu-panel-head small {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    text-transform: none;
  }

  .mobile-menu-links .mobile-link {
    min-height: 46px;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    gap: 12px;
    border: 0;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
    border-radius: 0;
    padding: 0 16px;
    background: #fff;
    color: #1e1e1e;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .mobile-menu-links .mobile-link::before {
    width: 18px;
    color: #1a3c6e;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
  }

  .mobile-menu-links .mobile-link[data-nav="chat"]::before {
    content: "C";
  }

  .mobile-menu-links .mobile-link[data-nav="history"]::before {
    content: "H";
  }

  .mobile-menu-links .mobile-link[data-nav="documents"]::before {
    content: "D";
  }

  .mobile-menu-links .mobile-link[data-nav="training"]::before {
    content: "T";
  }

  .mobile-menu-links .mobile-link[data-nav="tokens"]::before {
    content: "#";
  }

  .mobile-menu-links .mobile-link[data-nav="users"]::before {
    content: "U";
  }

  .mobile-menu-links .mobile-logout::before {
    content: "X";
  }

  .mobile-menu-links .mobile-link:last-child {
    border-bottom: 0;
  }

  .mobile-menu-links .mobile-link:active,
  .mobile-menu-links .mobile-link:hover,
  .mobile-menu-links .mobile-link.active {
    background: #f4f2f0;
    color: #1a3c6e;
  }
}

/* Native mobile shell */
@media (max-width: 900px) {
  html,
  body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    touch-action: manipulation;
    background: #f4f2f0;
  }

  .app {
    display: grid;
    grid-template-columns: 1fr;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar,
  .topbar {
    display: none;
  }

  .content {
    min-height: 0;
    height: 100dvh;
    display: grid;
    grid-template-rows: 1fr;
    padding-top: calc(64px + env(safe-area-inset-top, 0px));
    overflow: hidden;
    background: #f4f2f0;
  }

  .view,
  .history-view,
  .token-view {
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .mobile-nav {
    position: fixed;
    inset: 0 0 auto;
    z-index: 900;
    display: block;
    padding: env(safe-area-inset-top, 0px) 0 0;
    border: 0;
    background: #1a3c6e;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.12);
    backdrop-filter: none;
  }

  .mobile-nav.open {
    background: #1a3c6e;
    border-bottom-color: transparent;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.12);
  }

  .mobile-menu-bar {
    position: relative;
    z-index: 930;
    min-height: 64px;
    display: grid;
    grid-template-columns: 36px 42px minmax(0, 1fr) auto 40px;
    gap: 8px;
    align-items: center;
    padding: 10px 10px 12px;
  }

  .mobile-back-btn,
  .mobile-menu-toggle {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    cursor: pointer;
  }

  .mobile-back-btn:active,
  .mobile-menu-toggle:active {
    background: rgba(255, 255, 255, 0.12);
  }

  .mobile-back-btn svg,
  .mobile-menu-toggle svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-menu-toggle svg {
    stroke-width: 0;
  }

  .mobile-avatar-wrap {
    position: relative;
    width: 40px;
    height: 40px;
  }

  .mobile-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
  }

  .mobile-avatar svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: rgba(255, 255, 255, 0.86);
    stroke-width: 1.6;
    stroke-linecap: round;
  }

  .mobile-avatar circle {
    fill: rgba(255, 255, 255, 0.22);
  }

  .mobile-online-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border: 2.5px solid #1a3c6e;
    border-radius: 999px;
    background: #4ade80;
  }

  .mobile-header-text {
    min-width: 0;
    display: grid;
    gap: 1px;
    color: #fff;
    text-decoration: none;
  }

  .mobile-header-text span {
    overflow: hidden;
    color: #fff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.18;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-text small {
    overflow: hidden;
    color: rgba(255, 255, 255, 0.58);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-version-chip {
    min-height: 26px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    padding: 0 7px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 910;
    display: block;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .mobile-nav.open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-links {
    position: fixed;
    top: calc(68px + env(safe-area-inset-top, 0px));
    right: 10px;
    left: auto;
    z-index: 940;
    width: min(82vw, 240px);
    height: auto;
    max-height: calc(100dvh - 88px - env(safe-area-inset-top, 0px));
    display: grid;
    grid-auto-rows: max-content;
    gap: 0;
    overflow: hidden auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.08);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.88) translateY(-6px);
    transform-origin: top right;
    transition:
      opacity 180ms cubic-bezier(0.22, 0.68, 0, 1.2),
      transform 180ms cubic-bezier(0.22, 0.68, 0, 1.2);
  }

  .mobile-nav.open .mobile-menu-links {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
  }

  .mobile-menu-panel-head {
    display: grid;
    gap: 2px;
    padding: 13px 16px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .mobile-menu-panel-head span {
    color: #1e293b;
    font-size: 15px;
    font-weight: 800;
  }

  .mobile-menu-panel-head small {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    text-transform: none;
  }

  .mobile-menu-links .mobile-link {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 0;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
    border-radius: 0;
    padding: 0 16px;
    background: #fff;
    color: #1e1e1e;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .mobile-menu-links .mobile-link::before {
    width: 18px;
    color: #1a3c6e;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
  }

  .mobile-menu-links .mobile-link[data-nav="chat"]::before {
    content: "C";
  }

  .mobile-menu-links .mobile-link[data-nav="history"]::before {
    content: "H";
  }

  .mobile-menu-links .mobile-link[data-nav="documents"]::before {
    content: "D";
  }

  .mobile-menu-links .mobile-link[data-nav="training"]::before {
    content: "T";
  }

  .mobile-menu-links .mobile-link[data-nav="tokens"]::before {
    content: "#";
  }

  .mobile-menu-links .mobile-link[data-nav="users"]::before {
    content: "U";
  }

  .mobile-menu-links .mobile-logout::before {
    content: "X";
  }

  .mobile-menu-links .mobile-link:last-child {
    border-bottom: 0;
  }

  .mobile-menu-links .mobile-link:active,
  .mobile-menu-links .mobile-link:hover,
  .mobile-menu-links .mobile-link.active {
    background: #f4f2f0;
    color: #1a3c6e;
  }

  .mobile-menu-open {
    overflow: hidden;
  }
}

/* Native mobile shell guard against older mobile overrides */
@media (max-width: 900px) {
  .content {
    height: 100dvh !important;
    min-height: 0 !important;
    display: grid !important;
    grid-template-rows: 1fr !important;
    padding-top: calc(64px + env(safe-area-inset-top, 0px)) !important;
    overflow: hidden !important;
    background: #f4f2f0 !important;
  }

  .mobile-nav,
  .mobile-nav.open {
    position: fixed !important;
    inset: 0 0 auto !important;
    display: block !important;
    gap: 0 !important;
    overflow: visible !important;
    padding: env(safe-area-inset-top, 0px) 0 0 !important;
    border: 0 !important;
    background: #1a3c6e !important;
  }

  .mobile-menu-bar {
    min-height: 64px !important;
    display: grid !important;
    grid-template-columns: 36px 42px minmax(0, 1fr) auto 40px !important;
    gap: 8px !important;
    align-items: center !important;
    padding: 10px 10px 12px !important;
  }

  .mobile-menu-links {
    right: 10px !important;
    left: auto !important;
    width: min(86vw, 236px) !important;
    height: auto !important;
    display: grid !important;
    gap: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 10px !important;
    background: #fff !important;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.08) !important;
    transform-origin: top right !important;
  }

  .mobile-menu-links .mobile-link {
    min-height: 56px !important;
    display: flex !important;
    flex: 0 1 auto !important;
    align-items: center !important;
    gap: 14px !important;
    border: 0 !important;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    border-radius: 0 !important;
    padding: 0 20px !important;
    background: #fff !important;
    color: #1e1e1e !important;
    font-size: 16px !important;
    font-weight: 500 !important;
  }

  .mobile-menu-panel-head {
    padding: 10px 12px !important;
  }

  .mobile-menu-panel-head span {
    font-size: 13px !important;
  }

  .mobile-menu-panel-head small {
    font-size: 10px !important;
  }

  .mobile-menu-links .mobile-link::before {
    content: none !important;
    display: none !important;
  }

  .mobile-link-icon {
    width: 18px !important;
    height: 18px !important;
    display: inline-grid !important;
    place-items: center !important;
    flex: 0 0 auto !important;
    color: #1a3c6e !important;
  }

  .mobile-link-icon svg {
    width: 18px !important;
    height: 18px !important;
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2 !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
  }

  .mobile-menu-links .mobile-link.active,
  .mobile-menu-links .mobile-link:hover,
  .mobile-menu-links .mobile-link:active {
    background: #f4f2f0 !important;
    color: #1a3c6e !important;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-link {
  border-radius: 12px;
  padding: 10px 12px;
  color: #334155;
  font-weight: 600;
}

.nav-link.active {
  background: #eaf1ff;
  color: #1d4ed8;
}

.content {
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left h2 {
  margin: 0;
  font-size: 18px;
}

.topbar-left small {
  color: var(--muted);
}

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

.chip {
  border: 1px solid var(--line);
  background: #f9fafb;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
}

.btn:hover {
  background: var(--brand-dark);
}

.btn.soft {
  background: #eef2ff;
  color: #1d4ed8;
}

.btn.soft:hover {
  background: #e0e7ff;
}

.btn.danger {
  background: var(--danger);
}

.view {
  padding: 14px;
  overflow: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.hero h3 {
  margin: 0;
  font-size: 20px;
}

.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 720px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card {
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 14px;
}

.document-layout {
  display: grid;
  grid-template-columns: 1fr;
}

.document-list-card {
  min-width: 0;
}

.stack {
  display: grid;
  gap: 14px;
}

.status-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  background: #eef2ff;
  color: #1d4ed8;
}

.badge.success {
  background: #ecfdf5;
  color: #047857;
}

.badge.danger {
  background: #fef2f2;
  color: #b91c1c;
}

.empty-state {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  text-align: center;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 28%, rgba(255, 255, 255, 0.88), transparent 34%),
    radial-gradient(circle at 82% 30%, rgba(219, 234, 254, 0.9), transparent 38%),
    linear-gradient(180deg, rgba(248, 250, 252, 0.96), rgba(239, 246, 255, 0.92));
  display: flex;
  flex-direction: column;
  z-index: 20;
  overflow: auto;
}

.login-brandmark {
  padding: 22px 26px 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-shell {
  min-height: calc(100vh - 56px);
  width: 100%;
  display: grid;
  place-items: center;
  padding: 28px 16px 40px;
}

.login-box {
  width: min(420px, 92vw);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  padding: 34px 34px 26px;
  box-shadow: 0 18px 50px rgba(148, 163, 184, 0.18);
  backdrop-filter: blur(12px);
}

.login-header {
  text-align: center;
  margin-bottom: 18px;
}

.login-header h3 {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.login-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #eef2f7;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  background: #f3f6fb;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid #dbeafe;
  border-color: #bfdbfe;
  background: #fff;
}

.login-message {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.login-submit {
  width: 100%;
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #6b8df2);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
}

.login-submit:hover {
  background: linear-gradient(90deg, #1d4ed8, #5c7ee6);
}

.login-footer {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 18px;
  color: #9ca3af;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  font-size: 13px;
}

th {
  color: var(--muted);
}

.action-group {
  display: flex;
  gap: 6px;
}

.doc-process {
  min-width: 230px;
  display: grid;
  gap: 8px;
  color: #475569;
}

.doc-process-lines {
  display: grid;
  gap: 3px;
  font-size: 12px;
  line-height: 1.35;
}

.doc-process-lines strong {
  color: #64748b;
}

.doc-progress-track {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f7;
}

.doc-progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #22c55e);
  transition: width 240ms ease;
}

.upload-drop-zone {
  display: grid;
  gap: 6px;
  place-items: center;
  min-height: 150px;
  border: 1px dashed #bfdbfe;
  border-radius: 8px;
  background: #f8fbff;
  color: #64748b;
  text-align: center;
  cursor: pointer;
  padding: 18px;
  transition:
    background 180ms ease,
    border-color 180ms ease;
}

.upload-drop-zone.dragover {
  border-color: #2563eb;
  background: #eff6ff;
}

.upload-drop-zone strong {
  color: #1f2937;
}

.upload-drop-zone input {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(2px);
}

.upload-modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: 18px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.22);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0 0 6px;
  font-size: 19px;
}

.modal-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.modal-close {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  background: #f3f6fb;
  color: #64748b;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: #e5e7eb;
}

.upload-submit {
  width: 100%;
  margin-top: 14px;
}

body.modal-open {
  overflow: hidden;
}

.selected-files {
  display: grid;
  gap: 6px;
  color: #64748b;
  font-size: 12px;
}

.selected-files span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid #eef2f7;
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
}

.document-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.document-toolbar label {
  display: grid;
  gap: 5px;
}

.document-toolbar span {
  color: #94a3b8;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.batch-action-bar {
  position: sticky;
  top: 8px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 28px rgba(148, 163, 184, 0.16);
  backdrop-filter: blur(10px);
}

.batch-action-bar strong {
  margin-right: auto;
  color: #1f2937;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag-list span {
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2ff;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 800;
}

.muted-text {
  color: #94a3b8;
}

.training-example {
  display: block;
  margin-top: 5px;
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.35;
}

.role-select {
  width: auto;
  min-width: 120px;
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
}

.mobile-nav {
  display: none;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px;
  gap: 8px;
}

.mobile-menu-bar,
.mobile-menu-links,
.mobile-menu-backdrop {
  display: none;
}

body.mobile-menu-open {
  overflow: hidden;
}

.mobile-link {
  flex: 1;
  text-align: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  background: #fff;
}

.mobile-link.active {
  background: #eaf1ff;
  color: #1d4ed8;
  border-color: #c7d2fe;
}

.history-topbar {
  background: #f8fafc;
}

.history-search {
  min-width: 220px;
  border-radius: 999px;
  background: #eef2f7;
  color: #94a3b8;
  padding: 8px 14px;
  font-size: 12px;
}

.history-view {
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
  padding: 32px 32px 44px;
}

.history-dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 22px;
  margin-bottom: 26px;
}

.history-stat,
.history-period-card {
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 1px solid #edf0f4;
  border-radius: 24px;
  padding: 26px 28px;
  box-shadow: 0 18px 40px rgba(148, 163, 184, 0.12);
  min-height: 132px;
}

.history-stat::after {
  content: "";
  position: absolute;
  right: 24px;
  top: 22px;
  width: 34px;
  height: 34px;
  border: 4px solid #e5e7eb;
  border-radius: 8px;
  opacity: 0.75;
}

.history-stat span {
  display: block;
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.history-stat .stat-value {
  font-size: 38px;
  letter-spacing: 0.02em;
}

.history-stat small {
  display: block;
  margin-top: 14px;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}

.history-period-card {
  background: linear-gradient(135deg, #0b5ed7, #5f86f2);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 20px 42px rgba(37, 99, 235, 0.28);
}

.history-period-card span {
  display: block;
  margin-bottom: 10px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.history-period-card strong {
  display: block;
  font-size: 28px;
  line-height: 1.1;
}

.history-period-card small {
  display: inline-flex;
  margin-top: 18px;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 11px;
  font-weight: 800;
}

.history-filter-bar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
  padding: 6px;
}

.filter-label {
  color: #9ca3af;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(170px, 1.1fr) minmax(150px, 0.9fr) repeat(2, minmax(150px, 1fr)) 44px;
  gap: 10px;
  align-items: center;
}

.history-filters label {
  position: relative;
}

.history-filters label span {
  position: absolute;
  left: 14px;
  top: -7px;
  background: var(--bg);
  padding: 0 5px;
  color: #9ca3af;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.history-filters input,
.history-filters select {
  border-radius: 999px;
  padding: 10px 14px;
  background: #fff;
}

.history-filters input:disabled {
  color: #64748b;
  background: #f8fafc;
}

.history-filters .btn {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  padding: 0;
  font-size: 0;
}

.history-filters .btn::before {
  content: ">";
  font-size: 18px;
  line-height: 1;
}

.history-list {
  display: grid;
  gap: 0;
  position: relative;
  padding-left: 42px;
}

.history-list::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #e2e8f0;
}

.history-thread {
  position: relative;
  padding: 0 0 34px;
}

.history-thread-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 26px;
  margin-bottom: 14px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.history-dot {
  position: absolute;
  left: -40px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #0b5ed7;
  box-shadow: 0 0 0 5px #eef5ff;
}

.history-thread-meta strong {
  margin-left: auto;
  color: #94a3b8;
  font-weight: 800;
}

.history-full-chat {
  border: 0;
  padding: 0;
  background: transparent;
  color: #0b5ed7;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.history-user-label {
  margin: -6px 0 14px;
  color: #64748b;
  font-size: 12px;
}

.history-message {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
  margin-top: 14px;
}

.history-message.ai {
  grid-template-columns: 32px minmax(0, 0.72fr);
}

.history-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #0b5ed7;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
}

.history-avatar.ai {
  background: #eef2ff;
  color: #1d4ed8;
}

.history-bubble {
  border-radius: 24px;
  padding: 18px 20px;
  font-size: 13px;
  line-height: 1.55;
}

.history-bubble.question {
  background: #075bd8;
  color: #fff;
  justify-self: end;
  width: min(720px, 82%);
  font-weight: 700;
}

.history-bubble.answer {
  background: #e9edf2;
  color: #3f4652;
  min-height: 86px;
}

.token-topbar {
  background: #f8fafc;
}

.token-view {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 30px 28px 42px;
}

.token-filter-bar {
  display: grid;
  grid-template-columns: auto 1fr minmax(220px, 280px);
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.token-filter-bar > span,
.token-search span {
  color: #9ca3af;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.token-period-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(120px, auto));
  gap: 2px;
  width: fit-content;
  padding: 3px;
  border: 1px solid #e8edf5;
  border-radius: 8px;
  background: #fff;
}

.token-period-tabs button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  background: transparent;
  color: #64748b;
  font-weight: 800;
  cursor: pointer;
}

.token-period-tabs button.active {
  background: #2563eb;
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

.token-period-tabs button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.token-search {
  display: grid;
  gap: 5px;
}

.token-search input {
  border-radius: 999px;
  background: #fff;
  padding: 10px 14px;
}

.token-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 26px;
  margin-bottom: 28px;
}

.token-stat-card,
.token-table-card {
  background: #fff;
  border: 1px solid #edf0f4;
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(148, 163, 184, 0.12);
}

.token-stat-card {
  min-height: 132px;
  padding: 26px 28px;
}

.token-stat-card.primary {
  position: relative;
  overflow: hidden;
  background: #2f6eea;
  color: #fff;
  border-color: transparent;
  box-shadow: 0 20px 42px rgba(37, 99, 235, 0.28);
}

.token-stat-card.primary::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: 18px;
  width: 74px;
  height: 74px;
  background:
    linear-gradient(30deg, transparent 47%, rgba(255, 255, 255, 0.14) 48% 52%, transparent 53%),
    linear-gradient(150deg, transparent 47%, rgba(255, 255, 255, 0.12) 48% 52%, transparent 53%),
    rgba(255, 255, 255, 0.08);
  clip-path: polygon(50% 0, 92% 25%, 92% 75%, 50% 100%, 8% 75%, 8% 25%);
}

.token-stat-card span {
  display: block;
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 10px;
}

.token-stat-card.primary span {
  color: rgba(255, 255, 255, 0.78);
}

.token-stat-card strong {
  display: block;
  font-size: 34px;
  line-height: 1;
}

.token-stat-card small {
  display: block;
  margin-top: 16px;
  color: #8a94a6;
  font-size: 12px;
  font-weight: 700;
}

.token-stat-card.primary small {
  color: rgba(255, 255, 255, 0.82);
}

.token-table-card {
  padding: 28px;
}

.token-table-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.token-table-head h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.token-table-head p {
  margin: 0;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 700;
}

.token-table {
  min-width: 850px;
}

.token-table th {
  border-bottom: 0;
  color: #a3acbd;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.token-table th.numeric,
.token-table td.token-number,
.token-table td.token-usage {
  text-align: right;
}

.token-table td {
  padding: 16px 8px;
  color: #475569;
  font-weight: 700;
}

.rank-pill {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #eaf2ff;
  color: #2f6eea;
  font-size: 12px;
  font-weight: 900;
}

.token-user {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  align-items: center;
}

.token-user span {
  min-width: 0;
  color: #1f2937;
}

.token-user small {
  width: fit-content;
  border-radius: 999px;
  padding: 3px 8px;
  background: #f1f5f9;
  color: #94a3b8;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.token-usage {
  color: #2563eb !important;
}

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

  .sidebar {
    display: none;
  }

  .content {
    min-height: 100vh;
    grid-template-rows: auto 1fr;
    padding-top: 58px;
  }

  .topbar {
    display: none;
  }

  .mobile-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 90;
    display: block;
    padding: 0;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid rgba(229, 231, 235, 0.68);
    box-shadow: 0 10px 28px rgba(148, 163, 184, 0.12);
    backdrop-filter: blur(12px);
  }

  .mobile-nav.open {
    background: rgba(255, 255, 255, 0.96);
    border-bottom-color: rgba(229, 231, 235, 0.68);
    box-shadow: 0 10px 28px rgba(148, 163, 184, 0.12);
  }

  .mobile-menu-bar {
    position: relative;
    z-index: 120;
    min-height: 58px;
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    padding: 0 16px;
  }

  .mobile-menu-brand {
    justify-self: start;
    color: #2f6eea;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0;
  }

  .mobile-nav.open .mobile-menu-brand {
    color: #2f6eea;
  }

  .mobile-menu-toggle,
  .mobile-menu-more {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
  }

  .mobile-nav.open .mobile-menu-toggle,
  .mobile-nav.open .mobile-menu-more {
    color: #64748b;
  }

  .mobile-nav.open .mobile-menu-toggle {
    border-radius: 999px;
    background: #eef2ff;
  }

  .mobile-menu-toggle {
    gap: 4px;
  }

  .mobile-menu-toggle span {
    width: 17px;
    height: 2px;
    display: block;
    border-radius: 999px;
    background: #64748b;
  }

  .mobile-nav.open .mobile-menu-toggle span {
    background: #2f6eea;
  }

  .mobile-menu-more {
    justify-self: end;
    padding-bottom: 8px;
    font-size: 24px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: 0;
  }

  .mobile-menu-links {
    position: fixed;
    top: 66px;
    left: 8px;
    z-index: 110;
    width: min(88vw, 340px);
    height: calc(100vh - 78px);
    display: grid;
    grid-auto-rows: max-content;
    gap: 10px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 22px;
    background:
      radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.11), transparent 34%),
      rgba(20, 25, 30, 0.88);
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.34);
    backdrop-filter: blur(16px);
    transform: translateX(calc(-100% - 16px));
    opacity: 0;
    pointer-events: none;
    transition:
      transform 240ms ease,
      opacity 220ms ease;
  }

  .mobile-nav.open .mobile-menu-links {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: block;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .mobile-nav.open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-panel-head {
    display: grid;
    gap: 4px;
    padding: 4px 4px 12px;
  }

  .mobile-menu-panel-head span {
    color: #f8fafc;
    font-size: 20px;
    font-weight: 900;
  }

  .mobile-menu-panel-head small {
    color: #9ca3af;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .mobile-menu-links .mobile-link {
    min-height: 48px;
    display: grid;
    grid-template-columns: 34px 1fr;
    align-items: center;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #e5e7eb;
    text-align: left;
    font-size: 16px;
    font-weight: 800;
    transition:
      background 180ms ease,
      color 180ms ease;
  }

  .mobile-menu-links .mobile-link::before {
    width: 24px;
    color: #d1d5db;
    font-size: 19px;
    font-weight: 500;
    text-align: center;
  }

  .mobile-menu-links .mobile-link[data-nav="chat"]::before {
    content: "<";
  }

  .mobile-menu-links .mobile-link[data-nav="history"]::before {
    content: "o";
  }

  .mobile-menu-links .mobile-link[data-nav="documents"]::before {
    content: "[]";
  }

  .mobile-menu-links .mobile-link[data-nav="training"]::before {
    content: "+";
  }

  .mobile-menu-links .mobile-link[data-nav="tokens"]::before {
    content: "#";
  }

  .mobile-menu-links .mobile-link[data-nav="users"]::before {
    content: "*";
  }

  .mobile-menu-links .mobile-link + .mobile-link {
    border-top: 0;
  }

  .mobile-menu-links .mobile-link:hover,
  .mobile-menu-links .mobile-link.active {
    background: rgba(255, 255, 255, 0.1);
    color: #f8fafc;
  }

  .split-layout {
    grid-template-columns: 1fr;
  }

  .login-brandmark {
    padding: 16px 18px 0;
  }

  .login-box {
    padding: 28px 22px 22px;
    border-radius: 24px;
  }

  .login-footer {
    gap: 14px;
    flex-wrap: wrap;
  }

  .history-view {
    padding: 22px 14px;
  }

  .history-dashboard,
  .history-filter-bar,
  .history-filters {
    grid-template-columns: 1fr;
  }

  .history-list {
    padding-left: 28px;
  }

  .history-dot {
    left: -30px;
  }

  .history-thread-meta {
    gap: 8px;
    flex-wrap: wrap;
  }

  .history-thread-meta strong {
    margin-left: 0;
  }

  .history-message.ai {
    grid-template-columns: 30px 1fr;
  }

  .history-bubble.question {
    width: 100%;
  }

  .history-search {
    display: none;
  }

  .token-view {
    padding: 22px 14px;
  }

  .token-filter-bar,
  .token-stats {
    grid-template-columns: 1fr;
  }

  .token-period-tabs {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .token-table-head {
    display: grid;
  }
}

@media (max-width: 520px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    background: #f7f9fc;
  }

  .app,
  .content,
  .view,
  .card,
  .token-table-card,
  .history-view,
  .token-view {
    max-width: 100%;
    overflow-x: hidden;
  }

  .view {
    padding: 16px 14px 24px;
  }

  .hero {
    display: grid;
    grid-template-columns: 1fr;
    margin-bottom: 16px;
  }

  .hero h3 {
    font-size: 18px;
    line-height: 1.25;
  }

  .hero p {
    font-size: 13px;
    line-height: 1.5;
  }

  .stats-grid,
  .document-layout,
  .history-dashboard,
  .token-stats,
  .split-layout,
  .history-filter-bar,
  .history-filters,
  .token-filter-bar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card,
  .stat-card,
  .history-stat,
  .history-period-card,
  .token-stat-card,
  .token-table-card {
    width: 100%;
    border-radius: 8px;
    padding: 16px;
  }

  .stat-value,
  .history-stat .stat-value,
  .token-stat-card strong {
    font-size: 26px;
    line-height: 1.1;
  }

  .token-period-tabs {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .token-period-tabs button,
  .btn,
  input,
  textarea,
  select {
    min-height: 44px;
  }

  .field {
    margin-top: 12px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  .token-table {
    min-width: 0;
    width: 100%;
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    display: grid;
    width: 100%;
    border: 1px solid #e8edf5;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(148, 163, 184, 0.1);
    overflow: hidden;
  }

  td {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid #edf0f4;
    padding: 11px 12px;
    font-size: 13px;
    overflow-wrap: anywhere;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: #94a3b8;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  td[colspan] {
    display: block;
    padding: 18px 12px;
    text-align: center;
  }

  td[colspan]::before {
    content: "";
    display: none;
  }

  .action-group {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .action-group .btn {
    width: 100%;
  }

  .role-select {
    width: 100%;
    min-width: 0;
  }

  .document-toolbar {
    grid-template-columns: 1fr;
  }

  .batch-action-bar {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
  }

  .batch-action-bar strong {
    margin-right: 0;
  }

  .doc-process {
    min-width: 0;
  }

  .token-table-head {
    gap: 8px;
    margin-bottom: 14px;
  }

  .history-view,
  .token-view {
    padding: 18px 14px 28px;
  }

  .history-list {
    padding-left: 0;
  }

  .history-list::before,
  .history-dot {
    display: none;
  }

  .history-thread {
    padding-bottom: 26px;
  }

  .history-thread-meta {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
  }

  .history-thread-meta strong,
  .history-full-chat {
    margin-left: 0;
    justify-self: start;
  }

  .history-message.ai {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .history-bubble {
    border-radius: 18px;
    padding: 14px 15px;
  }

  .history-bubble.question {
    width: 100%;
  }

  .login-shell {
    min-height: calc(100vh - 46px);
    padding: 18px 14px 26px;
  }

  .login-box {
    width: 100%;
    max-width: 360px;
    padding: 26px 18px 20px;
    border-radius: 8px;
  }
}

/* Final shell overrides keep the app wide and sidebar-free. */
.app {
  grid-template-columns: 1fr;
}

.sidebar {
  display: none;
}

.content {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.topbar-left,
.topbar-right {
  flex: 0 0 auto;
}

.topbar-left h2 {
  font-size: 16px;
}

.top-tabs {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  overflow-x: auto;
}

.top-tab {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 12px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.top-tab:hover,
.top-tab.active {
  background: #eef2ff;
  color: #1d4ed8;
}

.view {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.btn,
.card,
.stat-card,
.empty-state,
input,
textarea,
select,
.upload-modal,
.selected-files span,
.token-stat-card,
.token-table-card,
.history-stat,
.history-period-card,
.history-bubble {
  border-radius: 8px;
}

@media (max-width: 900px) {
  .content {
    padding-top: 50px;
  }

  .mobile-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 7px 10px;
  }

  .mobile-nav .mobile-link {
    flex: 0 0 auto;
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
    background: transparent;
  }

  .mobile-nav .mobile-link.active {
    background: #eef2ff;
    color: #1d4ed8;
  }
}
