/* =========================
   Base, variables & helpers
   ========================= */
:root{
  /* Brand */
  --brand-primary:#0056b3;
  --brand-primary-hover:#004494;
  --brand-primary-border:#003e86;

  --brand-green-bg:#DDF4E7;
  --brand-green-border:#67C090;
  --brand-green-text:#1e4620;

  /* Light (default) surface + text */
  --page-bg:#f7f8fc;
  --page-fg:#1a2433;
  --muted:#6b7890;

  --card-bg:#ffffff;
  --card-shadow:0 .125rem .5rem rgba(0,0,0,.05);
  --surface-muted:#f0f3fa;
  --surface-elevated:#ffffff;

  --border:#e3e8f3;
  --emphasis-border:#0f172a;

  /* Tables */
  --table-alt:#eef2fb;
  --table-hover:#e0e7f6;
  --table-header-bg:#edf1fb;
  --table-header-fg:var(--page-fg);
  --table-surface:var(--card-bg);
  --match-highlight-bg:#fff3cd;
  --match-highlight-border:#f0ad4e;
  --match-highlight-text:#2c1f00;
  --register-zebra-bg:#f0f2f6;

  /* Inputs & overlays */
  --input-bg:#ffffff;
  --input-border:#d7deea;
  --input-shadow:0 14px 35px rgba(15,23,42,.08);
  --floating-shadow:0 8px 20px rgba(15,23,42,.12);

  /* Sidebar + cards */
  --form-card-gradient-start:#f8fafc;
  --form-card-gradient-end:#ffffff;
  --table-card-gradient-start:#fdfdff;
  --table-card-gradient-end:#f5f7fb;
  --sidebar-gradient-start:#f8f9fb;
  --sidebar-gradient-mid:#ffffff;
  --sidebar-gradient-end:#f2f5ff;
  --sidebar-pill-bg:rgba(255,255,255,.75);
  --sidebar-pill-border:rgba(15,23,42,.08);
  --sidebar-pill-shadow:0 8px 18px rgba(15,23,42,.06);
  --sidebar-pill-active-bg:rgba(0,86,179,.12);
  --sidebar-pill-active-shadow:0 12px 28px rgba(0,86,179,.18);
  --sidebar-link-hover-bg:rgba(0,86,179,.08);
  --sidebar-link-active-bg:rgba(0,86,179,.12);
  --pending-row-bg:#e9f0ff;
  --pending-row-text:#0f172a;
  --pending-row-border:#93c5fd;

  --warn-pill-bg:#fff4d6;
  --warn-pill-border:#facc6b;
  --warn-pill-text:#7a4b00;

  /* Legacy shadows */
  --shadow-sm:0 2px 8px rgba(0,0,0,.03);
  --shadow-card:0 .125rem .5rem rgba(0,0,0,.05);
}

body{
  font-family:"Inter",sans-serif;
  background:var(--page-bg);
  color:var(--page-fg);
}
h2{font-weight:600;color:var(--page-fg);} 
h4{font-weight:600;}
.page-title{font-size:1.8rem;margin-bottom:1.5rem;font-weight:600;}
.bold{font-weight:700;}

button,input,select,.form-control,.form-select{transition:all .2s ease-in-out;}

/* ===============
   Layout & cards
   =============== */
.container{max-width:1080px;}
.container-account{max-width:1250px;margin:0 auto;}
.main-content{position:relative;padding:1.5rem;}

.sidebar-toggle{
  position:fixed;
  top:50%;
  left:16px;
  transform:translateY(-50%);
  z-index:1100;
  width:2.25rem;
  height:2.25rem;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--card-bg);
  color:var(--page-fg);
  box-shadow:var(--floating-shadow);
  cursor:pointer;
  transition:box-shadow .2s ease,background-color .2s ease,color .2s ease;
  padding:0;
}
.sidebar-toggle:hover{
  box-shadow:0 12px 28px rgba(15,23,42,.18);
  background:var(--surface-muted);
}
.sidebar-toggle .bi{font-size:1.1rem;}

html.sidebar-collapsed #sidebar,
html.sidebar-collapsed #drag-handle{
  display:none !important;
}

html.sidebar-collapsed .main-content{
  padding-left:3.75rem;
}

@media (max-width:768px){
  html.sidebar-collapsed .main-content{
    padding-left:3.5rem;
  }
}

.form-section{
  background:var(--card-bg);padding:2rem;border-radius:1rem;box-shadow:var(--card-shadow);margin-bottom:2rem;
}

.card-summary{margin-bottom:1.5rem;}
.card{border-radius:.75rem;box-shadow:var(--card-shadow);background:var(--card-bg);} 

/* =============
   Buttons
   ============= */
.btn-primary{
  background-color:var(--brand-primary);
  border-color:var(--brand-primary);
}
.btn-primary:hover{
  background-color:var(--brand-primary-hover);
  border-color:var(--brand-primary-border);
}

.btn-account{
  background-color:var(--brand-green-bg);
  border:1px solid var(--brand-green-border);
  color:var(--brand-green-text);
  font-weight:500;
}
.btn-account:hover{
  background-color:#d2f4d1;
  border-color:#2e7d32;
}
.btn-account.active{border:2px solid var(--emphasis-border);} 

.btn-soft-yellow{
  background:var(--warn-pill-bg) !important;
  color:var(--warn-pill-text) !important;
  border:1px solid var(--warn-pill-border) !important;
}
.btn.plaid-merge-btn{
  background-color:#ffe7c2;
  border-color:#ffc78d;
  color:#7a4b00;
}
.btn.plaid-merge-btn:hover{
  background-color:#ffd8a4;
  border-color:#ffb86a;
  color:#5a3600;
}
.btn-secondary{min-width:140px;}
.btn-sm{margin-right:4px;}
.btn-outline-secondary{white-space:nowrap;}

/* =============
   Forms
   ============= */
.form-label{font-weight:600;}

td input.form-control,
td select.form-select{padding:2px 6px;height:auto;font-size:.9rem;}

.modern-form-card{
  background:linear-gradient(135deg,var(--form-card-gradient-start) 0%,var(--form-card-gradient-end) 100%);
}
.modern-form-card .card-body{
  padding:2rem;
}
.modern-form-card .modern-floating{
  border-radius:1rem;
  background:var(--input-bg);
  border:1px solid var(--input-border);
  box-shadow:var(--input-shadow);
  transition:transform .2s ease,box-shadow .2s ease,border-color .2s ease;
}
.modern-form-card .modern-floating label{
  font-size:.85rem;
  font-weight:500;
  color:var(--muted);
}
.modern-form-card .modern-floating label span{
  font-weight:600;
  color:var(--page-fg);
}
.form-control,
.form-select,
.form-control:disabled,
.form-select:disabled{
  background-color:var(--input-bg);
  color:var(--page-fg);
  border-color:var(--input-border);
}
.form-control-plaintext{ color:var(--page-fg) !important; }
.form-select option,
.form-select optgroup{ color:var(--page-fg); background-color:var(--card-bg); }
.strategy-metric-list dt,
.strategy-metric-list dd{
  color:var(--page-fg);
}
.form-control::placeholder{ color:var(--muted); opacity:1; }
.modern-form-card .modern-input,
.modern-form-card .modern-select{
  border:0;
  border-radius:1rem;
  background:transparent;
  padding:1.1rem 1.15rem .5rem;
  font-weight:500;
  color:var(--page-fg);
  height:auto;
  min-height:3.5rem;
  box-shadow:none;
}
.modern-form-card .modern-select{
  padding-right:2.75rem;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%230056b3' d='M6 9 1 4h10z'/%3E%3C/svg%3E");
  background-repeat:no-repeat;
  background-position:right 1.25rem center;
  background-size:12px 12px;
  appearance:none;
}
.modern-form-card .modern-input:focus,
.modern-form-card .modern-select:focus{
  box-shadow:none;
}
.modern-form-card .modern-floating:focus-within{
  border-color:var(--brand-primary);
  box-shadow:0 18px 45px rgba(0,86,179,.18);
  transform:translateY(-2px);
}
.modern-form-card .modern-input::-webkit-input-placeholder{color:transparent;}
.modern-form-card .modern-input:-ms-input-placeholder{color:transparent;}
.modern-form-card .modern-input::placeholder{color:transparent;}
.modern-form-card .modern-submit{
  border-radius:999px;
  font-weight:600;
  box-shadow:0 12px 24px rgba(0,86,179,.25);
}
.modern-form-card .modern-submit:hover{
  box-shadow:0 16px 32px rgba(0,86,179,.3);
}

.btn-responsive{
  width:100%;
}
@media (min-width:576px){
  .btn-responsive{
    width:auto;
  }
}

.modern-sidebar{
  width:260px;
  min-width:220px;
  background:linear-gradient(145deg,var(--sidebar-gradient-start) 0%,var(--sidebar-gradient-mid) 60%,var(--sidebar-gradient-end) 100%);
  border-radius:1.5rem;
  padding:1.75rem 1.5rem;
  display:flex;
  flex-direction:column;
  gap:1.75rem;
}
.modern-sidebar .sidebar-brand .text-sidebar-emphasis{
  color:var(--page-fg);
  letter-spacing:.02em;
}
.modern-sidebar .sidebar-section{
  display:flex;
  flex-direction:column;
  gap:.1rem;
}
.modern-sidebar .sidebar-section-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:.5rem;
}
.modern-sidebar .sidebar-subtitle{
  font-size:.75rem;
  font-weight:600;
  letter-spacing:.12em;
  text-transform:uppercase;
  color:var(--muted);
}
.modern-sidebar .btn-xs{
  padding:.35rem .85rem;
  font-size:.75rem;
}
.modern-sidebar .sidebar-list{
  display:flex;
  flex-direction:column;
  gap:.5rem;
}
.modern-sidebar .sidebar-pill{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:.15rem;
  padding:.3rem .4rem;
  border-radius:.85rem;
  background:var(--sidebar-pill-bg);
  border:1px solid var(--sidebar-pill-border);
  text-decoration:none;
  color:var(--page-fg);
  transition:all .2s ease-in-out;
  box-shadow:var(--sidebar-pill-shadow);
}
.modern-sidebar .sidebar-pill:hover{
  transform:translateY(-2px);
  border-color:var(--brand-primary);
  box-shadow:0 12px 26px rgba(0,86,179,.12);
}
.modern-sidebar .sidebar-pill.active{
  border-width:2px;
  border-color:var(--brand-primary);
  box-shadow:var(--sidebar-pill-active-shadow);
  background:var(--sidebar-pill-active-bg);
}
.modern-sidebar .sidebar-pill-warning{
  background:var(--sidebar-pill-bg);
  border-color:var(--sidebar-pill-border);
  color:var(--page-fg);
}
.modern-sidebar .sidebar-pill-label{
  display:flex;
  align-items:center;
  gap:.35rem;
  font-weight:500;
  font-size:.9rem;
  min-width:0;
  flex:1;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.modern-sidebar .sidebar-pill-balance{
  font-weight:600;
  font-size:.85rem;
  font-variant-numeric:tabular-nums;
}
.modern-sidebar .sidebar-pill-badge{
  width:8px;
  height:8px;
  border-radius:999px;
  background:linear-gradient(135deg,#facc15,#fb923c);
  display:inline-block;
}
.modern-sidebar .sidebar-nav{
  display:flex;
  flex-direction:column;
  gap:.2rem;
}
.modern-sidebar .sidebar-nav-nested{
  display:flex;
  flex-direction:column;
  gap:.15rem;
  margin-left:.35rem;
  padding-left:.35rem;
  border-left:1px solid rgba(15,23,42,.08);
}
.modern-sidebar .sidebar-link{
  border-radius:.75rem;
  padding:.45rem .65rem;
  font-size:.9rem;
  color:var(--muted);
  text-decoration:none;
  transition:all .2s ease-in-out;
}
.modern-sidebar .sidebar-link-toggle{
  width:100%;
  background:none;
  border:0;
  text-align:left;
  cursor:pointer;
}
.modern-sidebar .sidebar-link-toggle:focus{
  outline:none;
  box-shadow:0 0 0 2px rgba(0,86,179,.15);
}
.modern-sidebar .sidebar-link-toggle .toggle-icon{
  transition:transform .2s ease;
}
.modern-sidebar .sidebar-link-toggle[aria-expanded="true"] .toggle-icon{
  transform:rotate(180deg);
}
.modern-sidebar .sidebar-link-nested{
  padding-left:1.35rem;
  font-size:.85rem;
}
.modern-sidebar .sidebar-link:hover{
  color:var(--brand-primary);
  background:var(--sidebar-link-hover-bg);
}
.modern-sidebar .sidebar-link.active{
  color:var(--brand-primary);
  background:var(--sidebar-link-active-bg);
  font-weight:600;
}
.modern-sidebar .sidebar-footer .btn{
  padding:.6rem 1rem;
  border-radius:.85rem;
}

.modern-table-card{
  border-radius:1.25rem;
  background:linear-gradient(140deg,var(--table-card-gradient-start) 0%,var(--table-card-gradient-end) 100%);
}
.modern-table-card .card-header h5{
  font-size:1rem;
  letter-spacing:.04em;
}
.modern-table-card .badge{
  letter-spacing:.08em;
}
.modern-table{
  border-collapse:separate;
  border-spacing:0;
}
.modern-table thead th{
  border-bottom:0;
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:.75rem;
  font-weight:600;
  color:var(--muted);
  padding:0.75rem 0.75rem;
  background:transparent;
}
.modern-table tbody td{
  border-top:1px solid rgba(15,23,42,.05);
  padding:1rem 0.75rem;
  color:var(--page-fg);
}
.modern-table tbody tr:hover td{
  background:rgba(0,86,179,.04);
}
.modern-table tbody tr:first-child td{
  border-top:0;
}
.modern-table-card .card-footer{
  border-top:1px solid rgba(15,23,42,.07);
}

.large-input{width:140px;padding:4px 6px;}   /* e.g., date */
.medium-input{width:100px;}                   /* e.g., debit/credit */
.narrow-select{width:100px;}

input[type="number"].percent-input{
  width:80px;padding:.25rem .5rem;text-align:right;
}

.category-comment{font-size:.75rem;resize:vertical;color:red;}

/* Number input spin removal */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0;}
input[type=number]{-moz-appearance:textfield;}

.assign-form .assign-control{
  max-width:200px;
  margin:0 auto;
  gap:0.25rem;
}

.assign-form .assign-control .form-control{
  min-width:90px;
  font-variant-numeric:tabular-nums;
}

/* Date input – plain look in rows */
tr.txn-row input[type="date"]{
  appearance:none;-webkit-appearance:none;-moz-appearance:none;
  background:transparent !important;border:0 !important;box-shadow:none !important;
  position:relative;z-index:1;padding:0;margin:0;width:100%;
}
tr.txn-row input[type="date"]::-webkit-inner-spin-button,
tr.txn-row input[type="date"]::-webkit-calendar-picker-indicator{display:none;-webkit-appearance:none;}
tr.txn-row input[type="date"]::-moz-focus-inner{border:0;}

/* Read vs edit states */
tr.txn-row input,
tr.txn-row select:disabled{
  border:none !important;background:transparent !important;box-shadow:none !important;
  padding:0;margin:0;font-size:inherit;color:inherit;width:100%;pointer-events:auto;
}
tr.txn-row.editable input{
  pointer-events:auto;border:1px solid var(--border) !important;background:var(--card-bg) !important;
  padding:2px 6px;border-radius:4px;color:var(--page-fg);
}
tr.txn-row.editable input[type="date"],
tr.txn-row.editable input[type="number"]{min-width:80px;}

tr.txn-row select:disabled{
  appearance:none;-webkit-appearance:none;-moz-appearance:none;
  background-image:none !important;pointer-events:none;
}

/* =============
   Tables
   ============= */
table.table{
  border-radius:.5rem;overflow:hidden;box-shadow:0 2px 6px rgb(0 0 0 / .1);
  background:var(--table-surface);
}
.table thead th{background:var(--table-header-bg) !important;color:var(--table-header-fg) !important;font-weight:600;}
.table th,.table td{vertical-align:middle;text-align:center;font-size:.9rem;}
.table tbody tr:hover{background:var(--table-hover);transition:background-color .2s ease-in-out;}

tfoot th{font-size:1rem;font-weight:700;background:var(--table-alt);} 

.zebra-stripe{background:var(--register-zebra-bg) !important;} /* generic alt row */
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td{color:var(--page-fg) !important;}
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td input,
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td select,
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td textarea,
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td .form-control,
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td .form-control-plaintext,
.table.table-bordered tbody tr.zebra-stripe:not(.match-group):not(.match-single) > td .form-select{color:var(--page-fg) !important;}

html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td{color:var(--page-fg) !important;}
html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td input,
html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td select,
html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td textarea,
html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td .form-control,
html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td .form-control-plaintext,
html[data-theme="dark"] .table.table-bordered tbody tr.zebra-stripe > td .form-select{color:var(--page-fg) !important;}

table.table tbody tr.history-row:nth-child(odd):not(.pending-row){
  background:var(--table-alt) !important;
}

/* Striping for pending rows in light mode */
.pending-row,
.pending-row > td{
  background-color:var(--pending-row-bg) !important;
  color:var(--pending-row-text, var(--page-fg)) !important;
}
.pending-row input,
.pending-row .form-control,
.pending-row .form-select{
  color:var(--pending-row-text, var(--page-fg)) !important;
}
.pending-row > td:first-child{border-left:2px solid var(--pending-row-border, transparent) !important;}
.pending-row > td:last-child{border-right:2px solid var(--pending-row-border, transparent) !important;}

.pending-import-badge{
  background-color:var(--pending-row-border, #93c5fd) !important;
  color:var(--pending-row-text, var(--page-fg)) !important;
  border:1px solid var(--pending-row-border, #93c5fd);
}

.table-warning,
.table-warning > th,
.table-warning > td{
  background-color:var(--pending-row-bg) !important;
  color:var(--pending-row-text, var(--page-fg)) !important;
  border-color:var(--pending-row-border, var(--pending-row-bg)) !important;
}

/* Fixed layout register table + inner controls respect width */
.register-table{table-layout:fixed;}
.register-table th,.register-table td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.register-table .form-control,
.register-table .form-select{
  width:100%;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}

/* Plaid Imports: allow wrapping and show full buttons in Actions col */
#tx-table td:nth-child(7){
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
}
#tx-table td:nth-child(7) .btn{
  font-size: .8rem;            /* slightly smaller text */
  line-height: 1.1;
  padding: .2rem .45rem;       /* slightly tighter padding */
  margin-bottom: .2rem;        /* space when wrapping to new line */
}

html[data-theme="dark"] .list-group-item{
  background-color:var(--surface-muted) !important;
  color:var(--page-fg) !important;
  border-color:var(--border) !important;
}
html[data-theme="dark"] .list-group-item .text-muted{
  color:var(--muted) !important;
}
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .list-group-item{
    background-color:var(--surface-muted) !important;
    color:var(--page-fg) !important;
    border-color:var(--border) !important;
  }
  html:not([data-theme]) .list-group-item .text-muted{
    color:var(--muted) !important;
  }
}

/* Italic utility for rows */
.italic-row, .italic-row input, .italic-row select, .italic-row textarea{font-style:italic !important;}

/* Matched transactions highlight */
.table.table-bordered tbody tr.match-group > td,
.table.table-bordered tbody tr.match-single > td{
  background:var(--match-highlight-bg) !important;
  color:var(--match-highlight-text) !important;
  position:relative;
}
.table.table-bordered tbody tr.match-group.match-top > td,
.table.table-bordered tbody tr.match-single > td{
  border-top:1px solid var(--match-highlight-border) !important;
}
.table.table-bordered tbody tr.match-group.match-bottom > td,
.table.table-bordered tbody tr.match-single > td{
  border-bottom:1px solid var(--match-highlight-border) !important;
}
.table.table-bordered tbody tr.match-group > td:first-child::before,
.table.table-bordered tbody tr.match-single > td:first-child::before{
  content:"";
  position:absolute;
  top:0;
  bottom:0;
  left:0;
  width:4px;
  background:var(--match-highlight-border);
  border-radius:0;
}
.table.table-bordered tbody tr.match-group.match-top > td:first-child::before,
.table.table-bordered tbody tr.match-single > td:first-child::before{border-top-left-radius:6px;}
.table.table-bordered tbody tr.match-group.match-bottom > td:first-child::before,
.table.table-bordered tbody tr.match-single > td:first-child::before{border-bottom-left-radius:6px;}
.table.table-bordered tbody tr.match-group > td:last-child::after,
.table.table-bordered tbody tr.match-single > td:last-child::after{
  content:"";
  position:absolute;
  top:0;
  bottom:0;
  right:0;
  width:4px;
  background:var(--match-highlight-border);
  border-radius:0;
}
.table.table-bordered tbody tr.match-group.match-top > td:last-child::after,
.table.table-bordered tbody tr.match-single > td:last-child::after{border-top-right-radius:6px;}
.table.table-bordered tbody tr.match-group.match-bottom > td:last-child::after,
.table.table-bordered tbody tr.match-single > td:last-child::after{border-bottom-right-radius:6px;}
.table.table-bordered tbody tr.match-group.match-top > td:first-child,
.table.table-bordered tbody tr.match-single > td:first-child{border-top-left-radius:10px;}
.table.table-bordered tbody tr.match-group.match-top > td:last-child,
.table.table-bordered tbody tr.match-single > td:last-child{border-top-right-radius:10px;}
.table.table-bordered tbody tr.match-group.match-bottom > td:first-child,
.table.table-bordered tbody tr.match-single > td:first-child{border-bottom-left-radius:10px;}
.table.table-bordered tbody tr.match-group.match-bottom > td:last-child,
.table.table-bordered tbody tr.match-single > td:last-child{border-bottom-right-radius:10px;}
.table.table-bordered tbody tr.match-group > td input,
.table.table-bordered tbody tr.match-group > td select,
.table.table-bordered tbody tr.match-group > td textarea,
.table.table-bordered tbody tr.match-group > td .form-control-plaintext,
.table.table-bordered tbody tr.match-group > td .form-control,
.table.table-bordered tbody tr.match-group > td .form-select,
.table.table-bordered tbody tr.match-single > td input,
.table.table-bordered tbody tr.match-single > td select,
.table.table-bordered tbody tr.match-single > td textarea,
.table.table-bordered tbody tr.match-single > td .form-control-plaintext,
.table.table-bordered tbody tr.match-single > td .form-control,
.table.table-bordered tbody tr.match-single > td .form-select{
  color:var(--match-highlight-text) !important;
}

/* =============
   Alerts
   ============= */
.small-alert{
  padding:.25rem 2rem .25rem .75rem;font-size:.85rem;line-height:1.2;margin-bottom:.25rem;position:relative;
}
.small-alert .btn-close{
  position:absolute;top:.25rem;right:.5rem;padding:.25rem;font-size:.75rem;
}
.flash-message-space{height:2rem;position:relative;}
.flash-container{top:.25rem;z-index:1050;}
.hover-popup{
  position:absolute;background:var(--card-bg);border:1px solid var(--border);padding:8px;
  box-shadow:0 2px 10px rgba(0,0,0,.15);display:none;font-size:.9rem;z-index:1000;border-radius:6px;
}

/* =============
   Utilities
   ============= */
.negative{color:red;}
.text-success{color:#198754 !important;font-weight:600;}
.text-danger{color:#dc3545 !important;font-weight:600;}

/* Compact button utility for tight layouts */
.btn-compact{ padding:.1rem .35rem; line-height:1; font-size:.8rem; }

/* Portfolio Quotes: align colors with index table */
#portfolio-body .text-success{ color: green !important; }
#portfolio-body .text-danger{  color: red   !important; }


/* =============
   Special boxes
   ============= */
.recurring-box,
.income-summary{
  background:var(--brand-green-bg);
  border-left:6px solid var(--brand-green-border);
  border-radius:.5rem;box-shadow:0 1px 3px rgba(0,0,0,.1);
}
.recurring-box{padding:.5rem 1rem;}
.income-summary{padding:.5rem .5rem;font-size:1.1rem;font-weight:700;}

/* =============
   Misc
   ============= */
.alias-list strong{display:inline-block;min-width:150px;}
#portfolio-balance{max-width:300px;font-weight:500;}
#save-btn{min-width:160px;}

/* Grab handle (sidebar resize) */
#drag-handle,.resize-handle{
  flex:0 0 5px;cursor:col-resize;background:var(--border);align-self:stretch;position:relative;z-index:10;
}
.nw-noselect,.nw-noselect *{user-select:none !important;}

.recovery-code-panel{
  background:var(--surface-muted);
  border:1px solid var(--border);
  border-radius:1rem;
  box-shadow:var(--card-shadow);
  color:var(--page-fg);
}
.recovery-code-grid{
  display:grid;
  gap:1rem;
  grid-template-columns:repeat(auto-fit,minmax(160px,1fr));
}
.recovery-code-item{
  background:var(--card-bg);
  border:1px solid var(--border);
  border-radius:.85rem;
  padding:.75rem;
  text-align:center;
  font-weight:600;
  letter-spacing:.15em;
  color:var(--page-fg);
}
.recovery-code-item code{
  display:block;
  color:inherit;
  font-size:1.1rem;
}


/* =========================
   Dark theme palette & overrides
   ========================= */
:root[data-theme="light"]{
  color-scheme: light;
}

:root[data-theme="dark"]{
  color-scheme: dark;
  --page-bg:#050c1a;
  --page-fg:#e2e8f0;
  --muted:#94a3b8;
  --card-bg:#101b2b;
  --card-shadow:0 20px 45px rgba(2,6,23,.65);
  --surface-muted:#111a2c;
  --surface-elevated:#18253a;
  --border:rgba(148,163,184,.35);
  --emphasis-border:#7dd3fc;

  --table-alt:rgba(148,163,184,.08);
  --table-hover:rgba(148,163,184,.18);
  --table-header-bg:#172640;
  --table-header-fg:#e2e8f0;
  --table-surface:#0f172a;
  --match-highlight-bg:rgba(94,234,212,.2);
  --match-highlight-border:rgba(94,234,212,.45);
  --match-highlight-text:#e2e8f0;
  --register-zebra-bg:#1a2538;

  --brand-primary:#7dd3fc;
  --brand-primary-hover:#60a5fa;
  --brand-primary-border:#3b82f6;

  --brand-green-bg:rgba(20,83,45,.35);
  --brand-green-border:rgba(16,185,129,.55);
  --brand-green-text:#34d399;

  --input-bg:#0b1220;
  --input-border:rgba(148,163,184,.35);
  --input-shadow:0 20px 40px rgba(2,6,23,.65);
  --floating-shadow:0 12px 32px rgba(2,6,23,.7);

  --form-card-gradient-start:#0f172a;
  --form-card-gradient-end:#111d2f;
  --table-card-gradient-start:#0c1423;
  --table-card-gradient-end:#090f1a;

  --sidebar-gradient-start:#060e1b;
  --sidebar-gradient-mid:#0f1f33;
  --sidebar-gradient-end:#13253c;
  --sidebar-pill-bg:rgba(15,23,42,.65);
  --sidebar-pill-border:rgba(148,163,184,.25);
  --sidebar-pill-shadow:0 12px 28px rgba(0,0,0,.5);
  --sidebar-pill-active-bg:rgba(59,130,246,.2);
  --sidebar-pill-active-shadow:0 16px 34px rgba(2,6,23,.65);
  --sidebar-link-hover-bg:rgba(59,130,246,.18);
  --sidebar-link-active-bg:rgba(59,130,246,.22);

  --warn-pill-bg:rgba(250,204,21,.18);
  --warn-pill-border:rgba(251,191,36,.55);
  --warn-pill-text:#fde68a;
  --pending-row-bg:rgba(15,118,110,.35);
  --pending-row-text:#e2e8f0;
  --pending-row-border:rgba(45,212,191,.45);

  --bs-body-color:var(--page-fg);
  --bs-heading-color:var(--page-fg);
  --bs-card-color:var(--page-fg);
  --bs-card-title-color:var(--page-fg);
  --bs-secondary-color:var(--muted);
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme]){
    color-scheme: dark;
    --page-bg:#050c1a;
    --page-fg:#e2e8f0;
    --muted:#94a3b8;
    --card-bg:#101b2b;
    --card-shadow:0 20px 45px rgba(2,6,23,.65);
    --surface-muted:#111a2c;
    --surface-elevated:#18253a;
    --border:rgba(148,163,184,.35);
    --emphasis-border:#7dd3fc;

    --table-alt:rgba(148,163,184,.08);
    --table-hover:rgba(148,163,184,.18);
    --table-header-bg:#172640;
    --table-header-fg:#e2e8f0;
    --table-surface:#0f172a;
    --match-highlight-bg:rgba(94,234,212,.2);
    --match-highlight-border:rgba(94,234,212,.45);
    --match-highlight-text:#e2e8f0;
    --register-zebra-bg:#1a2538;

    --brand-primary:#7dd3fc;
    --brand-primary-hover:#60a5fa;
    --brand-primary-border:#3b82f6;

    --brand-green-bg:rgba(20,83,45,.35);
    --brand-green-border:rgba(16,185,129,.55);
    --brand-green-text:#34d399;

    --input-bg:#0b1220;
    --input-border:rgba(148,163,184,.35);
    --input-shadow:0 20px 40px rgba(2,6,23,.65);
    --floating-shadow:0 12px 32px rgba(2,6,23,.7);

    --form-card-gradient-start:#0f172a;
    --form-card-gradient-end:#111d2f;
    --table-card-gradient-start:#0c1423;
    --table-card-gradient-end:#090f1a;

    --sidebar-gradient-start:#060e1b;
    --sidebar-gradient-mid:#0f1f33;
    --sidebar-gradient-end:#13253c;
    --sidebar-pill-bg:rgba(15,23,42,.65);
    --sidebar-pill-border:rgba(148,163,184,.25);
    --sidebar-pill-shadow:0 12px 28px rgba(0,0,0,.5);
    --sidebar-pill-active-bg:rgba(59,130,246,.2);
    --sidebar-pill-active-shadow:0 16px 34px rgba(2,6,23,.65);
    --sidebar-link-hover-bg:rgba(59,130,246,.18);
    --sidebar-link-active-bg:rgba(59,130,246,.22);

    --warn-pill-bg:rgba(250,204,21,.18);
    --warn-pill-border:rgba(251,191,36,.55);
    --warn-pill-text:#fde68a;
    --pending-row-bg:rgba(15,118,110,.35);
    --pending-row-text:#e2e8f0;
    --pending-row-border:rgba(45,212,191,.45);

    --bs-body-color:var(--page-fg);
    --bs-heading-color:var(--page-fg);
    --bs-card-color:var(--page-fg);
    --bs-card-title-color:var(--page-fg);
    --bs-secondary-color:var(--muted);
  }

  :root:not([data-theme]) .pending-row,
  :root:not([data-theme]) .pending-row > td{
    background-color:var(--pending-row-bg) !important;
    color:var(--pending-row-text) !important;
  }
  :root:not([data-theme]) .pending-row input,
  :root:not([data-theme]) .pending-row .form-control,
  :root:not([data-theme]) .pending-row .form-select{
    color:var(--pending-row-text) !important;
  }
}

/* Sticky header helper used inline in templates */
.thead-sticky th{ background:var(--table-header-bg) !important; }

/* Projected budget inline style compatibility */
.table thead th { background:var(--table-header-bg) !important; }

/* Context menu (inline element) */
#context-menu{ background:var(--card-bg) !important; border-color:var(--border) !important; }

/* Shared dark-surface overrides */
html[data-theme="dark"] .card,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .bg-white,
html[data-theme="dark"] .bg-light,
html[data-theme="dark"] .table-light{
  background-color:var(--card-bg) !important;
  color:var(--page-fg) !important;
  border-color:var(--border) !important;
}
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .card,
  html:not([data-theme]) .dropdown-menu,
  html:not([data-theme]) .modal-content,
  html:not([data-theme]) .bg-white,
  html:not([data-theme]) .bg-light,
  html:not([data-theme]) .table-light{
    background-color:var(--card-bg) !important;
    color:var(--page-fg) !important;
    border-color:var(--border) !important;
  }
}

html[data-theme="dark"] .text-muted{ color:var(--muted) !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .text-muted{ color:var(--muted) !important; }
}

html[data-theme="dark"] .table,
html[data-theme="dark"] .table-bordered{
  background-color:var(--table-surface) !important;
  --bs-table-bg:var(--table-surface);
  --bs-table-striped-bg:var(--table-alt);
  --bs-table-hover-bg:var(--table-hover);
  --bs-table-color:var(--page-fg);
  --bs-table-striped-color:var(--page-fg);
  --bs-table-hover-color:var(--page-fg);
  border-color:var(--border) !important;
}
html[data-theme="dark"] .table thead,
html[data-theme="dark"] .table thead th{
  background-color:var(--table-header-bg) !important;
  color:var(--table-header-fg) !important;
}
html[data-theme="dark"] .table tbody tr:hover{ background-color:var(--table-hover) !important; }
html[data-theme="dark"] .table-secondary{ background-color:#1f2a3f !important; color:var(--page-fg) !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .table,
  html:not([data-theme]) .table-bordered{
    background-color:var(--table-surface) !important;
    --bs-table-bg:var(--table-surface);
    --bs-table-striped-bg:var(--table-alt);
    --bs-table-hover-bg:var(--table-hover);
    --bs-table-color:var(--page-fg);
    --bs-table-striped-color:var(--page-fg);
    --bs-table-hover-color:var(--page-fg);
    border-color:var(--border) !important;
  }
  html:not([data-theme]) .table thead,
  html:not([data-theme]) .table thead th{
    background-color:var(--table-header-bg) !important;
    color:var(--table-header-fg) !important;
  }
  html:not([data-theme]) .table tbody tr:hover{ background-color:var(--table-hover) !important; }
  html:not([data-theme]) .table-secondary{ background-color:#1f2a3f !important; color:var(--page-fg) !important; }
}

html[data-theme="dark"] .progress{ --bs-progress-bg:var(--surface-muted); }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .progress{ --bs-progress-bg:var(--surface-muted); }
}

html[data-theme="dark"] .btn-outline-secondary{
  color:var(--page-fg);
  border-color:var(--border);
}
html[data-theme="dark"] .btn-outline-secondary:hover{
  background:var(--surface-muted);
  border-color:var(--brand-primary-border);
  color:var(--page-fg);
}
html[data-theme="dark"] .btn-outline-primary{
  color:var(--brand-primary);
  border-color:var(--brand-primary-border);
}
html[data-theme="dark"] .btn-outline-primary:hover{
  background:rgba(96,165,250,.16);
  border-color:var(--brand-primary-hover);
  color:var(--page-fg);
}
html[data-theme="dark"] .btn.plaid-merge-btn{
  background-color:rgba(59,130,246,.25);
  border-color:#60a5fa;
  color:var(--page-fg);
}
html[data-theme="dark"] .btn.plaid-merge-btn:hover{
  background-color:rgba(59,130,246,.4);
  border-color:#93c5fd;
  color:var(--page-fg);
}
html[data-theme="dark"] .btn-warning{
  background:linear-gradient(135deg,#1f3261,#233b75);
  border-color:#3b5ccc;
  color:#eff6ff;
  box-shadow:0 8px 20px rgba(37,99,235,.35);
}
html[data-theme="dark"] .btn-warning:hover{
  background:linear-gradient(135deg,#21386b,#264280);
  border-color:#5f7fff;
  color:#ffffff;
}
html[data-theme="dark"] .btn-soft-yellow,
html[data-theme="dark"] .btn-account.btn-soft-yellow{
  background-color:rgba(59,130,246,.22) !important;
  border-color:#60a5fa !important;
  color:var(--page-fg) !important;
}
html[data-theme="dark"] .btn-primary{
  color:#ffffff !important;
}
html[data-theme="dark"] #importBtn.btn-primary{
  color:#000000 !important;
}
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .btn-outline-secondary{
    color:var(--page-fg);
    border-color:var(--border);
  }
  html:not([data-theme]) .btn-outline-secondary:hover{
    background:var(--surface-muted);
    border-color:var(--brand-primary-border);
    color:var(--page-fg);
  }
  html:not([data-theme]) .btn-outline-primary{
    color:var(--brand-primary);
    border-color:var(--brand-primary-border);
  }
  html:not([data-theme]) .btn-outline-primary:hover{
    background:rgba(96,165,250,.16);
    border-color:var(--brand-primary-hover);
    color:var(--page-fg);
  }
  html:not([data-theme]) .btn.plaid-merge-btn{
    background-color:rgba(59,130,246,.25);
    border-color:#60a5fa;
    color:var(--page-fg);
  }
  html:not([data-theme]) .btn.plaid-merge-btn:hover{
    background-color:rgba(59,130,246,.4);
    border-color:#93c5fd;
    color:var(--page-fg);
  }
  html:not([data-theme]) .btn-warning{
    background:linear-gradient(135deg,#1f3261,#233b75);
    border-color:#3b5ccc;
    color:#eff6ff;
    box-shadow:0 8px 20px rgba(37,99,235,.35);
  }
  html:not([data-theme]) .btn-warning:hover{
    background:linear-gradient(135deg,#21386b,#264280);
    border-color:#5f7fff;
    color:#ffffff;
  }
  html:not([data-theme]) .btn-soft-yellow,
  html:not([data-theme]) .btn-account.btn-soft-yellow{
    background-color:rgba(59,130,246,.22) !important;
    border-color:#60a5fa !important;
    color:var(--page-fg) !important;
  }
}

html[data-theme="dark"] a{ color:var(--brand-primary); }
html[data-theme="dark"] a:hover{ color:var(--brand-primary-hover); }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) a{ color:var(--brand-primary); }
  html:not([data-theme]) a:hover{ color:var(--brand-primary-hover); }
}

html[data-theme="dark"] input.cleared-toggle{
  accent-color:var(--brand-primary);
}
@media (prefers-color-scheme: dark){
  html:not([data-theme]) input.cleared-toggle{
    accent-color:var(--brand-primary);
  }
}

html[data-theme="dark"] .table td.available-cell[style*="color: green"]{ color:#34d399 !important; }
html[data-theme="dark"] .table td.available-cell[style*="color: red"]{ color:#f87171 !important; }
html[data-theme="dark"] .table td.available-cell[style*="color: black"]{ color:var(--page-fg) !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .table td.available-cell[style*="color: green"]{ color:#34d399 !important; }
  html:not([data-theme]) .table td.available-cell[style*="color: red"]{ color:#f87171 !important; }
  html:not([data-theme]) .table td.available-cell[style*="color: black"]{ color:var(--page-fg) !important; }
}
html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus{
  background-color:var(--input-bg);
  color:var(--page-fg);
}

html[data-theme="dark"] #portfolio-body .text-success{ color:#34d399 !important; }
html[data-theme="dark"] #portfolio-body .text-danger{ color:#f87171 !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) #portfolio-body .text-success{ color:#34d399 !important; }
  html:not([data-theme]) #portfolio-body .text-danger{ color:#f87171 !important; }
}

html[data-theme="dark"] .index-page input[type="date"],
html[data-theme="dark"] .index-page .form-control[type="date"]{ color:var(--page-fg) !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .index-page input[type="date"],
  html:not([data-theme]) .index-page .form-control[type="date"]{ color:var(--page-fg) !important; }
}

html[data-theme="dark"] .index-page .card-header,
html[data-theme="dark"] .index-page .card-title,
html[data-theme="dark"] .index-page .form-label,
html[data-theme="dark"] .index-page label,
html[data-theme="dark"] .index-page .card-body strong,
html[data-theme="dark"] .index-page h5,
html[data-theme="dark"] .index-page h6{ color:var(--page-fg) !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .index-page .card-header,
  html:not([data-theme]) .index-page .card-title,
  html:not([data-theme]) .index-page .form-label,
  html:not([data-theme]) .index-page label,
  html:not([data-theme]) .index-page .card-body strong,
  html:not([data-theme]) .index-page h5,
  html:not([data-theme]) .index-page h6{ color:var(--page-fg) !important; }
}

html[data-theme="dark"] .index-page .recurring-box{ color:var(--brand-green-text) !important; }
html[data-theme="dark"] .index-page .recurring-box strong{ color:var(--page-fg) !important; }
@media (prefers-color-scheme: dark){
  html:not([data-theme]) .index-page .recurring-box{ color:var(--brand-green-text) !important; }
  html:not([data-theme]) .index-page .recurring-box strong{ color:var(--page-fg) !important; }
}
