:root {
  --brand: #1a73c7;
  --brand-dark: #0f4c81;
  --brand-light: #e8f2fb;
  --bg: #eef0f4;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-muted: #6b7280;
  --border: #e2e5ea;
  --green: #17a673;
  --red: #d9464c;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 40px;
}

.login-brand .mark {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.5px;
  color: var(--brand-dark);
}

.login-brand .pill {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
  padding: 6px 14px;
  border-radius: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 24px;
  color: var(--text);
}

.field {
  position: relative;
  margin-bottom: 14px;
}

.field input {
  width: 100%;
  padding: 13px 40px 13px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: var(--brand); }

.field .icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9aa1ac;
  pointer-events: none;
  font-size: 15px;
}

.login-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.login-btn:hover { background: var(--brand-dark); }
.login-btn:disabled { background: #c7cdd6; cursor: not-allowed; }

.login-links {
  margin-top: 14px;
  font-size: 13px;
}

.login-error {
  color: var(--red);
  font-size: 13px;
  margin: -4px 0 12px;
  min-height: 16px;
}

.login-footnote {
  position: fixed;
  bottom: 20px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- App shell ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand .mark { font-weight: 700; font-size: 16px; color: var(--brand-dark); }
.sidebar-brand .pill {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 14px;
}

.nav-list { list-style: none; margin: 0; padding: 0; flex: 1; }

.nav-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.nav-item a:hover { background: var(--brand-light); color: var(--brand-dark); }

.nav-item.active a {
  color: var(--brand-dark);
  background: var(--brand-light);
  border-left-color: var(--brand);
}

.sidebar-footer {
  padding: 14px 20px 0;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.topbar h2 { font-size: 17px; margin: 0; font-weight: 600; }

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

.as-of { font-size: 12px; color: var(--text-muted); }

.entity-filter-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand-dark);
  background: var(--brand-light);
  outline: none;
  max-width: 220px;
}
.entity-filter-select:focus { border-color: var(--brand); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.user-chip .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.logout-link { font-size: 12px; color: var(--text-muted); }

.content {
  padding: 26px 28px 40px;
  overflow-y: auto;
}

.sample-banner {
  background: #fff7e6;
  border: 1px solid #f2d38c;
  color: #8a6210;
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 20px;
}

/* ---------- Summary cards ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.stat-sub {
  font-size: 12.5px;
  margin-top: 6px;
  font-weight: 600;
}

.up { color: var(--green); }
.down { color: var(--red); }

/* ---------- Panels ---------- */
.panel-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.panel h3 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel h3 .muted { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 14px;
  font-size: 12.5px;
}

.legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid #f0f1f4;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

.fund-name {
  font-weight: 600;
  color: var(--text);
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fund-name-clickable { cursor: pointer; }
.fund-name-clickable:hover { color: var(--brand); text-decoration: underline; }
.fund-cat { font-size: 11.5px; color: var(--text-muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.tag.buy { background: #eaf7f0; color: #0e7d52; }
.tag.sell { background: #fdecec; color: #b03236; }
.tag.dividend { background: #f4ecfb; color: #6b3fa0; }
.tag.kyc { background: #f4ecfb; color: #6b3fa0; }
.tag.statement { background: #e8f2fb; color: var(--brand-dark); }
.tag.tax { background: #fdecec; color: #b03236; }
.tag.contract { background: #fdf3e3; color: #9a6a10; }
.tag.pdf { background: #fdf3e3; color: #9a6a10; }
.tag.excel { background: #eaf7f0; color: #0e7d52; }
.tag.image { background: #f4ecfb; color: #6b3fa0; }

.row-delete-btn {
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: #9aa1ac;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.row-delete-btn:hover {
  background: #fdecec;
  color: var(--red);
  border-color: #f2c6c8;
}

.row-delete-btn.armed {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  font-weight: 600;
}

.row-edit-btn {
  min-width: 26px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.row-edit-btn:hover { background: var(--brand-light); color: var(--brand-dark); border-color: var(--brand); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }

.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: #f5f6f8; }

.btn-danger { background: #fff; color: var(--red); border-color: #f2c6c8; }
.btn-danger:hover:not(:disabled) { background: #fdecec; }
.btn-danger.armed { background: var(--red); color: #fff; border-color: var(--red); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Upload dropdown ---------- */
.upload-wrap { position: relative; display: inline-block; }

.upload-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 220px;
  padding: 6px;
}

/* A dropdown whose button sits in a right-aligned toolbar (toolbar-right)
   needs to open anchored to its own right edge, not left:0 — otherwise it
   opens past the button toward the right and can run off the viewport
   entirely, like the Tax Report Export menu did. */
.toolbar-right .upload-menu { left: auto; right: 0; }

.upload-menu-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.upload-menu-item:hover { background: var(--brand-light); }
.upload-menu-item .muted { font-size: 11.5px; font-weight: 400; color: var(--text-muted); }

/* ---------- Table toolbar ---------- */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.period-toolbar {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.period-label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }

.select-all-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

/* ---------- Scrip Master: category tree ---------- */
.empty-note {
  font-size: 13px;
  color: var(--text-muted);
}

.cat-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cat-tree .cat-tree {
  margin: 8px 0 0;
  padding-left: 22px;
  border-left: 2px solid var(--border);
}

.cat-node { margin-bottom: 8px; }

.cat-node-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.cat-add-sub-btn {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 5px 10px;
  cursor: pointer;
}
.cat-add-sub-btn:hover { color: var(--brand); border-color: var(--brand); }

.cat-inline-add {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.cat-inline-input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  width: 220px;
}
.cat-inline-input:focus { border-color: var(--brand); outline: none; }

.pill-delete-btn {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.pill-delete-btn:hover { background: rgba(0, 0, 0, 0.18); }
.pill-delete-btn.armed { background: var(--red); color: #fff; }

.period-toolbar select,
.period-toolbar input[type="date"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
}
.period-toolbar select:focus,
.period-toolbar input[type="date"]:focus { border-color: var(--brand); }

.period-sep { font-size: 12.5px; color: var(--text-muted); }

.selection-count { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Holdings: category-wise drill-down tree ----------
   Styled after a typical wealth-management "grouped register" grid (dense,
   plain black bold category rows, blue-link fund names, right-aligned figures,
   green/red for gain/loss with no leading "+" on positive values) rather than
   the colored-pill look used elsewhere in this app (Scrip Master, flat table). */
.view-toggle { display: flex; gap: 6px; }
.view-toggle .btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.holdings-tree { list-style: none; margin: 0; padding: 0; min-width: 920px; }

.holdings-tree-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 70px 100px 90px 90px 120px 130px 130px 100px;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid #eef0f3;
  font-size: 12.5px;
  min-width: 920px;
}
.holdings-tree-row .num { text-align: right; font-variant-numeric: tabular-nums; }

.holdings-tree-header {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: #f7f8fa;
  border-bottom: 1px solid var(--border);
  padding: 9px 12px;
}

.holdings-tree-cat-row {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  background: #fff;
}
.holdings-tree-cat-row:hover { background: #f5f7fa; }

.holdings-tree-toggle {
  display: inline-block;
  width: 12px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
  color: var(--brand);
  font-size: 9px;
}
.holdings-tree-cat-row.expanded .holdings-tree-toggle { transform: rotate(90deg); }

.holdings-tree-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.holdings-tree-cat-name { color: var(--text); }

.holdings-tree-fund-row {
  font-size: 12.5px;
  font-weight: 400;
  cursor: pointer;
}
.holdings-tree-fund-row:hover { background: #f9fafb; }
.holdings-tree-fund-row .holdings-tree-name { color: var(--brand); }
.holdings-tree-fund-row .holdings-tree-name:hover { text-decoration: underline; }

.holdings-tree-row .up { color: var(--green); }
.holdings-tree-row .down { color: var(--red); }
.holdings-tree-row .muted-cell { color: var(--text-muted); }

.holdings-tree-children { display: none; }
.holdings-tree-children.open { display: block; }

#holdingsBody tr { cursor: pointer; }
#holdingsBody tr:hover { background: #f9fafb; }

.tx-message {
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
}
.tx-message.ok { background: #eaf7f0; color: #0e7d52; border: 1px solid #bfe6d2; }
.tx-message.err { background: #fdecec; color: #b03236; border: 1px solid #f2c6c8; }

.checkbox-col { width: 34px; }
input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--brand); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.25);
  width: 100%;
  max-width: 420px;
  padding: 24px 26px;
}

.modal h3 { margin: 0 0 18px; font-size: 16px; font-weight: 700; }

.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.form-row input, .form-row select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  background: #fff;
}
.form-row input:focus, .form-row select:focus { border-color: var(--brand); }

.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: -8px; margin-bottom: 14px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Reports / Documents list ---------- */
.report-list { list-style: none; margin: 0; padding: 0; }
.report-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid #f0f1f4;
  font-size: 13.5px;
}
.report-list li:last-child { border-bottom: none; }
.report-list .rlist-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.report-list .rname { font-weight: 500; }
.report-list .rname .tag { margin-right: 8px; vertical-align: middle; }
.report-list .rmeta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .sidebar { display: none; }
  .summary-grid { grid-template-columns: 1fr; }
}
