/* ═══════════════════════════════════════════════════════════════
   TradeMesh — App shell (sidebar + topbar + dashboard components)
   Colors/component look from the old build; sidebar-folder structure,
   collapsible rail, profile dropdown, and chat widget are new — see
   frontend/map.md for the old-vs-new merge rationale.
   ═══════════════════════════════════════════════════════════════ */

.app-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Sidebar + main content share this row, below the full-width topbar. */
.app-body { flex: 1; display: flex; overflow: hidden; min-height: 0; }

/* ── SIDEBAR ─────────────────────────────────────── */
.app-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: relative; overflow-y: auto; overflow-x: hidden;
  transition: width 0.2s ease;
}
.app-sidebar.rail { width: var(--sidebar-w-rail); }

.sidebar-rail-btn {
  position: absolute; top: 14px; right: -12px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--orange); border: 2px solid var(--bg);
  display: flex; align-items: center; justify-content: center;
  color: #fff; cursor: pointer; z-index: 110; font-size: 0.65rem;
  transition: background 0.15s, transform 0.2s;
  animation: sidebar-rail-pulse 2.4s ease-out infinite;
}
.sidebar-rail-btn:hover { background: var(--orange-2); }
.app-sidebar.rail .sidebar-rail-btn { transform: rotate(180deg); }

/* Persistent eye-catching pulse — always on, not a one-time dismiss like the
   chat launcher's attention animation (this is a permanent affordance). */
@keyframes sidebar-rail-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(193,122,74,0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(193,122,74,0); }
  100% { box-shadow: 0 0 0 0 rgba(193,122,74,0); }
}

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 2rem 0.75rem 0.85rem; }
.nav-folder { margin-bottom: 2px; }
.nav-folder-hdr {
  display: flex; align-items: center; gap: 0.55rem; padding: 0.6rem 0.6rem;
  border-radius: var(--r-sm); cursor: pointer; transition: background 0.15s;
}
.nav-folder-hdr:hover { background: var(--bg-surface); }
.nav-folder-chevron { font-size: 0.6rem; color: var(--text-3); transition: transform 0.15s; flex-shrink: 0; width: 10px; text-align: center; }
.nav-folder.open .nav-folder-chevron { transform: rotate(90deg); }
.nav-folder-icon { font-size: 0.85rem; flex-shrink: 0; width: 16px; text-align: center; }
.nav-folder-label { font-size: 0.64rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; overflow: hidden; }
.nav-folder-items { display: none; padding-left: 1.05rem; margin-left: 1.1rem; border-left: 1px solid var(--border); padding-top: 2px; padding-bottom: 4px; }
.nav-folder.open .nav-folder-items { display: block; }

.sidebar-nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.55rem 0.6rem; border-radius: var(--r-sm);
  font-size: 0.83rem; font-weight: 500; color: var(--text-2);
  margin-bottom: 2px; transition: all 0.15s; white-space: nowrap; overflow: hidden;
}
.sidebar-nav-item:hover { background: var(--bg-surface); color: var(--text-1); }
.sidebar-nav-item.active { background: var(--orange-dim); color: var(--orange-2); font-weight: 600; }
.sidebar-nav-item .nav-icon { font-size: 0.9rem; flex-shrink: 0; width: 16px; text-align: center; }
.sidebar-nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }

.app-sidebar.rail .nav-folder-label,
.app-sidebar.rail .nav-folder-chevron,
.app-sidebar.rail .nav-folder-items,
.app-sidebar.rail .nav-label,
.app-sidebar.rail .sidebar-footer-label { display: none; }
.app-sidebar.rail .nav-folder-hdr,
.app-sidebar.rail .sidebar-nav-item { justify-content: center; }

.sidebar-footer { padding: 1rem 0.75rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-submit-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  width: 100%; padding: 0.65rem; border-radius: var(--r-sm);
  background: var(--orange); color: #fff;
  font-size: 0.84rem; font-weight: 700; border: none; cursor: pointer;
  transition: background 0.18s; white-space: nowrap; overflow: hidden;
}
.sidebar-submit-btn:hover { background: var(--orange-2); }

.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 290; background: rgba(44,26,14,0.5); backdrop-filter: blur(3px); }
.sidebar-backdrop.show { display: block; }

/* ── MAIN ────────────────────────────────────────── */
.app-main { flex: 1; min-width: 0; overflow-y: auto; }

/* ── TOPBAR — full width, spans above the sidebar+main row ── */
.app-topbar {
  height: var(--nav-h); flex-shrink: 0; width: 100%;
  background: rgba(250,247,242,0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 60;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1.75rem;
}
[data-theme="dark"] .app-topbar { background: rgba(17,17,24,0.92); }

.topbar-logo { display: flex; align-items: center; gap: 0.55rem; flex-shrink: 0; }
.topbar-logo-img { width: 30px; height: 30px; object-fit: contain; border-radius: 8px; flex-shrink: 0; }
.topbar-logo-text { font-size: 0.9rem; font-weight: 800; color: var(--text-1); white-space: nowrap; }
.topbar-logo-text span { color: var(--orange); }

.topbar-page-title { font-size: 0.88rem; font-weight: 700; color: var(--text-1); white-space: nowrap; flex-shrink: 0; }
.topbar-page-title .sub { color: var(--text-3); font-weight: 400; font-size: 0.8rem; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }

.sidebar-toggle {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--bg-surface); cursor: pointer; color: var(--text-2);
  transition: background 0.15s;
}
.sidebar-toggle:hover { background: var(--bg-alt); color: var(--text-1); }

.topbar-notif-btn {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--bg-surface);
  cursor: pointer; color: var(--text-2); transition: all 0.15s; flex-shrink: 0;
}
.topbar-notif-btn:hover { border-color: var(--border-2); color: var(--text-1); }
.notif-badge { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); border: 2px solid var(--bg-surface); }

/* Profile menu */
.profile-menu-wrap { position: relative; }
.profile-chip {
  display: flex; align-items: center; gap: 0.5rem; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px 4px 4px; cursor: pointer;
}
.profile-chip-av { width: 28px; height: 28px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--orange-dim); }
.profile-chip-name { font-size: 0.8rem; font-weight: 700; color: var(--text-1); }
.profile-chip-chev { color: var(--text-3); font-size: 0.65rem; transition: transform 0.15s; }
.profile-menu-wrap.open .profile-chip-chev { transform: rotate(180deg); }

.profile-dropdown {
  position: absolute; top: 48px; right: 0; width: 230px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-lg); padding: 8px; z-index: 60;
  display: none;
}
.profile-menu-wrap.open .profile-dropdown { display: block; }
.pd-user { display: flex; align-items: center; gap: 10px; padding: 9px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pd-user-av { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; flex-shrink: 0; background: var(--orange-dim); }
.pd-user-name { font-size: 0.82rem; font-weight: 700; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pd-user-email { font-size: 0.68rem; color: var(--text-3); }
.pd-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: var(--r-sm);
  font-size: 0.82rem; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.pd-item:hover { background: var(--bg-surface); color: var(--text-1); }
.pd-item.danger { color: var(--red); }
.pd-item.danger:hover { background: var(--red-dim); }
.pd-divider { height: 1px; background: var(--border); margin: 6px 4px; }
.pd-section-label { padding: 8px 10px 2px; font-size: 0.64rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }

.theme-toggle { display: flex; align-items: center; gap: 4px; padding: 6px 10px 8px; }
.tt-btn {
  flex: 1; border: none; background: var(--bg-alt); cursor: pointer;
  height: 30px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; transition: background 0.15s, color 0.15s; color: var(--text-3);
}
.tt-btn:hover { background: var(--bg-surface); color: var(--text-1); }
.tt-btn.active { background: var(--orange); color: #fff; }

/* ── CONTENT ─────────────────────────────────────── */
.app-content { padding: 1.75rem; padding-bottom: 3.5rem; }

.metric-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1.5rem; }
.metric-card { padding: 1.2rem 1.25rem; }
.metric-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 0.4rem; }
.metric-val { font-size: 1.4rem; font-weight: 800; color: var(--text-1); font-family: var(--mono); letter-spacing: -0.02em; margin-bottom: 0.2rem; }
.metric-sub { font-size: 0.72rem; display: flex; align-items: center; gap: 0.3rem; }
.metric-sub .up { color: var(--red); } .metric-sub .dn { color: var(--green); } .metric-sub .st { color: var(--neutral); }

.filter-bar {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r); padding: 0.75rem 1rem;
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.25rem;
}
.filter-group { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.filter-label { font-size: 0.72rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
.filter-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }
.filter-btn {
  padding: 0.35rem 0.85rem; border-radius: 100px;
  font-size: 0.78rem; font-weight: 600; border: 1.5px solid var(--border);
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: all 0.15s; white-space: nowrap;
}
.filter-btn:hover { border-color: var(--border-2); color: var(--text-1); }
.filter-btn.active { background: var(--orange-dim); border-color: var(--orange-bd); color: var(--orange-2); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.25rem; align-items: start; }
@media (max-width: 1100px) { .dashboard-grid { grid-template-columns: 1fr; } }

.alerts-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); }
.alerts-header h4 { font-size: 0.84rem; }
.alert-item { padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.alert-item:hover { background: var(--bg-alt); }
.alert-item:last-child { border-bottom: none; }
.alert-title { font-size: 0.82rem; font-weight: 600; color: var(--text-1); margin-bottom: 0.15rem; }
.alert-sub { font-size: 0.74rem; color: var(--text-3); }
.alert-dot-up { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }
.alert-dot-dn { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.alert-row { display: flex; align-items: flex-start; gap: 0.7rem; }

.chart-section { margin-top: 1.25rem; }
.chart-box { padding: 1.25rem 1.5rem; }
.chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.chart-tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chart-tab {
  padding: 0.3rem 0.75rem; border-radius: 100px;
  font-size: 0.75rem; font-weight: 600; border: 1px solid var(--border);
  background: transparent; color: var(--text-3); cursor: pointer; transition: all 0.15s;
}
.chart-tab.active { background: var(--blue-dim); border-color: var(--blue-bd); color: var(--blue-dk); }

.price-table-wrap { overflow: auto; }
.price-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.price-table thead th {
  padding: 0.75rem 1rem; text-align: left; font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3);
  background: var(--bg-alt); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.price-table thead th:not(:first-child) { text-align: right; }
.price-table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
.price-table tbody tr:last-child { border-bottom: none; }
.price-table tbody tr:hover { background: var(--bg-alt); }
.price-table tbody td { padding: 0.85rem 1rem; font-size: 0.85rem; vertical-align: middle; }
.price-table tbody td:not(:first-child) { text-align: right; }
.pt-mat-cell { display: flex; align-items: center; gap: 0.65rem; }
.pt-color { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.pt-name { font-weight: 600; color: var(--text-1); font-size: 0.88rem; }
.pt-sub { font-size: 0.72rem; color: var(--text-3); margin-top: 0.05rem; }
.pt-price { font-family: var(--mono); font-weight: 700; color: var(--text-1); }
.pt-loc { color: var(--text-2); font-size: 0.8rem; }
.pt-time { color: var(--text-3); font-size: 0.75rem; }
.hide-mobile { }

/* ── CHAT WIDGET ─────────────────────────────────── */
.chat-launcher {
  position: fixed; right: 26px; bottom: 26px; width: 54px; height: 54px;
  border-radius: 50%; background: var(--orange); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer; box-shadow: var(--sh-lg); z-index: 100;
  border: none; transition: transform 0.15s;
}
.chat-launcher:hover { transform: translateY(-2px); }

/* Attention animation: shake, expand, settle back to normal — loops until the
   user clicks the launcher once, then it's dismissed for good (localStorage). */
.chat-launcher.attn { animation: chat-launcher-attn 3.2s ease-in-out infinite; animation-delay: 1.5s; }
@keyframes chat-launcher-attn {
  0%, 58%, 100% { transform: scale(1) rotate(0deg); }
  2%  { transform: scale(1) rotate(-12deg); }
  6%  { transform: scale(1) rotate(11deg); }
  10% { transform: scale(1) rotate(-9deg); }
  14% { transform: scale(1) rotate(7deg); }
  18% { transform: scale(1) rotate(-4deg); }
  22% { transform: scale(1) rotate(0deg); }
  34% { transform: scale(1.28) rotate(0deg); }
  46% { transform: scale(1.28) rotate(0deg); }
  58% { transform: scale(1) rotate(0deg); }
}

.chat-widget {
  position: fixed; right: 26px; bottom: 92px; width: 340px; max-width: calc(100vw - 52px); height: 440px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-lg); display: none; flex-direction: column; overflow: hidden; z-index: 100;
}
.chat-widget.open { display: flex; }
.chat-widget-hdr { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-widget-hdr span.title { font-size: 0.88rem; font-weight: 800; color: var(--text-1); }
.chat-widget-close { margin-left: auto; cursor: pointer; color: var(--text-3); font-size: 16px; background: none; border: none; }
.chat-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-tab-btn {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px; cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; color: var(--text-3);
}
.chat-tab-btn.active { border-bottom-color: var(--orange); color: var(--text-1); }
.chat-tab-btn .icon { font-size: 17px; }
.chat-tab-btn .lbl { font-size: 0.66rem; font-weight: 700; }
.chat-tab-badge {
  position: absolute; top: 5px; right: 22%; background: var(--orange); color: #fff;
  font-size: 0.6rem; font-weight: 800; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 88%; font-size: 0.8rem; line-height: 1.45; padding: 8px 10px; border-radius: 10px; background: var(--bg-surface); color: var(--text-1); }
.chat-msg.me { align-self: flex-end; background: var(--orange); color: #fff; }
.chat-composer { padding: 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-composer input {
  width: 100%; background: var(--bg-surface); border: 1px solid var(--border-2);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 0.8rem; color: var(--text-1); outline: none;
}

/* ── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar-toggle { display: flex; }
  .app-sidebar {
    position: fixed; top: var(--nav-h); left: 0; bottom: 0;
    transform: translateX(-100%); z-index: 300; box-shadow: none;
    width: var(--sidebar-w) !important;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  }
  .app-sidebar.mobile-open { transform: translateX(0); box-shadow: var(--sh-lg); }
  .app-sidebar .sidebar-rail-btn { display: none; }
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .app-content { padding: 1.1rem; }
  .app-topbar .search-input-wrap { max-width: 200px; }
  .topbar-page-title { display: none; }
}
@media (max-width: 600px) {
  .app-topbar { padding: 0 1rem; }
  .topbar-logo-text { display: none; }
  .app-topbar .search-input-wrap { max-width: 120px; }
  .metric-row { gap: 0.6rem; }
  .metric-card { padding: 0.85rem; }
  .filter-bar { overflow-x: auto; flex-wrap: nowrap; }
}
