* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; color: #333; line-height: 1.5; }
a { color: #2563eb; }

.container { max-width: 900px; margin: 0 auto; padding: 16px; }
header { background: #1e293b; color: #fff; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; left: 0; right: 0; z-index: 10; width: 100%; }
header h1 { font-size: 1.1rem; font-weight: 600; }
header nav { display: flex; gap: 12px; align-items: center; font-size: 0.85rem; }
header nav a { color: #94a3b8; text-decoration: none; }
header nav a:hover, header nav a.active { color: #fff; }
header nav #user-name { color: #94a3b8; font-size: 0.8rem; cursor: default; padding-left: 12px; margin-left: 4px; border-left: 1px solid #475569; }
#logout-btn { background: none; border: 1px solid #475569; color: #94a3b8; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; width: auto; }
#nav-toggle { display: none; background: none; border: 1px solid #475569; color: #fff; font-size: 1.2rem; line-height: 1; padding: 4px 10px; border-radius: 4px; cursor: pointer; width: auto; }

.card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 20px; margin-bottom: 16px; }
h2 { font-size: 1.15rem; margin-bottom: 12px; color: #1e293b; }
h3 { font-size: 0.95rem; margin: 12px 0 8px; color: #475569; }

/* Login */
.login-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.login-box { width: 100%; max-width: 360px; padding: 24px; }
.login-box h1 { text-align: center; margin-bottom: 24px; font-size: 1.5rem; }
input[type="text"], input[type="password"], select { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.95rem; margin-bottom: 12px; }
.btn { display: inline-block; padding: 10px 20px; background: #2563eb; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 0.95rem; text-align: center; width: 100%; }
.btn:hover { background: #1d4ed8; }
.btn:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; width: auto; }
.btn-green { background: #16a34a; }
.btn-green:hover { background: #15803d; }
.btn-outline { background: none; border: 1px solid #d1d5db; color: #333; }
.btn-outline:hover { background: #f1f5f9; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.error { color: #dc2626; font-size: 0.85rem; margin-bottom: 8px; }

/* Upload drop zone */
.dropzone { border: 2px dashed #cbd5e1; border-radius: 8px; padding: 40px 20px; text-align: center; cursor: pointer; transition: border-color 0.2s, background 0.2s; }
.dropzone.dragover { border-color: #2563eb; background: #eff6ff; }
.dropzone p { color: #64748b; margin-bottom: 8px; }
.dropzone .hint { font-size: 0.8rem; color: #94a3b8; }
.file-list { margin-top: 12px; }
.file-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #f8fafc; border-radius: 4px; margin-bottom: 4px; font-size: 0.85rem; }
.file-item .type-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; background: #e2e8f0; color: #475569; }
.file-item .type-badge.receipt_photo { background: #dbeafe; color: #1e40af; }
.file-item .type-badge.bank_csv { background: #dcfce7; color: #166534; }
.file-item .type-badge.ibkr_tax_zip { background: #fef3c7; color: #92400e; }
.file-item .type-badge.ibkr_activity { background: #fce7f3; color: #9d174d; }
.file-item .type-badge.receipt_zip { background: #ede9fe; color: #6b21a8; }
.upload-meta { display: flex; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.upload-meta label { font-size: 0.85rem; color: #475569; }
.upload-meta select { width: auto; margin-bottom: 0; }

/* Results */
.result-item { padding: 10px; border-left: 3px solid #2563eb; background: #f8fafc; margin-bottom: 8px; border-radius: 0 4px 4px 0; font-size: 0.85rem; }
.result-item.error { border-left-color: #dc2626; }

/* Expenses table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.expenses-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.expenses-table th { text-align: left; padding: 8px; border-bottom: 2px solid #e2e8f0; color: #475569; font-weight: 600; vertical-align: top; }
.expenses-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.expenses-table tr:hover { background: #f8fafc; }
.expenses-table th.sortable { cursor: pointer; user-select: none; }
.expenses-table th.sortable:hover { color: #1e293b; }
.expenses-table th.sortable.active { color: #1e293b; }
.expenses-table td.col-date { white-space: nowrap; }
.expenses-table td.col-amount { white-space: nowrap; }
.expenses-table th.col-actions, .expenses-table td.col-actions { text-align: right; }
.expenses-table .person-chip { display: inline-block; font-size: 0.7rem; color: #64748b; background: #f1f5f9; padding: 1px 8px; border-radius: 10px; text-transform: capitalize; }
.action-group { display: inline-flex; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }
.action-group .btn { white-space: nowrap; }
.status-badge { display: inline-block; font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; font-weight: 500; white-space: nowrap; }
.status-badge.pending_review { background: #fef3c7; color: #92400e; }
.status-badge.confirmed { background: #dcfce7; color: #166534; }
.status-badge.flagged { background: #fee2e2; color: #991b1b; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { margin-bottom: 0; width: auto; font-size: 0.85rem; padding: 6px 10px; }
.filter-active { background: #fef3c7; color: #92400e; padding: 6px 12px; border-radius: 6px; font-size: 0.8rem; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-summary { color: #64748b; font-size: 0.78rem; margin-bottom: 8px; }
.btn-link { background: none; border: none; color: #2563eb; text-decoration: underline; cursor: pointer; padding: 0; font-size: inherit; width: auto; }
.btn-link:hover { color: #1d4ed8; background: none; }
.ellipsis-1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.ellipsis-1.expanded { white-space: normal; overflow: visible; }
.ellipsis-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.ellipsis-2.expanded { -webkit-line-clamp: unset; overflow: visible; }
.col-desc .vendor { font-size: 0.85rem; }
.col-desc .items { color: #64748b; margin-top: 2px; }
.expenses-table td.col-amount .amount-value { display: block; }
.expenses-table td.col-amount .ded-chip { display: inline-block; margin-top: 4px; }
.ded-chip { display: inline-block; font-size: 0.7rem; padding: 1px 8px; border-radius: 10px; font-weight: 500; vertical-align: middle; white-space: nowrap; }
.ded-chip[data-notes] { cursor: pointer; }
.ded-chip.show-notes { white-space: normal; }
.ded-chip.show-notes::after { content: ': ' attr(data-notes); margin-left: 4px; font-weight: normal; }
.ded-chip.ded-yes { background: #dcfce7; color: #166534; }
.ded-chip.ded-no { background: #fee2e2; color: #991b1b; }
.ded-chip.ded-maybe { background: #fef3c7; color: #92400e; }

/* Report */
.report-section { margin-bottom: 24px; }
.report-section h3 { border-bottom: 1px solid #e2e8f0; padding-bottom: 4px; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.summary-card { background: #f8fafc; padding: 12px; border-radius: 6px; text-align: center; }
.summary-card .value { font-size: 1.3rem; font-weight: 700; color: #1e293b; }
.summary-card .label { font-size: 0.75rem; color: #64748b; margin-top: 2px; }
.doc-list { list-style: none; }
.doc-list li { padding: 6px 0; border-bottom: 1px solid #f1f5f9; font-size: 0.85rem; }

/* Upload tracker */
.ut-card { padding: 16px; }
.ut-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.ut-file { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; font-size: 0.9rem; }
.ut-file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ut-file-type { font-size: 0.72rem; color: #94a3b8; text-transform: capitalize; }
.ut-status { font-size: 0.75rem; font-weight: 600; white-space: nowrap; padding: 2px 10px; border-radius: 10px; }
.ut-status.ut-done { background: #dcfce7; color: #166534; }
.ut-status.ut-fail { background: #fee2e2; color: #991b1b; }
.ut-status.ut-pending { background: #fef3c7; color: #92400e; }
.ut-message { font-size: 0.85rem; color: #475569; padding: 4px 0; }
.ut-detail { font-size: 0.78rem; color: #94a3b8; }
.ut-error { font-size: 0.85rem; color: #dc2626; padding: 4px 0; }
.ut-person { color: #94a3b8; }
.ut-expenses { margin-top: 8px; }
.ut-confirm-all { margin-top: 8px; display: block; margin-left: auto; width: fit-content; }

/* Fixed-layout table with explicit column widths so the description
   column gets the leftover space and ellipsizes instead of forcing a
   horizontal scrollbar. Person chip stacks above category text in the
   merged Category cell. */
.expenses-table { table-layout: fixed; width: 100%; }
.expenses-table th.col-date,     .expenses-table td.col-date     { width: 90px; }
.expenses-table th.col-amount,   .expenses-table td.col-amount   { width: 110px; }
.expenses-table th.col-category, .expenses-table td.col-category { width: 130px; white-space: normal; }
.expenses-table th.col-status,   .expenses-table td.col-status   { width: 80px; }
.expenses-table th.col-actions,  .expenses-table td.col-actions  { width: 150px; }
.expenses-table td.col-desc { min-width: 0; overflow: hidden; }
.expenses-table td.col-category .person-chip { display: inline-block; margin-bottom: 3px; }
.expenses-table td.col-category .cat-text { font-size: 0.78rem; color: #64748b; text-transform: capitalize; word-break: break-word; line-height: 1.3; }

/* Icon-only action buttons (pencil/trash). Used where the action is
   secondary and labels would crowd the row. */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  background: none; border: 1px solid #d1d5db; border-radius: 6px;
  color: #64748b; cursor: pointer;
}
.btn-icon:hover { background: #f1f5f9; color: #1e293b; }
.btn-icon.btn-icon-danger { color: #dc2626; }
.btn-icon.btn-icon-danger:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.btn-icon svg { display: block; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; overflow-y: auto; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 520px; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(0,0,0,0.25); margin: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid #e2e8f0; flex-shrink: 0; }
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: #64748b; padding: 0 4px; width: auto; }
.modal-close:hover { color: #1e293b; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid #e2e8f0; flex-shrink: 0; }
.modal-footer .btn { width: auto; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 0.8rem; color: #475569; margin-bottom: 4px; font-weight: 500; }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.9rem; margin-bottom: 0; font-family: inherit; }
.form-row .row-pair { display: flex; gap: 8px; }
.form-row .row-pair input.curr { width: 80px; flex-shrink: 0; text-transform: uppercase; }
.modal-source { margin-top: 12px; padding-top: 12px; border-top: 1px solid #f1f5f9; }
.modal-source img { max-width: 100%; max-height: 300px; border-radius: 4px; display: block; }

/* Change-password modal labels (modal-body uses native input default styling) */
.cp-label { display: block; font-size: 0.8rem; color: #475569; margin-bottom: 4px; font-weight: 500; }
.cp-hint { font-size: 0.75rem; color: #94a3b8; margin-top: 4px; }
.success-msg { color: #166534; background: #dcfce7; padding: 8px 12px; border-radius: 6px; font-size: 0.85rem; margin-bottom: 8px; }

/* Login extras: forgot link and inline forgot form */
.login-box .forgot-link { display: block; text-align: center; margin-top: 12px; font-size: 0.85rem; color: #2563eb; text-decoration: none; }
.login-box .forgot-link:hover { text-decoration: underline; }
.login-box .back-link { display: block; text-align: center; margin-top: 12px; font-size: 0.85rem; color: #64748b; text-decoration: none; }
.login-box .back-link:hover { text-decoration: underline; }
.login-box h1 .site-tag { display: block; font-size: 0.7rem; font-weight: 400; color: #94a3b8; margin-top: 4px; letter-spacing: 0.05em; text-transform: uppercase; }

/* Header "change password" link — match nav link style */
header nav .nav-action { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 0.85rem; padding: 0; font-family: inherit; width: auto; }
header nav .nav-action:hover { color: #fff; }

@media (max-width: 640px) {
  .container { padding: 8px; }
  .card { padding: 14px; }

  /* On mobile the nav is a hamburger menu, so the user identity has room
     for the "Signed in as" label and should look like a list item. */
  header nav #user-name { padding-left: 4px; margin-left: 0; border-left: none; font-size: 0.85rem; }
  header nav #user-name[data-label]:not(:empty)::before { content: attr(data-label) ' '; color: #64748b; }

  .btn-icon { width: 36px; height: 36px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal { max-width: 100%; max-height: 100vh; max-height: 100dvh; height: 100vh; height: 100dvh; border-radius: 0; margin: 0; }

  /* Expenses table reflows into stacked cards on mobile */
  .table-wrap { overflow-x: visible; }
  .expenses-table { display: block; width: 100%; font-size: 0.85rem; }
  .expenses-table thead { display: none; }
  .expenses-table tbody { display: block; }
  .expenses-table tr {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "date     status"
      "desc     desc"
      "amount   amount"
      "category category";
    column-gap: 12px;
    row-gap: 6px;
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
  }
  .expenses-table.has-actions tr {
    grid-template-areas:
      "date     status"
      "desc     desc"
      "amount   amount"
      "category category"
      "actions  actions";
  }
  .expenses-table tr:hover { background: #fff; }
  .expenses-table td { display: block; padding: 0; border: none; }
  .expenses-table td.col-date     { grid-area: date; color: #475569; font-weight: 600; }
  .expenses-table td.col-desc     { grid-area: desc; max-width: none; overflow-wrap: anywhere; word-break: break-word; }
  /* Amount cell: amount + deductible chip inline on mobile */
  .expenses-table td.col-amount   { grid-area: amount; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .expenses-table td.col-amount .amount-value { display: inline; }
  .expenses-table td.col-amount .ded-chip { margin-top: 0; }
  .expenses-table td.col-category {
    grid-area: category; text-align: left; align-self: center;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    min-width: 0; overflow: visible; white-space: normal;
  }
  .expenses-table td.col-category .person-chip { margin-bottom: 0; }
  .expenses-table td.col-category .cat-text { display: inline; font-size: 0.78rem; color: #64748b; text-transform: capitalize; }
  .expenses-table td.col-status   { grid-area: status; text-align: right; }
  .expenses-table td.col-actions  { grid-area: actions; text-align: right; padding-top: 6px; border-top: 1px solid #f1f5f9; margin-top: 4px; }

  .action-group { gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
  .action-group .btn { padding: 8px 12px; font-size: 0.78rem; min-height: 36px; }

  /* Hamburger nav */
  #nav-toggle { display: inline-block; }
  header { flex-wrap: wrap; }
  header nav {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding-top: 12px;
    margin-top: 12px;
    border-top: 1px solid #475569;
  }
  header nav.open { display: flex; }
  header nav a { padding: 8px 4px; }
  header nav #user-name { padding: 8px 4px; opacity: 0.7; }
  header nav .nav-action { padding: 8px 4px; text-align: left; }
  #logout-btn { align-self: flex-start; }
}
