/* Security Deposit Ledger — dark old-money theme */
:root {
  --bg: #13211A;
  --bg-deep: #0D1712;
  --bg-card: #1A2B22;
  --bg-card-2: #20362A;
  --ivory: #F5F2E8;
  --ivory-dim: #CFC9B8;
  --gold: #B49A5B;
  --gold-bright: #D6BE85;
  --oxblood: #5C2A2A;
  --green: #3E6B4F;
  --amber: #C99A3C;
  --red: #B04A3A;
  --line: rgba(180, 154, 91, 0.28);
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ivory);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, .serif {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(180deg, #0D1712 0%, #13211A 100%);
  border-bottom: 1px solid var(--line);
  padding: 1.4rem 1.25rem 1rem;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-header .brand {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.8rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.15rem;
}

.app-header h1 {
  font-size: 2rem;
  color: var(--ivory);
  font-weight: 600;
}

.app-header .tagline {
  font-size: 0.85rem;
  color: var(--ivory-dim);
  font-style: italic;
  margin-top: 0.15rem;
}

/* ---------- Tab nav ---------- */
.tabs {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  padding: 0.85rem 1rem;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 49;
  flex-wrap: wrap;
}

.tab {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.02rem;
  letter-spacing: 0.06em;
  background: transparent;
  color: var(--ivory-dim);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.45rem 1.15rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.tab:hover { color: var(--ivory); border-color: var(--line); }

.tab.active {
  color: #13211A;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  border-color: var(--gold);
  font-weight: 700;
  box-shadow: 0 2px 12px rgba(180, 154, 91, 0.35);
}

/* ---------- Layout ---------- */
main {
  max-width: 1060px;
  margin: 0 auto;
  padding: 1.5rem 1.1rem 4rem;
}

.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.section-title {
  font-size: 1.55rem;
  color: var(--gold-bright);
  margin: 0.4rem 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}

/* ---------- Cards & stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.6rem;
}

.stat-card {
  background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), transparent);
}

.stat-card .label {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ivory-dim);
  margin-bottom: 0.35rem;
}

.stat-card .value {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--ivory);
  line-height: 1.1;
}

.stat-card .sub {
  font-size: 0.82rem;
  color: var(--ivory-dim);
  margin-top: 0.25rem;
}

.card {
  background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card h3 {
  font-size: 1.3rem;
  color: var(--gold-bright);
  margin-bottom: 0.7rem;
}

/* ---------- Tenant rows ---------- */
.tenant-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.95rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: 0.7rem;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.tenant-row:hover {
  border-color: var(--gold);
  transform: translateX(2px);
}

.tenant-row .avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), #8a7440);
  color: #13211A;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 700;
  font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.tenant-row .who { flex: 1; min-width: 0; }
.tenant-row .who .name { font-size: 1.12rem; color: var(--ivory); }
.tenant-row .who .meta { font-size: 0.83rem; color: var(--ivory-dim); }

.tenant-row .money { text-align: right; flex-shrink: 0; }
.tenant-row .money .amt {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.35rem; font-weight: 700; color: var(--ivory);
}
.tenant-row .money .lbl { font-size: 0.75rem; color: var(--ivory-dim); letter-spacing: 0.08em; text-transform: uppercase; }

/* ---------- Status chips & deadlines ---------- */
.chip {
  display: inline-block;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  border: 1px solid;
  font-weight: 700;
  white-space: nowrap;
}

.chip.held   { color: #9fd8ae; border-color: #3E6B4F; background: rgba(62, 107, 79, 0.18); }
.chip.partial{ color: #e8c877; border-color: var(--amber); background: rgba(201, 154, 60, 0.14); }
.chip.returned{ color: var(--ivory-dim); border-color: var(--line); background: rgba(255,255,255,0.04); }

.deadline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-bottom: 0.6rem;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.deadline.amber { border-color: var(--amber); background: rgba(201, 154, 60, 0.08); }
.deadline.red   { border-color: var(--red); background: rgba(176, 74, 58, 0.10); }

.deadline .d-name { font-size: 1.02rem; }
.deadline .d-when { font-size: 0.85rem; color: var(--ivory-dim); }
.deadline.amber .d-when { color: #e8c877; font-weight: 700; }
.deadline.red .d-when { color: #e08a78; font-weight: 700; }

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--ivory-dim);
  font-style: italic;
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ivory-dim);
  margin-bottom: 0.35rem;
}

.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ivory);
  padding: 0.65rem 0.8rem;
  font-size: 1rem;
  font-family: Georgia, serif;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(180, 154, 91, 0.25);
}

.field .hint { font-size: 0.78rem; color: var(--ivory-dim); font-style: italic; margin-top: 0.25rem; }

/* ---------- Buttons ---------- */
.btn {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 10px;
  padding: 0.7rem 1.5rem;
  cursor: pointer;
  border: 1px solid var(--gold);
  transition: all 0.16s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: #13211A;
  border-color: var(--gold);
  box-shadow: 0 3px 14px rgba(180, 154, 91, 0.3);
}

.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--gold-bright);
  border-color: var(--line);
}

.btn-ghost:hover { border-color: var(--gold); color: var(--gold-bright); }

.btn-danger {
  background: transparent;
  color: #e08a78;
  border-color: rgba(176, 74, 58, 0.5);
}

.btn-danger:hover { border-color: var(--red); }

.btn-row { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Deduction builder ---------- */
.ded-row {
  display: grid;
  grid-template-columns: 1fr 130px 34px;
  gap: 0.6rem;
  align-items: end;
  margin-bottom: 0.6rem;
}

.ded-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--line);
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold-bright);
}

.settlement {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin-top: 1rem;
}

.settlement .s-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.98rem;
}

.settlement .s-row.grand {
  border-top: 1px solid var(--gold);
  margin-top: 0.5rem;
  padding-top: 0.7rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gold-bright);
}

/* ---------- Letter preview ---------- */
.letter {
  background: #F5F2E8;
  color: #2C2C2C;
  border-radius: 6px;
  padding: 2.2rem 2.4rem;
  font-family: Georgia, serif;
  box-shadow: var(--shadow);
  max-width: 720px;
  margin: 1rem auto;
}

.letter h2 {
  font-family: "Cormorant Garamond", Georgia, serif;
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1.4rem;
  color: #13211A;
}

.letter p { margin-bottom: 0.8rem; font-size: 0.98rem; }

.letter table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.letter th, .letter td {
  border: 1px solid #B49A5B;
  padding: 0.5rem 0.7rem;
  text-align: left;
}

.letter th { background: #13211A; color: #F5F2E8; font-family: "Cormorant Garamond", Georgia, serif; letter-spacing: 0.06em; }
.letter td.num, .letter th.num { text-align: right; }

.letter .sig { margin-top: 2rem; }
.letter .sig-line { border-top: 1px solid #2C2C2C; width: 240px; margin-top: 2.2rem; padding-top: 0.3rem; font-size: 0.85rem; }

/* ---------- Detail drawer ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.7rem;
  margin: 1rem 0;
}

.detail-item {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
}

.detail-item .k {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ivory-dim);
}

.detail-item .v {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ivory);
}

/* ---------- Notice / NJ note ---------- */
.notice {
  border-left: 3px solid var(--gold);
  background: rgba(180, 154, 91, 0.08);
  padding: 0.85rem 1.1rem;
  border-radius: 0 10px 10px 0;
  font-size: 0.92rem;
  color: var(--ivory-dim);
  margin: 1rem 0;
}

.notice strong { color: var(--gold-bright); }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  color: var(--ivory-dim);
  font-size: 0.82rem;
  border-top: 1px solid var(--line);
  font-style: italic;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 12, 0.72);
  backdrop-filter: blur(3px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 4vh 1rem;
  overflow-y: auto;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: linear-gradient(165deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border: 1px solid var(--gold);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  width: 100%;
  max-width: 620px;
  padding: 1.6rem 1.7rem;
  animation: fadeIn 0.22s ease;
}

.modal h3 {
  font-size: 1.5rem;
  color: var(--gold-bright);
  margin-bottom: 1rem;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--bg-card-2);
  border: 1px solid var(--gold);
  color: var(--ivory);
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  font-size: 0.95rem;
  z-index: 200;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .app-header, .tabs, .app-footer, .btn-row, .no-print, .toast, .modal-backdrop { display: none !important; }
  main { max-width: 100%; padding: 0; }
  .view { display: none !important; }
  .view.active { display: block !important; }
  .view.active > .card, .view.active > .section-title { display: none !important; }
  #letter-preview { display: block !important; }
  .letter { box-shadow: none; border-radius: 0; margin: 0; max-width: 100%; }
  .card { box-shadow: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app-header h1 { font-size: 1.55rem; }
  .tenant-row { flex-wrap: wrap; }
  .tenant-row .money { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; }
  .ded-row { grid-template-columns: 1fr 110px 34px; }
  .letter { padding: 1.4rem 1.1rem; }
  .stat-card .value { font-size: 1.6rem; }
}
