/* ---- Palette ---- */
:root {
  --charcoal-dark:  #1b140f;
  --charcoal:       #241b14;
  --charcoal-light: #34281d;
  --cream:          #f3ead9;
  --cream-light:    #fbf6ec;
  --ink:            #2a2118;
  --gold:           #c9a463;
  --gold-light:     #e0c594;
  --gold-deep:      #a07e44;
  --gold-dim:       rgba(201, 164, 99, 0.35);
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--cream);
  min-height: 100vh;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
}

a { color: var(--gold-deep); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--gold); }

/* ---- Nav ---- */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: var(--charcoal-dark);
  color: var(--cream);
  gap: 1rem;
  border-bottom: 1px solid var(--gold-dim);
}
.nav-brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  color: var(--gold-light);
}
.nav-version {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.7rem;
  letter-spacing: normal;
  color: #a0906f;
}
.logout-form { display: inline; }
.nav-links { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.nav-links a { color: #d8c9ab; font-size: 0.92rem; letter-spacing: 0.01em; }
.nav-links a:hover { color: var(--gold-light); text-decoration: none; }
.btn-link {
  background: none; border: none; cursor: pointer;
  color: #d8c9ab; font-size: 0.92rem; padding: 0;
}
.btn-link:hover { color: var(--gold-light); }

/* ---- Main ---- */
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem; }
.login-page main { max-width: none; margin: 0; padding: 0; }

/* ---- Alerts ---- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.alert-success { background: #eaf3df; color: #3f5c1f; border: 1px solid #c8dba5; }
.alert-error   { background: #f6e3df; color: #8a3324; border: 1px solid #e3b3a3; }
.login-page .alert {
  position: absolute;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: 90%;
  white-space: nowrap;
}

/* ---- Buttons ---- */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-block;
  padding: 0.45rem 1rem;
  border-radius: 5px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary  {
  background: linear-gradient(180deg, var(--gold-light), var(--gold-deep));
  color: var(--charcoal-dark);
  border-color: var(--gold-deep);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); }
.btn-secondary { background: var(--cream-light); color: var(--ink); border-color: var(--gold-dim); }
.btn-secondary:hover { background: #ece1cb; }
.btn-danger   { background: #b3503d; color: #fff; border-color: #963f2e; }
.btn-danger:hover { background: #963f2e; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ---- Page header ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap;
}
.page-header h1 { margin: 0; }

/* ---- Search form ---- */
.search-form {
  display: flex; gap: 0.5rem; align-items: center;
  margin-bottom: 1.5rem; flex-wrap: wrap;
}
.search-form input[type=search] {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--gold-dim);
  border-radius: 5px;
  font-size: 0.95rem;
  width: 320px;
  max-width: 100%;
  background: var(--cream-light);
  color: var(--ink);
}

/* ---- Resident grid (directory) ---- */
.resident-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ---- Resident list (unit manage view) ---- */
.resident-list { display: flex; flex-direction: column; gap: 1rem; }
.resident-list .resident-card { display: flex; align-items: flex-start; gap: 1rem; }

/* ---- Resident card ---- */
.resident-card {
  background: var(--cream-light);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  gap: 1rem;
}
.resident-grid .resident-card {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.resident-grid .resident-card:hover,
.resident-grid .resident-card:focus-visible {
  border-color: var(--gold);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}
.resident-photo { flex-shrink: 0; }
.resident-photo img {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 50%;
}
.photo-placeholder {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--gold-dim);
  color: var(--charcoal-dark);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 1.75rem; font-weight: 600;
}
.resident-info { flex: 1; min-width: 0; }
.resident-info h2 { font-size: 1.05rem; margin-bottom: 0.25rem; }
.resident-info p  { font-size: 0.9rem; color: #5c4f3f; margin-top: 0.2rem; }
.bio { white-space: pre-wrap; }
.unit-badge {
  display: inline-block;
  background: var(--gold-dim); color: var(--gold-deep);
  font-size: 0.78rem; font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  margin-bottom: 0.4rem;
}
.contact { font-style: italic; }

/* ---- Resident detail (full profile) ---- */
.resident-detail {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  background: var(--cream-light);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  padding: 1.5rem;
}
.resident-detail-photo { flex-shrink: 0; }
.resident-detail-photo img {
  width: 200px; height: 200px;
  object-fit: cover;
  border-radius: 50%;
}
.photo-placeholder-lg {
  width: 200px; height: 200px;
  font-size: 4rem;
}
.resident-detail-info { flex: 1; min-width: 0; }
.resident-detail-info h1 { margin-bottom: 0.4rem; }
.resident-actions {
  display: flex; flex-direction: column; gap: 0.4rem;
  align-items: flex-end; flex-shrink: 0;
}

/* ---- Forms ---- */
.form-container { max-width: 420px; margin: 2rem auto; }
.form-wide      { max-width: 660px; }
.form-container h1 { margin-bottom: 1.25rem; font-size: 1.4rem; }
.form-container label, .form-wide label {
  display: block; font-size: 0.88rem; font-weight: 600;
  color: #5c4f3f; margin-top: 1rem; margin-bottom: 0.3rem;
}
.form-container input, .form-wide input,
.form-container textarea, .form-wide textarea,
.form-container select, .form-wide select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gold-dim);
  border-radius: 5px;
  font-size: 0.95rem;
  background: var(--cream-light);
  color: var(--ink);
}
.form-container textarea, .form-wide textarea { resize: vertical; }
.form-container button[type=submit] { margin-top: 1.25rem; width: 100%; padding: 0.6rem; font-size: 1rem; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
.hint { font-size: 0.82rem; color: #8a7a64; margin-top: 0.25rem; }
.current-photo { margin-bottom: 0.5rem; }
.current-photo-img { max-width: 120px; border-radius: 4px; }

.photo-editor {
  margin: 0.6rem 0 1rem;
  padding: 0.85rem;
  background: var(--charcoal);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
}
.photo-editor-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  touch-action: none;
}
.photo-editor-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  border-radius: 4px;
  touch-action: none;
  cursor: crosshair;
}
.photo-editor-canvas-wrap canvas.dragging-move { cursor: move; }
.photo-editor-canvas-wrap canvas.dragging-resize-nw,
.photo-editor-canvas-wrap canvas.dragging-resize-se { cursor: nwse-resize; }
.photo-editor-canvas-wrap canvas.dragging-resize-ne,
.photo-editor-canvas-wrap canvas.dragging-resize-sw { cursor: nesw-resize; }
.photo-editor-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.photo-editor-spacer { flex: 1; }

/* ---- Tags ---- */
.tag-list { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--gold-dim);
  color: var(--gold-deep);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}
.tag-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gold-deep);
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
}
.tag-chip-remove:hover { color: var(--charcoal-dark); }

.tag-input {
  position: relative;
  border: 1px solid var(--gold-dim);
  border-radius: 5px;
  background: var(--cream-light);
  padding: 0.5rem 0.75rem;
}
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.tag-input .tag-text-input {
  border: none;
  padding: 0.2rem 0;
  background: transparent;
}
.tag-input .tag-text-input:focus { outline: none; }
.tag-suggestions {
  display: none;
  position: absolute;
  left: 0; right: 0; top: 100%;
  z-index: 10;
  background: var(--cream-light);
  border: 1px solid var(--gold-dim);
  border-radius: 5px;
  margin-top: 2px;
  max-height: 180px;
  overflow-y: auto;
}
.tag-suggestions.visible { display: block; }
.tag-suggestion-item {
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.tag-suggestion-item:hover { background: var(--gold-dim); }

/* ---- Admin table ---- */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--cream-light);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.9rem;
}
.admin-table th {
  background: #ece1cb;
  text-align: left;
  padding: 0.6rem 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--gold-dim);
}
.admin-table td {
  padding: 0.55rem 1rem;
  border-bottom: 1px solid #ece1cb;
}
.admin-table tr:last-child td { border-bottom: none; }
.badge {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  background: var(--gold-dim); color: var(--gold-deep);
  padding: 0.1rem 0.45rem; border-radius: 999px; margin-left: 0.3rem;
}

/* ---- Empty state ---- */
.empty-state { color: #8a7a64; font-style: italic; margin-top: 1rem; }

/* ---- Login screen ---- */
.login-screen {
  position: relative;
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: url('img/stone-arch-landing.png');
  background-size: cover;
  background-position: center 60%;
  background-repeat: no-repeat;
  padding: 1.5rem;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 2.25rem 2rem 2rem;
  background: rgba(20, 15, 10, 0.78);
  border: 1px solid var(--gold-dim);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.sa-monogram {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--gold-light);
}

.sa-divider {
  width: 70px;
  height: 1px;
  background: var(--gold-dim);
  margin: 0.85rem auto 1.5rem;
  position: relative;
}
.sa-divider::after {
  content: "◆";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.5rem;
  color: var(--gold);
  background: rgba(20, 15, 10, 0.78);
  padding: 0 0.4rem;
}

.login-card .input-group {
  position: relative;
  margin-bottom: 1.1rem;
}

.login-card .input-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--gold);
  pointer-events: none;
}

.login-card input {
  width: 100%;
  padding: 0.75rem 0.9rem 0.75rem 2.6rem;
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--cream-light);
  font-size: 0.95rem;
  font-family: var(--font-body);
}
.login-card input::placeholder { color: #b9ab93; }
.login-card input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

.btn-login {
  width: 100%;
  padding: 0.8rem;
  margin-top: 0.5rem;
  border: 1px solid var(--gold-deep);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--gold-light), var(--gold-deep));
  color: var(--charcoal-dark);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}
.btn-login:hover { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); }
