* { box-sizing: border-box; }
:root {
  --bg: #f4f6fa; --card: #ffffff; --ink: #1a2332; --muted: #64748b;
  --line: #e2e8f0; --accent: #2563eb; --accent-ink: #ffffff;
  --pos: #047857; --neg: #dc2626; --head-bg: #0f172a; --head-ink: #e2e8f0;
}
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, Arial, sans-serif;
}
header {
  background: var(--head-bg); color: var(--head-ink);
  display: flex; align-items: center; gap: 18px; padding: 0 20px;
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.hdr-filters { margin-left: auto; display: flex; gap: 8px; align-items: center; padding: 8px 0; }
.hdr-filters select {
  background: #1e293b; color: #e2e8f0; border: 1px solid #334155; border-radius: 7px;
  padding: 7px 9px; font-size: 12.5px; max-width: 320px; cursor: pointer;
}
.hdr-filters select:hover { border-color: #475569; }
.brand { font-size: 17px; font-weight: 700; padding: 14px 0; white-space: nowrap; }
nav { display: flex; flex-wrap: wrap; }
nav a {
  color: #cbd5e1; text-decoration: none; padding: 16px 13px; font-size: 13.5px;
  border-bottom: 3px solid transparent;
}
nav a:hover { color: #fff; }
nav a.active { color: #fff; border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 1420px; margin: 0 auto; padding: 20px; }
h1 { font-size: 22px; margin: 6px 0 16px; }
h2 { font-size: 16px; margin: 26px 0 10px; }
footer { max-width: 1280px; margin: 30px auto; padding: 0 20px 30px; color: var(--muted); font-size: 12px; }

.filters {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 14px; align-items: end;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filters select, .filters input {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font-size: 13.5px;
  background: #fff; color: var(--ink); min-width: 130px;
}
.filters button, .btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block;
}
.filters button:hover, .btn:hover { filter: brightness(1.1); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  border-left: 4px solid #cbd5e1;
}
.card .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card .v { font-size: 21px; font-weight: 700; margin-top: 4px; }
.card .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Soft pastel card variants */
.card.cb { background: #eff6ff; border-color: #bfdbfe; border-left-color: #60a5fa; }
.card.cg { background: #f0fdf4; border-color: #bbf7d0; border-left-color: #4ade80; }
.card.cr { background: #fef2f2; border-color: #fecaca; border-left-color: #f87171; }
.card.ca { background: #fffbeb; border-color: #fde68a; border-left-color: #fbbf24; }
.card.cp { background: #faf5ff; border-color: #e9d5ff; border-left-color: #c084fc; }
.card.ct { background: #f0fdfa; border-color: #99f6e4; border-left-color: #2dd4bf; }
.card.cpk { background: #fdf2f8; border-color: #fbcfe8; border-left-color: #f472b6; }

.tablewrap {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  overflow: auto; max-height: 75vh; margin-bottom: 20px;
}
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  background: #eef2f7; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); position: sticky; top: 0; z-index: 5;
  box-shadow: 0 1px 0 var(--line);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #f8fafc; }
tfoot td {
  font-weight: 700; background: #f1f5f9;
  position: sticky; bottom: 0; z-index: 4;
  box-shadow: 0 -1px 0 var(--line);
}

/* Compact tables: fit many columns without horizontal scroll */
table.compact { font-size: 12px; }
table.compact th { white-space: normal; padding: 6px 7px; line-height: 1.3; }
table.compact td { padding: 5px 7px; }
table.compact td .small { font-size: 10.5px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.tag {
  display: inline-block; font-size: 11px; font-weight: 600; border-radius: 20px; padding: 2px 9px;
  background: #e0e7ff; color: #3730a3;
}
.tag.fno { background: #fef3c7; color: #92400e; }
.tag.intraday { background: #fce7f3; color: #9d174d; }
.tag.short_term { background: #dbeafe; color: #1e40af; }
.tag.long_term { background: #dcfce7; color: #166534; }
.tag.debt_etf { background: #f3e8ff; color: #6b21a8; }
.tag.non_equity_st { background: #ccfbf1; color: #115e59; }
.tag.buy { background: #dcfce7; color: #166534; }
.tag.sell { background: #fee2e2; color: #991b1b; }

.subnav { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid var(--line); }
.subnav a {
  padding: 9px 16px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.subnav a:hover { color: var(--ink); }
.subnav a.active { color: var(--accent); border-bottom-color: var(--accent); }

.chartbox { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 20px; }
.chartbox canvas { max-height: 320px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.notice { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px; }
.notice.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.notice.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
a { color: var(--accent); }
.small { font-size: 12px; }
.pager { margin: 10px 0 20px; display: flex; gap: 8px; align-items: center; }
.pager a { padding: 5px 11px; border: 1px solid var(--line); background: #fff; border-radius: 6px; text-decoration: none; }

/* Signed-in user chip in the header */
.hdr-user { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: #cbd5e1; padding: 8px 0; }
.hdr-user span { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-user a {
  color: #e2e8f0; text-decoration: none; border: 1px solid #334155; background: #1e293b;
  border-radius: 7px; padding: 6px 11px; font-weight: 600;
}
.hdr-user a:hover { background: #334155; }

/* Login page */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eef2ff 0%, #f4f6fa 45%, #ecfdf5 100%); padding: 20px;
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 26px; box-shadow: 0 16px 40px rgba(15, 23, 42, .10);
}
.login-brand { font-size: 22px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 13px; margin: 4px 0 20px; }
.login-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.login-input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 15px; background: #fff; color: var(--ink);
}
.login-input:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.login-otp { letter-spacing: 8px; text-align: center; font-size: 20px; font-weight: 700; }
.login-btn { width: 100%; margin-top: 14px; padding: 11px 16px; font-size: 14.5px; }
.login-hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; text-align: center; }
.login-actions { margin-top: 14px; text-align: center; font-size: 13px; display: flex; gap: 8px; justify-content: center; align-items: center; }
.linkbtn { background: none; border: 0; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; }
.linkbtn:hover { text-decoration: underline; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }

/* Quick date-range chips (.filters prefix needed to beat the `.filters button` rule) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; padding-top: 10px; border-top: 1px dashed var(--line); margin-top: 6px; }
.chips-label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.filters .chip, .chip {
  background: #f8fafc; color: #334155; border: 1px solid var(--line); border-radius: 20px;
  padding: 3px 11px; font-size: 12px; font-weight: 600; cursor: pointer; line-height: 1.5;
}
.filters .chip:hover, .chip:hover { background: #e0e7ff; border-color: #c7d2fe; color: #3730a3; filter: none; }
.filters .chip-month, .chip-month { background: #f0fdf4; color: #166534; border-color: #d1fae5; }
.filters .chip-month:hover, .chip-month:hover { background: #dcfce7; border-color: #86efac; color: #166534; }
.filters .chip-clear, .chip-clear { background: #fff; color: var(--muted); }
.filters .chip-clear:hover, .chip-clear:hover { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

/* Zerodha-style date range picker */
.drp { position: relative; }
.drp-trigger {
  min-width: 215px; text-align: left; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; font-size: 13.5px; color: var(--ink); cursor: pointer;
}
.drp-trigger::after { content: " ▾"; color: var(--muted); float: right; }
.drp-trigger:hover { border-color: #94a3b8; }
.drp-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .2); padding: 12px; width: 580px;
}
.drp-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.drp-cals { display: flex; gap: 16px; margin-top: 4px; }
.drp-cal { flex: 1; min-width: 0; }
.drp-head {
  background: var(--accent); color: #fff; text-align: center; border-radius: 7px;
  padding: 5px 0; font-weight: 700; font-size: 13px; margin-bottom: 6px;
}
.drp-nav { display: flex; align-items: center; gap: 2px; margin-bottom: 4px; }
.drp-nav span { flex: 1; text-align: center; font-weight: 600; font-size: 13px; }
.drp-nav button {
  border: 0; background: transparent; cursor: pointer; font-size: 15px;
  padding: 1px 7px; color: var(--muted); border-radius: 5px; line-height: 1.4;
}
.drp-nav button:hover { background: #eef2f7; color: var(--ink); }
.drp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.drp-grid .dn { font-size: 10.5px; color: var(--muted); text-align: center; font-weight: 700; padding: 3px 0; }
.drp-grid .d {
  border: 0; background: transparent; font-size: 12px; padding: 5px 0;
  border-radius: 6px; cursor: pointer; text-align: center; color: var(--ink);
}
.drp-grid .d:hover { background: #dbe3ff; }
.drp-grid .d.out { color: #cbd5e1; }
.drp-grid .d.inr { background: #eff6ff; }
.drp-grid .d.sel { background: var(--accent); color: #fff; font-weight: 700; }
@media (max-width: 700px) {
  .drp-panel { width: 92vw; }
  .drp-cals { flex-direction: column; }
}

/* Charges breakdown modal */
.charges-link { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }
.charges-link:hover { color: var(--accent); }
.card .v .charges-link { text-decoration-color: var(--muted); }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card); border-radius: 12px; width: 100%; max-width: 440px;
  max-height: 85vh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: #f8fafc;
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close {
  border: 0; background: transparent; font-size: 24px; line-height: 1;
  cursor: pointer; color: var(--muted); padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
.modal-body { overflow: auto; padding: 6px 0; }
.modal-body table { width: 100%; }
.modal-body td { padding: 8px 18px; border-bottom: 1px solid var(--line); }
.modal-body tr:last-child td { border-bottom: 0; }
.modal-body tr.zero td { color: var(--muted); }
.modal-body tr.total td { font-weight: 700; background: #f1f5f9; }
