:root {
  --bg: #0f1720;
  --panel: #16212c;
  --panel-border: #26333f;
  --text: #e7edf3;
  --muted: #93a3b2;
  --accent: #4da3ff;
  --accent-2: #35c48f;
  --danger: #ef5b5b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.muted { color: var(--muted); }

/* ---- Auth ---- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.auth-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(77, 163, 255, 0.12);
  border: 1px solid rgba(77, 163, 255, 0.35);
  color: var(--accent);
  margin-bottom: 14px;
}
.auth-logo-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  margin-bottom: 0;
}
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-form { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.auth-form input {
  background: #0f1720;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-form button {
  margin-top: 6px;
  background: var(--accent);
  color: #05131f;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 15px;
}
.auth-form button:hover { filter: brightness(1.08); }
.error-banner {
  background: rgba(239, 91, 91, 0.12);
  border: 1px solid var(--danger);
  color: #ffb3b3;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 16px;
}

/* ---- Layout ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar-sub { font-weight: 600; }
.logout-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.logout-link:hover { color: var(--text); }

.topnav { display: flex; gap: 6px; }
.topnav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
}
.topnav-link:hover { color: var(--text); }
.topnav-link.active { background: rgba(77, 163, 255, 0.15); color: var(--accent); font-weight: 600; }

.dashboard { max-width: 1100px; margin: 0 auto; padding: 22px; display: flex; flex-direction: column; gap: 22px; }

.fees-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.fees-filters { display: flex; gap: 8px; }
.fees-filters select, .fees-filters input {
  background: #0f1720;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
}

.fees-table th, .fees-table td { vertical-align: top; }
.contact-links { display: flex; flex-direction: column; gap: 4px; }
.icon-btn {
  display: inline-block;
  text-decoration: none;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #1d2b38;
  color: var(--text);
  white-space: nowrap;
}
.icon-btn.call { color: var(--accent); }
.icon-btn.wa { color: var(--accent-2); }
.icon-btn:hover { filter: brightness(1.2); }

.status-select, .date-input, .notes-input {
  background: #0f1720;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
}
.notes-input { min-width: 160px; min-height: 44px; resize: vertical; font-family: inherit; }
.date-input.due-soon { border-color: var(--danger); color: #ff9d9d; }
.save-btn {
  background: var(--accent);
  color: #05131f;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.save-btn:hover { filter: brightness(1.08); }
.save-btn:disabled { opacity: 0.7; cursor: default; }
.due-soon-text { color: #ff9d9d; font-weight: 600; }

/* ---- Follow-up modal ---- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 780px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  background: var(--accent);
  color: #05131f;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
}
.modal-close { background: none; border: none; color: #05131f; font-size: 20px; cursor: pointer; line-height: 1; }
.modal-body { display: flex; gap: 20px; padding: 18px; overflow-y: auto; }
.modal-form-col { flex: 1; min-width: 0; }
.modal-summary-col {
  width: 220px;
  flex-shrink: 0;
  background: #0f1720;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.7;
}
.modal-summary-col h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.form-row label { flex: 1; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.form-row input, .form-row select {
  background: #0f1720;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
}

.timeline-heading { font-size: 13px; color: var(--muted); margin: 18px 0 10px; }
.timeline { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.timeline-entry { display: flex; gap: 10px; padding-bottom: 14px; position: relative; }
.timeline-entry:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 13px;
  top: 28px;
  bottom: -4px;
  width: 2px;
  background: var(--panel-border);
}
.timeline-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #05131f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  z-index: 1;
}
.timeline-content { font-size: 13px; padding-top: 3px; }
.timeline-date { color: var(--muted); font-size: 12px; margin-bottom: 2px; }

@media (max-width: 640px) {
  .modal-body { flex-direction: column; }
  .modal-summary-col { width: auto; }
  .form-row { flex-direction: column; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 94vh; border-radius: 14px 14px 0 0; }
}

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 20px; font-weight: 700; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.panel h2 { margin: 0 0 14px; font-size: 16px; }

.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.events-table { width: 100%; min-width: 540px; border-collapse: collapse; font-size: 13px; }
.fees-table { min-width: 820px; }
.events-table th, .events-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: top;
}
.events-table th { color: var(--muted); font-weight: 600; }
.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status-pill.ok { background: rgba(53, 196, 143, 0.15); color: var(--accent-2); }
.status-pill.bad { background: rgba(239, 91, 91, 0.15); color: #ff9d9d; }

.chat-panel { display: flex; flex-direction: column; gap: 12px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 360px; overflow-y: auto; }
.chat-msg { padding: 10px 13px; border-radius: 10px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; max-width: 90%; }
.chat-msg.ai { background: #1d2b38; align-self: flex-start; }
.chat-msg.user { background: #14405f; align-self: flex-end; }
.chat-form { display: flex; gap: 10px; }
.chat-form input {
  flex: 1;
  background: #0f1720;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.chat-form input:focus { outline: none; border-color: var(--accent); }
.chat-form button {
  background: var(--accent);
  color: #05131f;
  border: none;
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 640px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Home: welcome + module tiles ---- */
.welcome-panel h2 { margin: 0 0 4px; }
.welcome-panel p { margin: 0; }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.module-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.module-tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.module-tile-icon {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(77, 163, 255, 0.12);
  color: var(--accent);
}
.module-tile.admin-tile .module-tile-icon { background: rgba(53, 196, 143, 0.12); color: var(--accent-2); }
.module-tile-title { font-weight: 600; font-size: 15px; margin-bottom: 3px; }
.module-tile-desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.module-tile-arrow { margin-left: auto; color: var(--muted); flex-shrink: 0; }

/* ---- Users & Roles page ---- */
.pill-tag {
  display: inline-block;
  background: rgba(77, 163, 255, 0.12);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  margin: 1px 3px 1px 0;
}
.icon-only-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: #1d2b38;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 7px;
  cursor: pointer;
  margin-right: 6px;
}
.icon-only-btn:hover { filter: brightness(1.2); }
.icon-only-btn.danger { color: #ff9d9d; }
.icon-only-btn.danger:hover { background: rgba(239, 91, 91, 0.12); border-color: var(--danger); }

.module-checkboxes { display: flex; flex-direction: column; gap: 8px; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.link-btn {
  display: inline-block;
  margin-top: 18px;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }

/* ---- Mobile: touch targets stay >=40px tall, layout stacks/scrolls
   instead of squeezing, and the topnav becomes a horizontal scroller so
   the topbar never wraps into a messy multi-line header. ---- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 12px 14px; row-gap: 8px; }
  .topbar-title { order: 1; }
  .logout-link { order: 2; }
  .topnav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .topnav-link { white-space: nowrap; }

  .dashboard { padding: 14px; gap: 16px; }
  .panel { padding: 16px; }
  .auth-card { padding: 26px 20px; }

  .fees-toolbar { flex-direction: column; align-items: stretch; }
  .fees-filters { flex-direction: column; }
  .fees-filters select, .fees-filters input { width: 100%; }

  .contact-links { flex-direction: row; flex-wrap: wrap; }
  .icon-btn { padding: 7px 10px; font-size: 13px; }

  .module-grid { grid-template-columns: 1fr; }

  .auth-form input, .auth-form button,
  .form-row input, .form-row select,
  .save-btn, .icon-only-btn { font-size: 16px; }
}
