/* ===========================================================
   Sun City Membership App — Stylesheet
   Brand: Maroon #6B1A2C (primary) / Gold #C9A84C (accent, sparing)
   Status row colors are FIXED — never themed to brand colors.
   =========================================================== */

:root {
  /* Brand */
  --maroon: #6B1A2C;
  --maroon-dark: #531421;
  --maroon-tint: #F4E8EA;     /* very light maroon wash, for subtle highlights */
  --gold: #C9A84C;
  --gold-dark: #A8893A;
  --gold-tint: #FBF5E6;

  /* Neutrals */
  --ink: #2A2B2E;             /* body text */
  --ink-soft: #5B5D63;        /* secondary text */
  --line: #E2DED7;            /* borders / dividers */
  --surface: #FFFFFF;
  --bg: #F5F3EF;              /* soft off-white app background */

  /* Status colors — fixed, do not theme */
  --status-active: #C6EFCE;
  --status-pending: #FFEB9C;
  --status-follow_up: #F4B942;
  --status-completed: #BDD7EE;
  --status-cancelled: #FFC7CE;

  /* Status text colors — chosen for AA contrast against each status bg */
  --status-active-text: #1E5631;
  --status-pending-text: #6B5500;
  --status-follow_up-text: #5C3A00;
  --status-completed-text: #1B3A66;
  --status-cancelled-text: #7A1F2B;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(42, 27, 17, 0.06), 0 1px 1px rgba(42, 27, 17, 0.04);
  --shadow-md: 0 4px 16px rgba(42, 27, 17, 0.10);
  --shadow-lg: 0 12px 40px rgba(42, 27, 17, 0.18);

  --ease: 200ms ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[x-cloak] { display: none !important; }

button, select, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===================== HEADER ===================== */

.app-header {
  background: var(--maroon);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header__logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: var(--maroon-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.app-header__title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.app-header__name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.app-header__subtitle {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.75);
}

.app-header__user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: rgba(255, 255, 255, 0.92);
}

.app-header__user-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
}

.app-header__user-loading {
  color: rgba(255, 255, 255, 0.6);
  font-style: italic;
}

/* ===================== TOOLBAR ===================== */

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  flex-wrap: wrap;
}

.search-field {
  position: relative;
  flex: 1 1 360px;
  max-width: 560px;
  display: flex;
  align-items: center;
}

.search-field__icon {
  position: absolute;
  left: 16px;
  color: var(--ink-soft);
  pointer-events: none;
}

.search-field__input {
  width: 100%;
  padding: 13px 40px 13px 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  font-size: 15px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--ease), box-shadow var(--ease);
}

.search-field__input::placeholder { color: #9B978F; }

.search-field__input:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.28);
}

.search-field__clear {
  position: absolute;
  right: 10px;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--ease);
}

.search-field__clear:hover { background: var(--line); }

.filter-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-field__label {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  white-space: nowrap;
}

.filter-field__select {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.filter-field__select:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.28);
}

.filter-field__select--active {
  border-color: var(--maroon);
  box-shadow: 0 0 0 2px rgba(107, 26, 44, 0.12);
}

.toolbar__count {
  margin-left: auto;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* ===================== MAIN / TABLE ===================== */

.app-main {
  flex: 1;
  padding: 0 24px 32px;
}

.table-wrap {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--line);
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.contacts-table thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  background: var(--bg);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.contact-row {
  cursor: pointer;
  transition: background-color var(--ease), filter var(--ease);
  border-bottom: 1px solid rgba(42, 27, 17, 0.06);
}

.contact-row:hover { filter: brightness(0.97); }
.contact-row:last-child { border-bottom: none; }

.contact-row td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--ink);
}

.contact-row__name { font-weight: 600; }

.status-active     { background: var(--status-active); }
.status-pending     { background: var(--status-pending); }
.status-follow_up   { background: var(--status-follow_up); }
.status-completed   { background: var(--status-completed); }
.status-cancelled   { background: var(--status-cancelled); }

.status-select {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(42, 27, 17, 0.18);
  background: rgba(255, 255, 255, 0.65);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.status-select:hover { background: rgba(255, 255, 255, 0.9); }

.status-select:focus-visible {
  outline: none;
  border-color: var(--gold-dark);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.35);
}

/* Status badges used in the History timeline */
.status-badge--active     { background: var(--status-active);    color: var(--status-active-text); }
.status-badge--pending    { background: var(--status-pending);   color: var(--status-pending-text); }
.status-badge--follow_up  { background: var(--status-follow_up); color: var(--status-follow_up-text); }
.status-badge--completed  { background: var(--status-completed); color: var(--status-completed-text); }
.status-badge--cancelled  { background: var(--status-cancelled); color: var(--status-cancelled-text); }

/* ===================== STATE PANELS (loading / empty / error) ===================== */

.state-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 56px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.state-panel__spinner { margin-bottom: 4px; }

.spin-circle {
  transform-origin: center;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.state-panel__icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--maroon-tint);
  color: var(--maroon);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

.state-panel__icon--gold {
  background: var(--gold-tint);
  color: var(--gold-dark);
}

.state-panel--error .state-panel__icon {
  background: #FBE7E9;
  color: #9A2436;
}

.state-panel__text {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.state-panel__subtext {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 0 0 6px;
}

/* ===================== BUTTONS ===================== */

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--primary {
  background: var(--maroon);
  color: #FFFFFF;
}

.btn--primary:hover:not(:disabled) {
  background: var(--gold-dark);
  color: #2A1B0E;
}

.btn--primary:active:not(:disabled) { transform: translateY(1px); }

.btn--ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.btn--ghost:hover { background: var(--bg); }

.btn--sm { padding: 8px 14px; font-size: 13px; }

/* ===================== SLIDE-OUT PANEL ===================== */

.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 18, 13, 0.32);
  z-index: 30;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 420px;
  max-width: 92vw;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 31;
  transform: translateX(100%);
  transition: transform 280ms ease;
  display: flex;
  flex-direction: column;
}

.side-panel--open { transform: translateX(0); }

.side-panel__inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.side-panel__header {
  background: var(--maroon);
  color: #FFFFFF;
  padding: 20px 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.side-panel__header-text h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.side-panel__header-text p {
  margin: 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.78);
}

.side-panel__close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #FFFFFF;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--ease);
}

.side-panel__close:hover { background: rgba(255, 255, 255, 0.24); }

.side-panel__tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
}

.side-panel__tab {
  background: none;
  border: none;
  padding: 14px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--ease), border-color var(--ease);
}

.side-panel__tab:hover { color: var(--ink); }

.side-panel__tab--active {
  color: var(--maroon);
  border-bottom-color: var(--gold);
}

.side-panel__content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-panel__hint {
  font-size: 13.5px;
  color: var(--ink-soft);
  text-align: center;
  padding: 18px 0;
}

/* ---- Notes ---- */

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  position: relative;
}

.note-card__meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}

.note-card__author {
  font-weight: 700;
  color: var(--maroon);
}

.note-card__time { color: var(--ink-soft); white-space: nowrap; }
.note-card__edited { font-style: italic; }

.note-card__body {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.note-card__edit-link {
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--gold-dark);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.note-card__edit-link:hover { text-decoration: underline; }

.note-card__edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-card__edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.note-textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 14px;
  resize: vertical;
  background: var(--surface);
  transition: border-color var(--ease), box-shadow var(--ease);
}

.note-textarea:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.28);
}

.note-composer {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-composer .btn { align-self: flex-end; }

/* ---- History timeline (signature element) ---- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 4px;
  position: relative;
}

.timeline__item {
  position: relative;
  padding: 0 0 22px 24px;
  border-left: 2px solid var(--gold-tint);
}

.timeline__item:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}

.timeline__dot {
  position: absolute;
  left: -7px;
  top: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--maroon);
  border: 2px solid var(--gold);
}

.timeline__change {
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
}

.timeline__badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.timeline__arrow { color: var(--ink-soft); }

.timeline__meta {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ===================== RESPONSIVE ===================== */

@media (max-width: 900px) {
  .toolbar { padding: 16px; }
  .app-main { padding: 0 16px 24px; }
  .app-header { padding: 12px 16px; }
  .toolbar__count { margin-left: 0; }
  .contacts-table { font-size: 13px; }
  .contacts-table thead th,
  .contact-row td { padding: 10px 12px; }
}

@media (max-width: 720px) {
  .table-wrap { overflow-x: auto; }
  .contacts-table { min-width: 760px; }
  .side-panel { width: 100%; max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
