/* =========================================================
   PROFESSIONAL FINANCIAL APP UI
   Drop-in replacement for the existing stylesheet.
   Keeps the original class names while upgrading the design
   and responsive behavior across desktop, tablet, and mobile.
   ========================================================= */

/* =========================================================
   1. DESIGN TOKENS
   ========================================================= */
:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-soft: #dbeafe;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;

  --bg-color: #f5f7fb;
  --surface: #ffffff;
  --card-bg: #ffffff;
  --surface-muted: #f8fafc;
  --surface-hover: #f1f5f9;

  --text-color: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.07);
  --shadow-hover: 0 16px 34px rgba(15, 23, 42, 0.1);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --content-max: 1280px;
  --header-height: 72px;
  --transition: 160ms ease;
}

/* =========================================================
   2. RESET / BASE
   ========================================================= */
* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg-color);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.055), transparent 34rem),
    var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

input,
select,
textarea,
button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3,
.amount,
td,
th {
  font-variant-numeric: tabular-nums;
}

/* =========================================================
   3. HEADER / NAVIGATION
   ========================================================= */
header {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px max(24px, env(safe-area-inset-right)) 14px max(24px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid rgba(226, 232, 240, 0.88);
  box-shadow: 0 1px 12px rgba(15, 23, 42, 0.035);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.logo {
  flex: 0 0 auto;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--text-color);
}

.logo::first-letter {
  color: var(--primary-color);
}

nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

nav button {
  min-height: 40px;
  margin: 0;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

nav button:hover {
  background: var(--surface-hover);
  color: var(--text-color);
}

nav button:active {
  transform: translateY(1px);
}

nav button.active,
nav button[aria-current="page"] {
  background: var(--primary-light);
  border-color: var(--primary-soft);
  color: var(--primary-dark);
}

/* =========================================================
   4. PAGE SHELL
   ========================================================= */
main {
  width: min(calc(100% - 40px), var(--content-max));
  margin: 28px auto 48px;
  padding: clamp(20px, 3vw, 34px);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

main > h1:first-child,
main > h2:first-child {
  margin-bottom: 8px;
  letter-spacing: -0.035em;
  color: var(--text-color);
}

main > p {
  color: var(--text-muted);
}

/* =========================================================
   5. SUMMARY / REPORT CARDS
   ========================================================= */
.report-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 16px;
  margin: 0 0 24px;
}

.report-card,
.admin-card {
  position: relative;
  min-width: 0;
  padding: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.report-card::before,
.admin-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--primary-color);
}

.report-card:hover,
.admin-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-hover);
}

.report-card.spent::before {
  background: var(--danger);
}

.report-card.received::before,
.report-card.income::before {
  background: var(--success);
}

.report-card h3,
.admin-card h3 {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.report-card .amount {
  margin: 4px 0 0;
  color: var(--text-color);
  font-size: clamp(1.75rem, 3.2vw, 2.45rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
}

.report-card small,
.admin-card small {
  color: var(--text-muted);
}

/* =========================================================
   6. COLLAPSIBLE SECTIONS
   ========================================================= */
details {
  margin: 0 0 20px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

summary {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 20px;
  color: var(--text-color);
  font-size: 1rem;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition);
}

summary:hover {
  background: var(--surface-muted);
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "";
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform var(--transition);
}

details[open] summary {
  border-bottom: 1px solid var(--border-color);
}

details[open] summary::after {
  transform: rotate(225deg) translate(-2px, -2px);
}

details > :not(summary) {
  margin-left: 20px;
  margin-right: 20px;
}

details > :last-child {
  margin-bottom: 20px;
}

/* =========================================================
   7. PROGRESS / BUDGET BARS
   ========================================================= */
.visual-bar-container {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.visual-row {
  margin-bottom: 20px;
}

.visual-row:last-child {
  margin-bottom: 0;
}

.visual-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--text-color);
  font-size: 0.92rem;
  font-weight: 750;
}

.visual-label span:last-child {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
}

.bar-bg {
  width: 100%;
  height: 10px;
  overflow: hidden;
  background: #e9eef5;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--primary-color), #3b82f6);
  border-radius: inherit;
  transition: width 700ms cubic-bezier(0.4, 0, 0.2, 1);
}

.bar-fill.over-budget,
.bar-fill.danger {
  background: var(--danger);
}

.bar-fill.success {
  background: var(--success);
}

/* =========================================================
   8. FILTERS / FORMS
   ========================================================= */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 0 0 20px;
  padding: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.filter-bar input,
.filter-bar select,
.add-form input,
.add-form select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-color);
  font-size: 0.92rem;
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}

.filter-bar input::placeholder,
.add-form input::placeholder {
  color: var(--text-soft);
}

.filter-bar input:focus,
.filter-bar select:focus,
.add-form input:focus,
.add-form select:focus {
  border-color: #93b4fb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  outline: none;
}

.add-form {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.add-form input,
.add-form select {
  flex: 1 1 180px;
}

.add-form button,
.excel-table button {
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.18);
  color: #fff;
  font-weight: 800;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

.add-form button:hover,
.excel-table button:hover {
  filter: brightness(1.03);
  box-shadow: 0 7px 18px rgba(37, 99, 235, 0.24);
}

.add-form button:active,
.excel-table button:active {
  transform: translateY(1px);
}

/* =========================================================
   9. DESKTOP TABLES
   ========================================================= */
.excel-table,
.history-table {
  width: 100%;
  margin-top: 14px;
  border-spacing: 0;
  border-collapse: separate;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.excel-table th,
.history-table th {
  padding: 12px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  color: #475569;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.035em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.excel-table td,
.history-table td {
  min-width: 0;
  padding: 13px 14px;
  border-bottom: 1px solid #edf1f6;
  color: #334155;
  font-size: 0.9rem;
  vertical-align: middle;
}

.excel-table tr:last-child td,
.history-table tr:last-child td {
  border-bottom: 0;
}

.excel-table tbody tr,
.history-table tbody tr {
  transition: background-color var(--transition);
}

.excel-table tbody tr:hover,
.history-table tbody tr:hover {
  background: #fbfdff;
}

.excel-table input,
.excel-table select {
  width: 100%;
  min-width: 90px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-color);
  font-size: 0.9rem;
  transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.excel-table input:hover,
.excel-table select:hover {
  background: var(--surface-muted);
  border-color: var(--border-color);
}

.excel-table input:focus,
.excel-table select:focus {
  outline: none;
  background: var(--surface);
  border-color: #93b4fb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.excel-table button {
  width: 100%;
  white-space: nowrap;
}

/* =========================================================
   10. ACTION BUTTONS
   ========================================================= */
.action-btn {
  min-height: 34px;
  padding: 7px 11px;
  margin: 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  transition: transform var(--transition), filter var(--transition), box-shadow var(--transition);
}

.action-btn:hover {
  filter: brightness(0.98);
  box-shadow: var(--shadow-sm);
}

.action-btn:active {
  transform: translateY(1px);
}

.edit-btn {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: #92400e;
}

.delete-btn {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: #b91c1c;
}

/* =========================================================
   11. ADMIN LISTS
   ========================================================= */
.admin-list {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}

.admin-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  color: #334155;
}

.admin-list li:last-child {
  border-bottom: 0;
}

.admin-list button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: var(--danger-soft);
  color: #b91c1c;
  font-weight: 800;
}

/* =========================================================
   12. TABLET / SMALL LAPTOPS
   ========================================================= */
@media (max-width: 1024px) {
  :root {
    --content-max: 960px;
  }

  header {
    gap: 14px;
    padding-left: 18px;
    padding-right: 18px;
  }

  nav button {
    padding-left: 11px;
    padding-right: 11px;
    font-size: 0.85rem;
  }

  main {
    width: min(calc(100% - 28px), var(--content-max));
    margin-top: 20px;
  }

  .excel-table,
  .history-table {
    font-size: 0.88rem;
  }

  .excel-table th,
  .history-table th,
  .excel-table td,
  .history-table td {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* =========================================================
   13. MOBILE APP LAYOUT
   ========================================================= */
@media (max-width: 768px) {
  body {
    background: var(--bg-color);
  }

  header {
    position: sticky;
    min-height: auto;
    display: block;
    padding: 12px 14px 9px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .logo {
    display: block;
    margin-bottom: 10px;
    padding: 2px 2px 0;
    font-size: 1.18rem;
  }

  nav {
    width: 100%;
    margin: 10px 0 0 0;
    padding: 0;
    display: flex;
    justify-content: space-between; /* Spreads them perfectly */
    flex-wrap: nowrap; /* FORCES them to stay on one line */
    gap: 4px; /* Tightens the space between them */
  }

  nav button {
    flex: 1; /* Makes all 4 buttons exactly the same width */
    text-align: center;
    min-height: 42px;
    padding: 8px 2px; /* Reduces side padding to make room for text */
    font-size: 0.72rem; /* Slightly smaller font to fit "Transactions" */
    white-space: nowrap; /* Stops the text from breaking onto two lines */
    letter-spacing: -0.02em; /* Pulls the letters together just a hair */
  }

  main {
    width: 100%;
    margin: 0;
    padding: 16px 14px calc(28px + env(safe-area-inset-bottom));
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .report-grid,
  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }

  .report-card,
  .admin-card {
    padding: 16px 14px;
    border-radius: 14px;
  }

  .report-card:hover,
  .admin-card:hover {
    transform: none;
  }

  .report-card h3,
  .admin-card h3 {
    margin-bottom: 7px;
    font-size: 0.68rem;
    letter-spacing: 0.055em;
  }

  .report-card .amount {
    font-size: clamp(1.35rem, 7vw, 1.8rem);
  }

  details,
  .visual-bar-container {
    border-radius: 14px;
  }

  summary {
    min-height: 54px;
    padding: 15px 16px;
    font-size: 0.95rem;
  }

  details > :not(summary) {
    margin-left: 14px;
    margin-right: 14px;
  }

  .visual-bar-container {
    padding: 16px;
  }

  .filter-bar {
    grid-template-columns: 1fr;
    gap: 9px;
    padding: 12px;
  }

  .filter-bar input,
  .filter-bar select,
  .add-form input,
  .add-form select {
    min-height: 46px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .add-form {
    flex-direction: column;
  }

  .add-form input,
  .add-form select {
    flex-basis: auto;
  }

  .add-form button {
    width: 100%;
    min-height: 48px;
  }

  /* Mobile entry form becomes a clean card */
  .excel-table,
  .excel-table tbody,
  .excel-table tr,
  .excel-table td {
    display: block;
    width: 100%;
  }

  .excel-table {
    margin-top: 12px;
    padding: 14px;
    overflow: visible;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }

  .excel-table thead {
    display: none;
  }

  .excel-table tr {
    display: grid;
    gap: 12px;
  }

  .excel-table td {
    position: relative;
    margin: 0;
    padding: 22px 0 0;
    border: 0;
  }

  .excel-table td::before {
    content: "Field";
    position: absolute;
    top: 0;
    left: 1px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .excel-table td:nth-child(1)::before { content: "Date"; }
  .excel-table td:nth-child(2)::before { content: "Description"; }
  .excel-table td:nth-child(3)::before { content: "Category"; }
  .excel-table td:nth-child(4)::before { content: "Spent"; }
  .excel-table td:nth-child(5)::before { content: "Received"; }
  .excel-table td:nth-child(6)::before { content: "From account"; }
  .excel-table td:nth-child(7)::before { content: "To account"; }

  .excel-table input,
  .excel-table select {
    min-width: 0;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    font-size: 16px;
  }

  .excel-table td:last-child {
    padding-top: 4px;
  }

  .excel-table button {
    min-height: 48px;
    border-radius: 10px;
    font-size: 0.95rem;
  }

  /* Transaction history becomes individual finance cards */
  .history-table,
  .history-table tbody,
  .history-table tr,
  .history-table td {
    display: block;
    width: 100%;
  }

  .history-table {
    border: 0;
    background: transparent;
    border-radius: 0;
    overflow: visible;
  }

  .history-table thead {
    display: none;
  }

  .history-table tbody {
    display: grid;
    gap: 12px;
  }

  .history-table tr {
    margin: 0;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
  }

  .history-table tbody tr:hover {
    background: var(--surface);
  }

  .history-table td {
    position: relative;
    min-height: 38px;
    padding: 8px 0 8px 46%;
    border-bottom: 1px solid #edf1f6;
    text-align: right;
    overflow-wrap: anywhere;
  }

  .history-table td::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 0;
    width: 42%;
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 750;
    text-align: left;
  }

  .history-table td:nth-child(1)::before { content: "Date"; }
  .history-table td:nth-child(2)::before { content: "Description"; }
  .history-table td:nth-child(3)::before { content: "Category"; }
  .history-table td:nth-child(4)::before { content: "Spent"; }
  .history-table td:nth-child(5)::before { content: "Received"; }
  .history-table td:nth-child(6)::before { content: "Account"; }

  .history-table td:last-child {
    min-height: auto;
    margin-top: 8px;
    padding: 10px 0 0;
    border-bottom: 0;
    text-align: center;
  }

  .history-table td:last-child::before {
    display: none;
  }

  .history-table .action-btn {
    min-height: 40px;
    padding: 8px 12px;
  }

  .admin-list li {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}

/* =========================================================
   14. SMALL PHONES
   ========================================================= */
@media (max-width: 480px) {
  main {
    padding-left: 12px;
    padding-right: 12px;
  }

  .report-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .report-card,
  .admin-card {
    padding: 16px;
  }

  .visual-label {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .visual-label span:last-child {
    text-align: left;
  }

  .history-table td {
    padding-left: 43%;
  }

  .history-table td::before {
    width: 39%;
  }
}

/* =========================================================
   15. EXTRA-NARROW DEVICES
   ========================================================= */
@media (max-width: 360px) {
  header {
    padding-left: 10px;
    padding-right: 10px;
  }

  nav {
    width: calc(100% + 20px);
    margin-left: -10px;
    padding-left: 10px;
    padding-right: 10px;
  }

  main {
    padding-left: 10px;
    padding-right: 10px;
  }

  .report-card .amount {
    font-size: 1.45rem;
  }

  .history-table td {
    padding-left: 0;
    padding-top: 26px;
    text-align: left;
  }

  .history-table td::before {
    top: 7px;
    width: 100%;
  }
}

/* =========================================================
   16. LARGE SCREENS
   ========================================================= */
@media (min-width: 1440px) {
  main {
    margin-top: 36px;
    padding: 38px;
  }

  .report-grid,
  .admin-grid {
    gap: 20px;
  }
}

/* =========================================================
   17. ACCESSIBILITY / MOTION
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (forced-colors: active) {
  .report-card,
  .admin-card,
  details,
  .visual-bar-container,
  .excel-table,
  .history-table,
  .history-table tr {
    border: 1px solid CanvasText;
  }
}
