/* ============================================================
   NOTEBOOK THEME — Expense Tracker
   Fully standalone. No Bootstrap required.
   Fonts: Caveat (headings) + Kalam (body/inputs)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;500;600;700&family=Kalam:wght@300;400;700&display=swap');

/* ── Variables ──────────────────────────────────────────── */
:root {
  --paper:           #f7f3e9;
  --paper-dark:      #ede8d5;
  --paper-shadow:    #c8bfa0;
  --ink:             #1c2b4a;
  --ink-mid:         #3a4f6e;
  --ink-faint:       #8095b0;
  --margin-line:     #e05a5a;
  --rule-line:       #b8cfe0;
  --rule-line-soft:  #ccdde8;
  --binding-red:     #c0392b;
  --highlight:       #fffacd;
  --highlight-warm:  #ffeaa7;
  --green-ink:       #1a6b3a;
  --red-ink:         #c0392b;
  --blue-ink:        #2c5fa8;
  --line-h:          32px;
  --radius:          3px;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 16px; }

body {
  font-family: 'Kalam', cursive;
  font-weight: 400;
  color: var(--ink);
  background-color: #c9c0a8;
  background-image:
    radial-gradient(ellipse at 20% 50%, #bfb695 0%, transparent 55%),
    radial-gradient(ellipse at 80% 20%, #b8b08a 0%, transparent 50%);
  min-height: 100vh;
  line-height: 1.65;
}

a {
  color: var(--blue-ink);
  text-decoration: underline wavy var(--blue-ink);
  transition: color 0.2s;
}

a:hover { color: var(--red-ink); text-decoration-color: var(--red-ink); }

ul, ol { list-style: none; }

button { cursor: pointer; font-family: inherit; }

/* ── Animations ─────────────────────────────────────────── */
@keyframes pageTurnIn {
  0% {
    transform: perspective(1800px) rotateY(-20deg) translateX(-24px);
    opacity: 0;
    filter: brightness(0.88);
  }
  55% {
    transform: perspective(1800px) rotateY(2.5deg) translateX(4px);
    opacity: 1;
    filter: brightness(1.02);
  }
  75% {
    transform: perspective(1800px) rotateY(-0.8deg) translateX(-1px);
  }
  100% {
    transform: perspective(1800px) rotateY(0deg) translateX(0);
    opacity: 1;
    filter: brightness(1);
  }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes spiralDrop {
  from { transform: scaleY(0); opacity: 0; transform-origin: top; }
  to   { transform: scaleY(1); opacity: 1; transform-origin: top; }
}

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 2rem;
  background: linear-gradient(135deg, #1a2744 0%, #2c3e6b 60%, #1a3050 100%);
  border-bottom: 4px solid var(--binding-red);
  box-shadow: 0 3px 14px rgba(0,0,0,0.4);
  position: relative;
  z-index: 100;
}

/* Dashed strip below the red border */
.navbar::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 0; right: 0;
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    var(--binding-red) 0, var(--binding-red) 8px,
    transparent 8px, transparent 14px
  );
}

.navbar-brand {
  font-family: 'Caveat', cursive;
  font-size: 1.85rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0.04em;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.navbar-brand:hover {
  color: #fff;
  transform: rotate(-1deg) scale(1.04);
  text-decoration: none;
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.navbar-links li { display: inline; }

.nav-link {
  font-family: 'Caveat', cursive;
  font-size: 1.2rem;
  font-weight: 500;
  color: #c8d4f0;
  text-decoration: none;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  transition: color 0.2s, background 0.2s, transform 0.15s;
  display: inline-block;
}

.nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
  transform: rotate(-1.5deg) translateY(-1px);
  text-decoration: none;
}

/* Hamburger — hidden on desktop */
.navbar-toggle {
  display: none;
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 1.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius);
  line-height: 1;
}

/* ── Page Container (The Notebook Page) ─────────────────── */
.page-container {
  max-width: 980px;
  margin: 18px auto 40px;
  padding: 20px 28px 48px;
  min-height: calc(100vh - 100px);
  position: relative;

  /* Aged paper background */
  background-color: var(--paper);

  /* Ruled lines + red margin line */
  background-image:
    linear-gradient(
      90deg,
      transparent 66px,
      var(--margin-line) 66px,
      var(--margin-line) 68px,
      transparent 68px
    ),
    repeating-linear-gradient(
      transparent,
      transparent calc(var(--line-h) - 1px),
      var(--rule-line) calc(var(--line-h) - 1px),
      var(--rule-line) var(--line-h)
    );
  background-attachment: local;

  /* Binding & shadow */
  border-left: 6px solid var(--binding-red);
  box-shadow:
    -2px 0 8px rgba(0,0,0,0.18),
    4px 6px 22px rgba(0,0,0,0.22),
    8px 8px 0 rgba(0,0,0,0.07),
    14px 14px 0 rgba(0,0,0,0.04);

  /* Page-turn on load */
  transform-origin: left center;
  animation: pageTurnIn 0.65s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

/* Spiral binding holes along the top */
.page-container::before {
  content: '';
  display: block;
  height: 26px;
  margin: -20px -28px 18px;
  background-image: radial-gradient(circle at center, #777 28%, #aaa 48%, #444 68%, transparent 70%);
  background-size: 24px 24px;
  background-repeat: repeat-x;
  background-position: 14px center;
  animation: spiralDrop 0.45s 0.1s ease-out both;
}

/* Bottom-right corner fold */
.page-container::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 0 38px 38px;
  border-color: transparent transparent var(--paper-shadow) transparent;
  filter: drop-shadow(-2px -2px 3px rgba(0,0,0,0.12));
}

/* ── Flash Messages ─────────────────────────────────────── */
.flash-messages {
  margin-bottom: 1.25rem;
}

.flash {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem 0.7rem 1.25rem;
  margin-bottom: 0.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: 'Kalam', cursive;
  animation: fadeUp 0.3s ease both;
  box-shadow: 1px 2px 5px rgba(0,0,0,0.08);
}

.flash::before { content: '✎ '; opacity: 0.65; margin-right: 0.25rem; }

.flash-success { background: #e8f5e9; color: #1b5e20; border-left: 4px solid #43a047; }
.flash-danger  { background: #fdecea; color: #7f0000; border-left: 4px solid #e53935; }
.flash-info    { background: #e3f2fd; color: #0d3c61; border-left: 4px solid #1e88e5; }
.flash-warning { background: #fffde7; color: #4e3700; border-left: 4px solid #fdd835; }

.flash-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  opacity: 0.45;
  padding: 0 0.2rem;
  transition: opacity 0.2s;
}
.flash-close:hover { opacity: 0.9; }

/* ── Page Header (list page title row) ──────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--rule-line);
}

/* ── Typography ─────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
  letter-spacing: 0.02em;
}

h2 { font-size: 2.1rem; }
h4 { font-size: 1.55rem; }

/* ── Cards ──────────────────────────────────────────────── */
.card-wrap {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
}

.card-wrap .card {
  width: 100%;
  max-width: 620px;
}

.card {
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent calc(var(--line-h) - 1px),
      var(--rule-line-soft) calc(var(--line-h) - 1px),
      var(--rule-line-soft) var(--line-h)
    );
  border-radius: var(--radius) var(--radius) 5px var(--radius);
  box-shadow:
    0 2px 6px rgba(0,0,0,0.09),
    3px 5px 14px rgba(0,0,0,0.11),
    inset 0 0 0 1px rgba(0,0,0,0.05);
  position: relative;
  overflow: hidden;
  margin-bottom: 1.5rem;
  animation: fadeUp 0.45s 0.2s ease both;
}

/* Tape decoration on card */
.card::before {
  content: '';
  position: absolute;
  top: -5px; left: 50%;
  transform: translateX(-50%) rotate(-1.5deg);
  width: 72px; height: 20px;
  background: rgba(255, 250, 180, 0.78);
  border: 1px solid rgba(200, 190, 100, 0.35);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  z-index: 2;
}

.card-header {
  padding: 1.15rem 1.5rem 0.75rem;
  border-bottom: 2px solid var(--rule-line);
  position: relative;
  z-index: 3;
}

.card-header h4::before { content: '✏ '; opacity: 0.55; }

.card-header--primary { border-bottom-color: var(--blue-ink); }
.card-header--primary h4::before { content: '✏ '; }

.card-header--warning  { border-bottom-color: #c89000; }
.card-header--warning h4::before { content: '✎ '; }

.card-body {
  padding: 1.4rem 1.6rem;
  position: relative;
  z-index: 3;
}

/* ── Forms ──────────────────────────────────────────────── */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.5rem;
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-label {
  display: block;
  font-family: 'Caveat', cursive;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink-mid);
  margin-bottom: 0.2rem;
}

.form-input,
.form-textarea {
  display: block;
  width: 100%;
  font-family: 'Kalam', cursive;
  font-size: 1rem;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--rule-line);
  border-radius: 0;
  padding: 0.4rem 0.3rem;
  outline: none;
  transition: border-color 0.22s, background 0.22s;
  caret-color: var(--ink);
  resize: none;
}

.form-input:focus,
.form-textarea:focus {
  border-bottom-color: var(--blue-ink);
  background: rgba(255, 250, 180, 0.3);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--ink-faint);
  font-style: italic;
  font-weight: 300;
}

.form-input--error {
  border-bottom-color: var(--red-ink) !important;
  background: rgba(220, 50, 50, 0.04) !important;
}

.field-error {
  font-family: 'Kalam', cursive;
  font-size: 0.88rem;
  color: var(--red-ink);
  font-style: italic;
  margin-top: 0.2rem;
}

/* Input group — $prefix + input */
.input-group {
  display: flex;
  align-items: flex-end;
  border-bottom: 2px solid var(--rule-line);
  transition: border-color 0.22s;
}

.input-group:focus-within {
  border-bottom-color: var(--blue-ink);
}

.input-group .form-input {
  border-bottom: none;
  flex: 1;
}

.input-prefix {
  font-family: 'Caveat', cursive;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-ink);
  padding: 0.4rem 0.35rem 0.4rem 0.1rem;
  line-height: 1;
  flex-shrink: 0;
}

/* Checkbox */
.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.1rem;
}

.check-input {
  width: 16px;
  height: 16px;
  accent-color: var(--ink-mid);
  cursor: pointer;
  flex-shrink: 0;
}

.check-label {
  font-family: 'Kalam', cursive;
  font-size: 0.95rem;
  color: var(--ink-mid);
  cursor: pointer;
}

/* Form actions row */
.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.form-actions--full { justify-content: stretch; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-block;
  font-family: 'Caveat', cursive;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  border-radius: var(--radius);
  padding: 0.45rem 1.25rem;
  border: 2px solid transparent;
  line-height: 1.4;
  cursor: pointer;
  transition: transform 0.14s, box-shadow 0.14s, background 0.18s, color 0.18s;
  white-space: nowrap;
}

.btn:hover  { transform: translateY(-2px) rotate(-0.5deg); text-decoration: none; }
.btn:active { transform: translateY(1px) rotate(0.2deg); }

.btn--full { width: 100%; text-align: center; }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  box-shadow: 2px 3px 0 var(--ink-mid);
}
.btn-primary:hover {
  background: var(--ink-mid);
  border-color: var(--ink-mid);
  color: #fff;
  box-shadow: 3px 4px 0 var(--ink);
}

.btn-secondary {
  background: transparent;
  border-color: var(--ink-faint);
  color: var(--ink-mid);
  box-shadow: 2px 3px 0 rgba(0,0,0,0.08);
}
.btn-secondary:hover {
  background: var(--paper-dark);
  border-color: var(--ink-mid);
  color: var(--ink);
  box-shadow: 3px 4px 0 rgba(0,0,0,0.13);
}

.btn-warning {
  background: var(--highlight-warm);
  border-color: #c89000;
  color: var(--ink);
  box-shadow: 2px 3px 0 rgba(180,130,0,0.28);
}
.btn-warning:hover {
  background: #ffd700;
  border-color: #a07000;
  color: var(--ink);
  box-shadow: 3px 4px 0 rgba(160,110,0,0.35);
}

.btn-danger {
  background: #fdecea;
  border-color: var(--red-ink);
  color: var(--red-ink);
  box-shadow: 2px 3px 0 rgba(192,57,43,0.18);
}
.btn-danger:hover {
  background: var(--red-ink);
  border-color: #8e1b12;
  color: #fff;
  box-shadow: 3px 4px 0 rgba(192,57,43,0.32);
}

.btn-sm {
  font-size: 0.95rem;
  padding: 0.2rem 0.7rem;
}

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

.expense-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Kalam', cursive;
  font-size: 1rem;
}

.expense-table thead tr {
  border-bottom: 2.5px solid var(--ink);
}

.expense-table th {
  font-family: 'Caveat', cursive;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  padding: 0.45rem 0.8rem;
  text-align: left;
  background: transparent;
}

.expense-table tbody tr {
  border-bottom: 1px solid var(--rule-line);
  transition: background 0.18s;
  animation: fadeUp 0.3s ease both;
}

/* Stagger each row's animation */
.expense-table tbody tr:nth-child(1)  { animation-delay: 0.04s; }
.expense-table tbody tr:nth-child(2)  { animation-delay: 0.09s; }
.expense-table tbody tr:nth-child(3)  { animation-delay: 0.14s; }
.expense-table tbody tr:nth-child(4)  { animation-delay: 0.19s; }
.expense-table tbody tr:nth-child(5)  { animation-delay: 0.24s; }
.expense-table tbody tr:nth-child(6)  { animation-delay: 0.29s; }
.expense-table tbody tr:nth-child(7)  { animation-delay: 0.34s; }
.expense-table tbody tr:nth-child(8)  { animation-delay: 0.39s; }
.expense-table tbody tr:nth-child(9)  { animation-delay: 0.44s; }
.expense-table tbody tr:nth-child(10) { animation-delay: 0.49s; }

.expense-table tbody tr:nth-child(even) {
  background: rgba(184, 207, 224, 0.13);
}

.expense-table tbody tr:hover {
  background: var(--highlight);
}

.expense-table td {
  padding: 0.5rem 0.8rem;
  vertical-align: middle;
  color: var(--ink);
  border: none;
}

/* Amount column */
.col-amount {
  text-align: right;
  font-family: 'Caveat', cursive;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green-ink);
}

/* Actions column */
.col-actions {
  text-align: center;
  white-space: nowrap;
}

.inline-form {
  display: inline;
}

/* Totals row */
.expense-table tfoot .total-row {
  border-top: 2px double var(--ink);
  background: var(--highlight);
}

.expense-table tfoot .total-row td {
  padding: 0.6rem 0.8rem;
}

.total-label {
  text-align: right;
  font-family: 'Caveat', cursive;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-mid);
}

.total-amount {
  font-family: 'Caveat', cursive;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-ink);
}

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-state p {
  font-family: 'Caveat', cursive;
  font-size: 1.4rem;
  font-style: italic;
  color: var(--ink-faint);
  margin-bottom: 1.25rem;
}

/* ── Auth Pages (Login / Register) ──────────────────────── */
.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
}

.auth-wrap .card {
  width: 100%;
  max-width: 420px;
}

.auth-wrap .card::before {
  content: '📖';
  position: absolute;
  top: -14px; left: 50%;
  transform: translateX(-50%);
  width: auto; height: auto;
  background: none;
  border: none;
  font-size: 1.6rem;
  box-shadow: none;
  border-radius: 0;
}

.auth-title {
  font-size: 2.3rem;
  text-align: center;
  margin-bottom: 1.4rem;
  padding-bottom: 0.5rem;
  border-bottom: 1.5px solid var(--rule-line);
}

.auth-footer {
  text-align: center;
  margin-top: 1.2rem;
  font-family: 'Kalam', cursive;
  font-size: 0.95rem;
  color: var(--ink-mid);
}

.auth-footer a {
  font-weight: 700;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 720px) {

  .navbar {
    flex-wrap: wrap;
    padding: 0.55rem 1rem;
    gap: 0.5rem;
  }

  .navbar-toggle {
    display: block;
  }

  .navbar-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.4rem 0;
    gap: 0;
  }

  .navbar-links.open {
    display: flex;
  }

  .nav-link {
    width: 100%;
    padding: 0.4rem 0.5rem;
  }

  .page-container {
    margin: 10px auto 24px;
    padding: 16px 16px 40px;
    background-image:
      linear-gradient(
        90deg,
        transparent 42px,
        var(--margin-line) 42px,
        var(--margin-line) 44px,
        transparent 44px
      ),
      repeating-linear-gradient(
        transparent,
        transparent calc(var(--line-h) - 1px),
        var(--rule-line) calc(var(--line-h) - 1px),
        var(--rule-line) var(--line-h)
      );
  }

  .page-container::before {
    background-size: 18px 18px;
    height: 20px;
    margin: -16px -16px 14px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .card-wrap .card,
  .auth-wrap .card {
    max-width: 100%;
  }

  /* Stack table into card-style rows on mobile */
  .expense-table thead { display: none; }

  .expense-table,
  .expense-table tbody,
  .expense-table tr,
  .expense-table td {
    display: block;
    width: 100%;
  }

  .expense-table tbody tr {
    margin-bottom: 0.85rem;
    border: 1px solid var(--rule-line) !important;
    border-radius: 4px;
    padding: 0.6rem 0.75rem;
    background: rgba(255,255,255,0.45);
  }

  .expense-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    text-align: right;
    border-bottom: 1px dashed var(--rule-line-soft);
  }

  .expense-table td:last-child { border-bottom: none; }

  .expense-table td::before {
    content: attr(data-label);
    font-family: 'Caveat', cursive;
    font-weight: 700;
    color: var(--ink-faint);
    text-align: left;
    flex-shrink: 0;
    margin-right: 0.5rem;
  }

  .col-amount, .col-actions {
    text-align: right;
  }

  .expense-table tfoot { display: none; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  h2 { font-size: 1.75rem; }
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  body { background: white; }
  .navbar, .form-actions, .col-actions { display: none; }
  .page-container {
    border: none;
    box-shadow: none;
    animation: none;
    margin: 0;
    padding: 1rem;
  }
  .page-container::before,
  .page-container::after { display: none; }
}