:root{
    --bg:#0b1020;
    --card:#121a33;
    --muted:#9aa6c1;
    --text:#e9eeff;
    --border:rgba(255,255,255,.10);
    --good:#2ce5a7;
    --bad:#ff5b6e;
    --warn:#ffd166;
  }

  *{ box-sizing:border-box; }
  body{
    margin:0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    background: radial-gradient(1200px 700px at 20% 10%, rgba(44,229,167,.18), transparent 55%),
                radial-gradient(900px 600px at 90% 20%, rgba(255,209,102,.14), transparent 50%),
                radial-gradient(900px 700px at 40% 90%, rgba(120,100,255,.14), transparent 55%),
                var(--bg);
    color:var(--text);
    line-height:1.35;
  }

  header{
    padding:28px 16px 14px;
    max-width:1100px;
    margin:0 auto;
  }
  header h1{ margin:0; font-size:22px; letter-spacing:.2px; }
  header p{ margin:6px 0 0; color:var(--muted); font-size:13px; }

  .wrap{
    max-width:1100px;
    margin:0 auto;
    padding:12px 16px 36px;
    display:grid;
    gap:14px;
    grid-template-columns: 1fr;
  }

  @media(min-width: 980px){
    .wrap{ grid-template-columns: 380px 1fr; align-items:start; }
  }

  .card{
    background: color-mix(in oklab, var(--card), black 8%);
    border:1px solid var(--border);
    border-radius:16px;
    box-shadow: 0 18px 40px rgba(0,0,0,.30);
    overflow:hidden;
  }

  .card .hd{
    padding:14px 14px 10px;
    border-bottom: 1px solid var(--border);
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
  }

  .card .hd h2{
    font-size:14px;
    margin:0;
    color: color-mix(in oklab, var(--text), white 10%);
    letter-spacing:.25px;
  }

  .card .bd{ padding:14px; }

  .grid{
    display:grid;
    gap:10px;
    grid-template-columns: 1fr;
  }

  .row2{ grid-template-columns: 1fr 1fr; }
  .row3{ grid-template-columns: 1fr 1fr 1fr; }

  label{ display:block; font-size:12px; color:var(--muted); margin-bottom:6px; }
  input, select, button, textarea{
    width:100%;
    font: inherit;
    color: var(--text);
    background: rgba(255,255,255,.06);
    border:1px solid var(--border);
    border-radius:12px;
    padding:10px 10px;
    outline:none;
  }
  textarea{ min-height: 40px; resize: vertical; }
  input::placeholder, textarea::placeholder{ color: rgba(233,238,255,.40); }
  input:focus, select:focus, textarea:focus{ border-color: rgba(44,229,167,.60); box-shadow: 0 0 0 3px rgba(44,229,167,.12); }

  .btn{
    cursor:pointer;
    background: linear-gradient(135deg, rgba(44,229,167,.95), rgba(44,229,167,.55));
    border: 1px solid rgba(44,229,167,.65);
    color:#06141e;
    font-weight:700;
  }

  .btn.secondary{
    background: rgba(255,255,255,.06);
    border:1px solid var(--border);
    color: var(--text);
    font-weight:600;
  }

  .btn.danger{
    background: linear-gradient(135deg, rgba(255,91,110,.95), rgba(255,91,110,.60));
    border: 1px solid rgba(255,91,110,.70);
    color:#1a0608;
    font-weight:800;
  }

  .kpis{
    display:grid;
    gap:10px;
    grid-template-columns: 1fr 1fr;
  }
  .kpi{
    background: rgba(255,255,255,.05);
    border:1px solid var(--border);
    border-radius:14px;
    padding:12px;
  }
  .kpi .t{ font-size:12px; color:var(--muted); }
  .kpi .v{ font-size:18px; font-weight:800; margin-top:6px; letter-spacing:.2px; }
  .kpi .s{ font-size:12px; color:var(--muted); margin-top:4px; }

  .pill{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:6px 10px;
    border-radius:999px;
    background: rgba(255,255,255,.06);
    border:1px solid var(--border);
    color: var(--muted);
    font-size:12px;
    white-space:nowrap;
  }

  .good{ color: var(--good); }
  .bad{ color: var(--bad); }
  .warn{ color: var(--warn); }

  table{ width:100%; border-collapse:collapse; }
  th, td{ padding:10px 10px; border-bottom:1px solid var(--border); vertical-align:top; }
  th{ text-align:left; font-size:12px; color:var(--muted); font-weight:700; }
  td{ font-size:13px; }

  .actions{ display:flex; gap:8px; justify-content:flex-end; }
  .smallbtn{
    width:auto;
    padding:7px 10px;
    border-radius:10px;
    font-size:12px;
  }

  .topbar{
    display:flex;
    flex-wrap:wrap;
    gap:8px;
    align-items:center;
    justify-content:space-between;
  }

  .note{ font-size:12px; color: var(--muted); }

  .progress{
    height:10px;
    background: rgba(255,255,255,.06);
    border:1px solid var(--border);
    border-radius:999px;
    overflow:hidden;
  }
  .progress > div{
    height:100%;
    width:0;
    background: linear-gradient(90deg, rgba(255,209,102,.92), rgba(44,229,167,.92));
  }

  .footerBtns{ display:flex; gap:10px; flex-wrap:wrap; }

  .mono{ font-variant-numeric: tabular-nums; }

  /* Modal Styles */
  .modal{
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
  }

  .modal.active{ display: flex; }

  .modal-overlay{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.75);
    backdrop-filter: blur(4px);
  }

  .modal-content{
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,.50);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease-out;
  }

  @keyframes modalSlideIn{
    from{
      opacity: 0;
      transform: translateY(-20px) scale(0.95);
    }
    to{
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  .modal-header{
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .modal-header h3{
    margin: 0;
    font-size: 16px;
    color: var(--text);
    letter-spacing: 0.3px;
  }

  .modal-close{
    width: auto;
    padding: 4px 12px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    background: rgba(255,255,255,.06);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    transition: all 0.2s;
  }

  .modal-close:hover{
    background: rgba(255,91,110,.15);
    border-color: rgba(255,91,110,.40);
    color: var(--bad);
  }

  .modal-body{
    padding: 20px;
    overflow-y: auto;
    flex: 1;
  }

  .modal-item{
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: all 0.2s;
  }

  .modal-item:hover{
    background: rgba(255,255,255,.06);
    border-color: rgba(255,255,255,.15);
  }

  .modal-item-header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
  }

  .modal-item-name{
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
  }

  .modal-item-amount{
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.2px;
  }

  .modal-item-type{
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  .modal-item-type.expense{
    background: rgba(255,91,110,.15);
    color: var(--bad);
  }

  .modal-item-type.sale{
    background: rgba(44,229,167,.15);
    color: var(--good);
  }

  .modal-item-type.capital{
    background: rgba(255,209,102,.15);
    color: var(--warn);
  }

  .modal-item-desc{
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
  }

  .modal-item-actions{
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
  }

  .modal-summary{
    margin-top: 20px;
    padding-top: 16px;
    border-top: 2px solid var(--border);
  }

  .summary-row{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 13px;
  }

  .summary-row.total{
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 15px;
    font-weight: 700;
  }

  /* Clickable date styling */
  .clickable-date{
    cursor: pointer;
    color: rgba(44,229,167,.85);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    transition: all 0.2s;
  }

  .clickable-date:hover{
    color: var(--good);
    text-decoration-style: solid;
  }

  /* Warning Banner Styles */
  .warning-banner{
    background: linear-gradient(135deg, rgba(255,209,102,.20), rgba(255,91,110,.15));
    border: 1px solid rgba(255,209,102,.50);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    animation: warningPulse 2s ease-in-out infinite;
  }

  @keyframes warningPulse{
    0%, 100%{ opacity: 1; }
    50%{ opacity: 0.85; }
  }

  .warning-icon{
    font-size: 18px;
    animation: warningShake 0.5s ease-in-out infinite;
  }

  @keyframes warningShake{
    0%, 100%{ transform: rotate(0deg); }
    25%{ transform: rotate(-5deg); }
    75%{ transform: rotate(5deg); }
  }

  /* Runway Display Styles */
  .runway-display{
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .runway-label{
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
  }

  .runway-value{
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
  }

  /* Batch Guidance Styles */
  .info-icon{
    display: inline-block;
    font-size: 14px;
    color: rgba(44,229,167,.70);
    cursor: help;
    margin-left: 4px;
    transition: all 0.2s;
  }

  .info-icon:hover{
    color: var(--good);
    transform: scale(1.1);
  }

  .batch-helper-text{
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(44,229,167,.08);
    border: 1px solid rgba(44,229,167,.25);
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
  }

  .batch-helper-text strong{
    color: var(--good);
    font-weight: 700;
  }

  .batch-reminder{
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(255,209,102,.10);
    border: 1px solid rgba(255,209,102,.35);
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
    display: flex;
    align-items: flex-start;
    gap: 6px;
    animation: reminderFadeIn 0.3s ease-out;
  }

  @keyframes reminderFadeIn{
    from{
      opacity: 0;
      transform: translateY(-5px);
    }
    to{
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* ============================================ */
  /* Fix for dropdown option readability         */
  /* ============================================ */
  /* Problem: On Windows/Chrome/Edge, native dropdown options use light backgrounds
     while select text uses light colors, making options unreadable until hover.
     
     Solution: Use color-scheme to hint browsers to use dark native controls,
     and force option colors as fallback for better cross-browser support. */

  select {
    color-scheme: dark;
  }

  select option {
    background-color: var(--card);
    color: var(--text);
  }

  /* ============================================ */
  /* Category Breakdown - Overflow Fix           */
  /* ============================================ */
  /* Limit category cell width and apply ellipsis for long category names */
  
  /* Force fixed table layout for Category Breakdown to ensure ellipsis works */
  #categoryBreakdown table {
    table-layout: fixed;
    width: 100%;
  }
  
  /* Set specific width for category column */
  #categoryBreakdown th:first-child,
  #categoryBreakdown td:first-child {
    width: 220px;
  }
  
  /* Apply ellipsis styling to category cells */
  .category-cell {
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ============================================ */
  /* App Navigation Bar                           */
  /* ============================================ */
  .appnav {
    position: sticky;
    top: 0;
    z-index: 999;
    background: rgba(11, 16, 32, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  }

  .appnav-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
  }

  .appnav-brand {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.3px;
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s ease;
    white-space: nowrap;
  }

  .appnav-brand:hover {
    color: var(--good);
  }

  .appnav-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .appnav-link {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
  }

  .appnav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(44, 229, 167, 0.35);
    color: var(--text);
    transform: translateY(-1px);
  }

  .appnav-link.active {
    background: linear-gradient(135deg, rgba(44, 229, 167, 0.18), rgba(44, 229, 167, 0.08));
    border: 1px solid rgba(44, 229, 167, 0.45);
    color: var(--good);
    box-shadow: 0 0 0 3px rgba(44, 229, 167, 0.08);
    font-weight: 700;
  }

  .appnav-link.active:hover {
    transform: none;
    background: linear-gradient(135deg, rgba(44, 229, 167, 0.22), rgba(44, 229, 167, 0.12));
  }

  /* Mobile optimization for nav */
  @media (max-width: 640px) {
    .appnav-inner {
      padding: 10px 12px;
      gap: 12px;
    }

    .appnav-brand {
      font-size: 13px;
    }

    .appnav-links {
      width: 100%;
      justify-content: center;
    }

    .appnav-link {
      flex: 1;
      justify-content: center;
      min-width: 0;
      padding: 8px 10px;
      font-size: 12px;
    }
  }
