/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #1a1a2e;
  background: #f5f7fa;
  line-height: 1.5;
}

a { color: #4361ee; text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navbar === */
.navbar {
  background: #1a1a2e;
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}
.navbar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  white-space: nowrap;
}
.navbar .nav-links {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.navbar .nav-links a { color: #a9b4d4; font-size: 0.875rem; }
.navbar .nav-links a:hover { color: #fff; text-decoration: none; }

/* === Nav dropdowns === */
.nav-group { position: relative; }
.nav-group-btn {
  background: none; border: none; cursor: pointer;
  color: #a9b4d4; font-size: 0.875rem; padding: 0;
  font-family: inherit; line-height: inherit;
}
.nav-group-btn:hover { color: #fff; }
.nav-dropdown {
  display: none;
  position: absolute; top: 100%; left: 0;
  background: #1a1a2e; border: 1px solid #2d2d44;
  border-radius: 6px; min-width: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  z-index: 200; padding: 0.5rem 0 0.35rem;
}
.nav-dropdown a {
  display: block; padding: 0.45rem 1rem;
  color: #a9b4d4; font-size: 0.875rem; white-space: nowrap;
}
.nav-dropdown a:hover { color: #fff; background: #2d2d44; text-decoration: none; }
.nav-group:hover .nav-dropdown,
.nav-group:focus-within .nav-dropdown { display: block; }

/* === Container === */
.container {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

h1 { font-size: 1.6rem; margin-bottom: 1rem; color: #1a1a2e; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 0.6rem; color: #2d2d44; }
.subtitle { color: #666; margin-top: -0.5rem; margin-bottom: 1rem; }

/* === Alerts === */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-left: 4px solid #4361ee;
}
.stat-card.income { border-left-color: #10b981; }
.stat-card.expense { border-left-color: #ef4444; }
.stat-label { font-size: 0.75rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; }

/* === Tables === */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 1.5rem;
}
th {
  background: #f1f5f9;
  text-align: left;
  padding: 0.6rem 0.9rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
}
td {
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.inactive-row td { opacity: 0.5; }
.row-warning td { background: #fef9c3; }
.total-row td { background: #f1f5f9; font-weight: 600; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-paid    { background: #d1fae5; color: #065f46; }
.badge-unpaid  { background: #fee2e2; color: #991b1b; }
.badge-partial { background: #fef3c7; color: #92400e; }
.badge-sent    { background: #d1fae5; color: #065f46; }
.badge-failed  { background: #fee2e2; color: #991b1b; }
.badge-unknown { background: #f1f5f9; color: #6b7280; }

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 0.45rem 1rem;
  background: #4361ee;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: #3451d1; text-decoration: none; color: #fff; }
.btn-outline {
  background: transparent;
  color: #4361ee;
  border: 1px solid #4361ee;
}
.btn-outline:hover { background: #4361ee; color: #fff; }
.btn-danger { background: #ef4444; }
.btn-danger:hover { background: #dc2626; }
.btn-warn { background: #f59e0b; }
.btn-warn:hover { background: #d97706; }
.btn-active { background: #1a1a2e; }
.btn-dialpad { background: #7c3aed; }
.btn-dialpad:hover { background: #6d28d9; color: #fff; text-decoration: none; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

/* === Forms === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 150px;
}
.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.45rem 0.7rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  background: #fff;
  color: #1a1a2e;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #4361ee;
  box-shadow: 0 0 0 2px rgba(67,97,238,0.15);
}
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.filter-form, .inline-form {
  background: #fff;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 1.5rem;
}

/* === Misc === */
.section { margin-bottom: 2rem; }
.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.ok-msg { color: #10b981; font-weight: 600; margin-bottom: 1rem; }
.income-text { color: #10b981; }
.expense-text { color: #ef4444; }

.report-nav { margin-bottom: 1.5rem; display: flex; gap: 0.5rem; }
.report-section { background: #fff; padding: 1.5rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.report-table { margin-bottom: 1rem; }
.net-row { font-size: 1.3rem; font-weight: 700; margin-top: 1rem; padding: 0.5rem 0; border-top: 2px solid #e2e8f0; }

/* === Conversations List === */
.convo-list {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
  max-width: 700px;
}
.convo-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid #f1f5f9;
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}
.convo-row:last-child { border-bottom: none; }
.convo-row:hover { background: #f8fafc; text-decoration: none; }
.convo-unread { background: #eff6ff; }
.convo-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: #4361ee;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.convo-meta { flex: 1; min-width: 0; }
.convo-header-row { display: flex; justify-content: space-between; align-items: baseline; }
.convo-name { font-weight: 600; font-size: 0.925rem; }
.convo-time { font-size: 0.75rem; color: #9ca3af; white-space: nowrap; }
.convo-sub-row { display: flex; justify-content: space-between; align-items: center; margin-top: 0.1rem; }
.convo-preview { font-size: 0.8rem; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 380px; }
.convo-you { color: #374151; font-weight: 500; }
.convo-no-msg { font-style: italic; }
.convo-badge {
  background: #4361ee; color: #fff;
  border-radius: 999px; font-size: 0.7rem; font-weight: 700;
  padding: 0.1rem 0.45rem; min-width: 18px; text-align: center; flex-shrink: 0;
}
.convo-prop { font-size: 0.72rem; color: #9ca3af; margin-top: 0.15rem; }

/* === Thread layout === */
.thread-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.25rem;
  height: calc(100vh - 120px);
}
.thread-sidebar {
  display: flex;
  flex-direction: column;
}
.tenant-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  text-align: center;
  flex: 1;
}
.tenant-avatar-lg {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #4361ee;
  color: #fff;
  font-weight: 700;
  font-size: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 0.6rem;
}
.tenant-card-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.25rem; }
.tenant-card-detail { font-size: 0.78rem; color: #6b7280; margin-bottom: 0.15rem; }

.thread-main {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
}
.thread-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* === Chat bubbles === */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: #f8fafc;
}
.chat-empty { text-align: center; color: #9ca3af; margin-top: 2rem; font-size: 0.875rem; }
.dialpad-banner {
  background: #f5f3ff;
  border-bottom: 1px solid #ede9fe;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: #5b21b6;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.dialpad-banner a { color: #7c3aed; font-weight: 600; }
.bubble-row { display: flex; }
.bubble-out { justify-content: flex-end; }
.bubble-in  { justify-content: flex-start; }
.bubble {
  max-width: 68%;
  padding: 0.55rem 0.85rem;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}
.bubble-sent {
  background: #4361ee;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-recv {
  background: #fff;
  color: #1a1a2e;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}
.bubble-time {
  font-size: 0.65rem;
  margin-top: 0.25rem;
  opacity: 0.65;
  text-align: right;
}

/* === Chat input === */
.chat-input-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #f1f5f9;
  background: #fff;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  padding: 0.5rem 0.9rem;
  font-size: 0.875rem;
  resize: none;
  line-height: 1.4;
  font-family: inherit;
}
.chat-input:focus { outline: none; border-color: #4361ee; box-shadow: 0 0 0 2px rgba(67,97,238,0.15); }
.chat-send-btn { border-radius: 20px; padding: 0.5rem 1.2rem; align-self: flex-end; }

@media (max-width: 700px) {
  .thread-layout { grid-template-columns: 1fr; height: auto; }
  .thread-sidebar { display: none; }
}

/* === Transactions inline-edit table === */
.txn-wrap { overflow-x: auto; }

.txn-table {
  table-layout: fixed;
  font-size: 0.8rem;
  min-width: 860px;
}
.txn-table th, .txn-table td {
  padding: 0.4rem 0.55rem;
  overflow: hidden;
  white-space: nowrap;
}
.txn-table .col-date     { width: 88px; }
.txn-table .col-desc     { width: 20%; }
.txn-table .col-amount   { width: 78px; text-align: right; }
.txn-table .col-cat      { width: 13%; }
.txn-table .col-prop     { width: 11%; }
.txn-table .col-tenant   { width: 9%; }
.txn-table .col-notes    { width: 13%; }
.txn-table .col-job      { width: 11%; }
.txn-table .col-inv      { width: 52px; }

.txn-table .col-desc td-content,
.txn-desc {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Controls look like plain text until the row is hovered */
.inline-select, .inline-text {
  width: 100%;
  border: none;
  background: transparent;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  padding: 1px 2px;
  outline: none;
  cursor: pointer;
  border-radius: 3px;
  display: block;
}
.inline-text  { cursor: text; }
.inline-check { cursor: pointer; }

.txn-table tr:hover .inline-select,
.txn-table tr:hover .inline-text {
  background: #eef1fd;
}
.inline-select:focus,
.inline-text:focus {
  background: #fff;
  outline: 2px solid #4361ee;
}

/* === Print === */
@media print {
  .navbar, .btn, .filter-form, form { display: none !important; }
  body { background: white; }
  table { box-shadow: none; }
}

@media (max-width: 600px) {
  .section-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* === Auto-classification indicator === */
.auto-badge {
  display: inline-block;
  font-size: 0.58rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  letter-spacing: 0.03em;
  vertical-align: middle;
  margin-right: 3px;
  cursor: default;
}

/* === Bank Badges === */
.bank-badge { display:inline-block; font-size:0.6rem; font-weight:700; padding:2px 5px; border-radius:6px; letter-spacing:0.03em; white-space:nowrap; }
.bank-chase  { background:#dbeafe; color:#1d4ed8; }
.bank-tnb    { background:#dcfce7; color:#15803d; }
.bank-pb     { background:#fee2e2; color:#b91c1c; }
.bank-other  { background:#f1f5f9; color:#475569; }
.txn-table .col-bank { width: 44px; }

/* === Role Badges === */
.role-badge { display:inline-block; font-size:0.6rem; font-weight:700;
              padding:2px 6px; border-radius:10px; letter-spacing:0.03em; }
.role-owner       { background:#1e3a5f; color:#fff; }
.role-manager     { background:#dbeafe; color:#1d4ed8; }
.role-bookkeeper  { background:#dcfce7; color:#15803d; }
.role-maintenance { background:#fef3c7; color:#92400e; }
.role-investor    { background:#f3e8ff; color:#7e22ce; }

/* === Nav Company === */
.nav-company { display:flex; align-items:center; }
.company-btn { color:#7dd3a8 !important; font-weight:600 !important; }
.company-btn:hover { color:#a7f3d0 !important; }
.company-label { color:#7dd3a8; font-size:0.875rem; font-weight:600; }

/* === Nav User === */
.nav-user { margin-left:auto; display:flex; align-items:center; gap:0.75rem; color:#a9b4d4; font-size:0.85rem; }
.nav-logout { background:none; border:1px solid #4a5568; color:#a9b4d4;
              border-radius:4px; padding:2px 10px; cursor:pointer; font-size:0.8rem; }
.nav-logout:hover { color:#fff; border-color:#a9b4d4; }

/* === SMS Button === */
.sms-btn {
  background:none; border:none; cursor:pointer; padding:0 0 0 4px;
  color:#4361ee; vertical-align:middle; line-height:1; opacity:0.65;
  display:inline-flex; align-items:center;
}
.sms-btn:hover { opacity:1; }

/* === Modal === */
.modal-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.45);
  display:flex; align-items:center; justify-content:center; z-index:1000;
}
.modal-box {
  background:#fff; border-radius:10px;
  box-shadow:0 8px 32px rgba(0,0,0,0.18);
  width:100%; max-width:420px; margin:1rem;
}
.modal-header {
  display:flex; justify-content:space-between; align-items:center;
  padding:0.85rem 1.25rem; border-bottom:1px solid #f1f5f9;
}
.modal-close {
  background:none; border:none; cursor:pointer;
  font-size:1rem; color:#6b7280; padding:0 0.2rem; line-height:1;
}
.modal-close:hover { color:#1a1a2e; }

/* === Approval Workflow === */
.badge-locked  { background:#1e3a5f; color:#fff; border-radius:10px; padding:2px 8px; font-size:0.72rem; font-weight:600; white-space:nowrap; }
.badge-flagged { background:#fef3c7; color:#92400e; border-radius:10px; padding:2px 8px; font-size:0.72rem; font-weight:600; white-space:nowrap; }
.badge-bk      { background:#dcfce7; color:#15803d; border-radius:10px; padding:2px 8px; font-size:0.72rem; font-weight:600; white-space:nowrap; }
.locked-row td { background:#f0f7f0 !important; }
.bulk-bar {
  position:fixed; bottom:0; left:0; right:0; background:#1a1a2e; color:#fff;
  padding:0.65rem 1.5rem; display:flex; align-items:center; gap:0.75rem;
  z-index:500; box-shadow:0 -2px 8px rgba(0,0,0,0.2); flex-wrap:wrap;
}
.bulk-bar.hidden { display:none; }
.bulk-bar .btn { font-size:0.8rem; padding:0.3rem 0.7rem; }
.bulk-count { font-weight:600; margin-right:0.25rem; }
