:root {
  --navy: #1f3a5f;
  --navy-dark: #16293f;
  --teal: #1aa39a;
  --gold: #d99a18;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2530;
  --muted: #6b7785;
  --border: #dce1e7;
  --danger: #c0392b;
  --ok: #1e824c;
  --radius: 12px;
  --tap: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(76px + env(safe-area-inset-bottom));
}

/* Header */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-head h1 { font-size: 1.5rem; margin: 0; color: var(--navy); }
.head-date { color: var(--muted); font-size: 0.95rem; }

.logout-form { margin: 0; }
.logout-btn {
  background: none; border: none; font-size: 1.4rem;
  color: var(--muted); cursor: pointer; padding: 6px 10px;
}

/* Forms */
label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin: 14px 0 6px;
  color: var(--navy);
}
.optional { font-weight: 400; color: var(--muted); }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font-size: 1.05rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
}

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7785' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.amount-wrap { position: relative; }
.amount-wrap .rupee {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 1.2rem; color: var(--muted); pointer-events: none;
}
.amount-wrap input { padding-left: 34px; font-size: 1.3rem; font-weight: 600; }

/* Save button */
.save-btn {
  width: 100%;
  min-height: 56px;
  margin-top: 22px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
}
.save-btn:active { background: var(--navy-dark); }
.save-btn:disabled { opacity: 0.65; cursor: not-allowed; }
.save-btn.small { min-height: 46px; margin-top: 0; font-size: 1rem; width: auto; padding: 0 18px; }

.form-msg { margin-top: 14px; text-align: center; font-weight: 600; min-height: 22px; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }

/* Flash */
.flash-wrap { margin-bottom: 12px; }
.flash {
  padding: 12px 14px; border-radius: var(--radius); margin-bottom: 8px; font-weight: 600;
}
.flash-success { background: #e6f4ec; color: var(--ok); }
.flash-error { background: #fdecea; color: var(--danger); }

/* Recent */
.recent { margin-top: 28px; }
.recent h2, section h2 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.recent-list .r-time { color: var(--muted); }
.recent-list .r-cc { font-weight: 600; }
.recent-list .r-amt { font-weight: 700; color: var(--navy); text-align: right; }
.recent-list .r-note { grid-column: 1 / 3; color: var(--muted); }
.recent-list .r-pm { font-size: 0.75rem; color: var(--teal); text-align: right; }
.recent-list .empty, .empty { color: var(--muted); font-style: italic; }
.see-all { display: inline-block; margin-top: 12px; color: var(--teal); text-decoration: none; font-weight: 600; }

/* Total card */
.total-card {
  background: var(--navy); color: #fff; border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 2px; margin-bottom: 18px;
}
.total-label { font-size: 0.85rem; opacity: 0.8; }
.total-value { font-size: 1.8rem; font-weight: 800; }
.total-count { font-size: 0.85rem; opacity: 0.8; }

/* Entry list */
.entry-list, .group-list, .cc-list { list-style: none; padding: 0; margin: 0; }
.entry {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px;
}
.entry-top { display: flex; justify-content: space-between; align-items: baseline; }
.e-cc { font-weight: 700; color: var(--navy); }
.e-amt { font-weight: 800; }
.entry-bot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; color: var(--muted); font-size: 0.88rem; }
.e-pm { color: var(--teal); }
.entry-actions { display: flex; gap: 14px; margin-top: 10px; }
.entry-actions form { margin: 0; }
.edit-toggle, .del-btn, .link-btn {
  background: none; border: none; font-size: 0.9rem; font-weight: 600; cursor: pointer; padding: 4px 0;
}
.edit-toggle { color: var(--teal); }
.del-btn, .link-btn.danger { color: var(--danger); }
.link-btn.ok { color: var(--ok); }
.link-btn { color: var(--teal); }
.edit-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.edit-form input[name="amount"] { width: 110px; }
.edit-form input[name="note"] { flex: 1; min-width: 140px; }

/* Groups */
.group-list li {
  display: flex; justify-content: space-between; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.g-amt { font-weight: 700; color: var(--navy); }

/* Filters */
.filter-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filter-form input, .filter-form select { flex: 1; min-width: 120px; min-height: 46px; }

/* Cost center page */
.cc-add-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: stretch; }
.cc-add-form input { flex: 1; min-width: 150px; }
.cc-add-form select { width: auto; }
.cc-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.cc-item.inactive { opacity: 0.55; }
.cc-edit { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.cc-edit input { flex: 1; min-width: 140px; min-height: 44px; }
.cc-edit select { width: auto; min-height: 44px; }
.cc-item form { margin: 0; }

/* Login */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--card); border-radius: 16px; padding: 28px 22px; width: 100%; max-width: 360px; box-shadow: 0 4px 20px rgba(0,0,0,0.06); }
.login-card h1 { color: var(--navy); margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin: 0 0 18px; }

/* Error page */
.error-wrap { text-align: center; padding-top: 60px; }
.error-wrap h1 { font-size: 4rem; color: var(--navy); margin: 0; }
.error-wrap p { color: var(--muted); margin-bottom: 24px; }
.error-wrap .save-btn { display: inline-block; width: auto; padding: 0 24px; text-decoration: none; line-height: 56px; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.bottom-nav a {
  flex: 1; text-align: center; padding: 8px 0; text-decoration: none;
  color: var(--muted); font-size: 0.72rem; display: flex; flex-direction: column; gap: 2px;
}
.bottom-nav a.active { color: var(--navy); font-weight: 700; }
.nav-icon { font-size: 1.2rem; line-height: 1; }
