/* ═══════════════════════════════════════════════
   KALPA — Dark LMS Theme
   Colors: #0d1117 bg, #161b22 surface, #21262d border
            #3fb950 green, #58a6ff blue, #f85149 red
   ═══════════════════════════════════════════════ */

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --text-muted:#8b949e;
  --green:     #3fb950;
  --blue:      #58a6ff;
  --red:       #f85149;
  --amber:     #d29922;
  --sidebar-w: 280px;
  --topbar-h:  56px;
  --radius:    6px;
  --mono:      'JetBrains Mono', monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ══════════════════════════════════
   LAYOUT
   ══════════════════════════════════ */
body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease;
  position: relative;
  z-index: 100;
}

.sidebar.collapsed {
  width: 48px;
  min-width: 48px;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .owner-tabs,
.sidebar.collapsed .signals-section,
.sidebar.collapsed .ai-section,
.sidebar.collapsed .options-panel,
.sidebar.collapsed .sidebar-footer span {
  display: none;
}

.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}

/* ══════════════════════════════════
   SIDEBAR INTERNALS
   ══════════════════════════════════ */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.logo-icon {
  color: var(--green);
  font-size: 18px;
  line-height: 1;
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.sidebar-toggle:hover { color: var(--text); border-color: var(--text-muted); }

/* Owner Tabs */
.owner-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.owner-tab {
  flex: 1;
  padding: 4px 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.owner-tab:hover { border-color: var(--blue); color: var(--blue); }

.owner-tab.active {
  background: rgba(88, 166, 255, 0.1);
  border-color: var(--blue);
  color: var(--blue);
}

/* Signals */
.signals-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 220px;
  overflow-y: auto;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.signal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.signal-dot.pulse {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.signal-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: default;
  transition: border-color 0.15s;
}

.signal-item:hover { border-color: var(--green); }

.signal-ticker {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--green);
}

.signal-action {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.signal-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

.signal-loading { font-size: 11px; color: var(--text-muted); }

/* AI Chat */
.ai-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  min-height: 0;
}

.ai-icon { font-size: 12px; }

.ai-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 0;
}

.ai-msg {
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.4;
  max-width: 100%;
  word-break: break-word;
}

.ai-msg.user {
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.2);
  color: var(--text);
  align-self: flex-end;
}

.ai-msg.assistant {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  align-self: flex-start;
}

.ai-msg.loading { color: var(--text-muted); font-style: italic; }

.ai-input-row {
  display: flex;
  gap: 6px;
}

.ai-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.ai-input:focus { border-color: var(--blue); }
.ai-input::placeholder { color: var(--text-muted); }

.ai-send {
  background: var(--blue);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.ai-send:hover { opacity: 0.85; }
.ai-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.options-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}

.options-toggle:hover { color: var(--text); }

.last-updated {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--mono);
}

/* Options Panel */
.options-panel {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.option-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
}

.option-row label { color: var(--text-muted); }

.option-row select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
}

.btn-options-save {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px;
  border-radius: var(--radius);
  font-size: 11px;
  cursor: pointer;
}

.btn-options-save:hover { border-color: var(--green); }

.hidden { display: none !important; }

/* ══════════════════════════════════
   TOPBAR
   ══════════════════════════════════ */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.page-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.owner-badge {
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.3);
  color: var(--blue);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

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

.btn-refresh {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: border-color 0.15s, color 0.15s;
}

.btn-refresh:hover { border-color: var(--green); color: var(--green); }

.refresh-icon.spinning {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════
   MAIN CONTENT SCROLL
   ══════════════════════════════════ */
.main > section {
  flex-shrink: 0;
}

.table-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 20px 20px;
  min-height: 0;
}

/* ══════════════════════════════════
   SUMMARY CARDS — ROW 1
   ══════════════════════════════════ */
.summary-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px 20px 0;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s;
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--border);
  transition: background 0.15s;
}

.summary-card:hover { border-color: var(--blue); }
.summary-card:hover::before { background: var(--blue); }
.summary-card.highlight::before { background: var(--green); }

.card-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.card-value {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.card-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ══════════════════════════════════
   ASSET CLASS CARDS — ROW 2
   ══════════════════════════════════ */
.asset-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 12px 20px;
}

.asset-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.asset-card:hover, .asset-card.active {
  border-color: var(--green);
  background: rgba(63, 185, 80, 0.05);
}

.asset-name {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.asset-value {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.asset-count {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ══════════════════════════════════
   TABLE
   ══════════════════════════════════ */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
}

.table-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.table-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  width: 180px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--blue); }
.search-input::placeholder { color: var(--text-muted); }

.filter-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.table-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.holdings-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.holdings-table th {
  background: var(--surface2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-align: left;
  padding: 9px 12px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.holdings-table th.num { text-align: right; }

.holdings-table th.sortable { cursor: pointer; }
.holdings-table th.sortable:hover { color: var(--text); }
.holdings-table th.sort-asc .sort-arrow::after { content: '↑'; }
.holdings-table th.sort-desc .sort-arrow::after { content: '↓'; }

.sort-arrow { opacity: 0.4; font-size: 10px; margin-left: 3px; }
.holdings-table th:hover .sort-arrow { opacity: 0.8; }

.holdings-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.5);
  white-space: nowrap;
  vertical-align: middle;
}

.holdings-table td.num { text-align: right; font-family: var(--mono); }

.holdings-table tbody tr {
  transition: background 0.1s;
}

.holdings-table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}

.holdings-table tbody tr:last-child td { border-bottom: none; }

.ticker-cell {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 12px;
  color: var(--blue);
}

.name-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.type-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.type-equity  { background: rgba(88, 166, 255, 0.1); color: var(--blue); }
.type-mf      { background: rgba(210, 153, 34, 0.1); color: var(--amber); }
.type-etf     { background: rgba(63, 185, 80, 0.1);  color: var(--green); }
.type-bond    { background: rgba(255,255,255,0.05);   color: var(--text-muted); }
.type-other   { background: rgba(255,255,255,0.05);   color: var(--text-muted); }

.pnl-pos { color: var(--green); }
.pnl-neg { color: var(--red); }
.pnl-zero{ color: var(--text-muted); }

.loading-row {
  text-align: center;
  color: var(--text-muted);
  padding: 40px !important;
  font-size: 13px;
}

.account-cell {
  font-size: 11px;
  color: var(--text-muted);
}

/* ══════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════ */
@media (max-width: 900px) {
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  .asset-row   { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .sidebar { position: fixed; left: -280px; transition: left 0.25s ease; }
  .sidebar.open { left: 0; }
  .mobile-menu { display: block; }
  .summary-row { grid-template-columns: 1fr 1fr; }
  .asset-row   { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0 14px; }
}
