/* Dashboard & auth styling. Card-based, functional, dense — per NFR-4 this
   look is deliberately plain; the elegant editorial aesthetic is reserved
   for the guest-facing invitation page built in later phases. */

:root {
  --color-bg: #f5f4f1;
  --color-surface: #ffffff;
  --color-border: #e4e1da;
  --color-text: #26241f;
  --color-text-muted: #6f6b60;
  /* Darkened from the original #a8763e (WCAG AA pass, Phase 10) — same
     reasoning as guest.css's --guest-accent: the lighter gold only hit
     ~3.9:1 against white, below AA's 4.5:1 for normal text/button labels.
     The hover shade is darkened to match, so it still reads as "darker
     than the resting state" rather than lighter. */
  --color-accent: #7e582e;
  --color-accent-hover: #6d4c28;
  --color-danger: #b3261e;
  --color-danger-bg: #fbeae9;
  --color-success: #2e6b3e;
  --color-success-bg: #e9f5ec;
  --color-sidebar-bg: #1f1d19;
  --color-sidebar-text: #d9d5cb;
  --color-sidebar-text-active: #ffffff;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Sinhala", "Noto Sans Tamil", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  margin: 0 0 0.5em;
  font-weight: 600;
}

p {
  margin: 0 0 1em;
}

/* ---------- Buttons & forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  padding: 0.65em 1.2em;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.btn-block {
  width: 100%;
}

.form-group {
  margin-bottom: 1.2em;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9em;
  margin-bottom: 0.4em;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="datetime-local"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.7em 0.85em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1em;
  font-family: inherit;
  background: #fff;
  color: var(--color-text);
}

.form-group textarea {
  resize: vertical;
  min-height: 5em;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ---------- Alerts / flash messages ---------- */

.alert {
  padding: 0.8em 1em;
  border-radius: var(--radius);
  font-size: 0.9em;
  margin-bottom: 1.2em;
}

.alert-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* ---------- Auth page (login) ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
}

.auth-card h1 {
  font-size: 1.3em;
  text-align: center;
  margin-bottom: 1.4em;
}

.auth-brand {
  text-align: center;
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: 0.4em;
  letter-spacing: 0.02em;
}

/* ---------- App shell (dashboards) ---------- */

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

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  font-weight: 700;
  color: #fff;
  font-size: 1.05em;
  margin-bottom: 1.8rem;
  padding: 0 0.5rem;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar nav a,
.sidebar nav span {
  display: block;
  padding: 0.6em 0.7em;
  border-radius: var(--radius);
  color: var(--color-sidebar-text);
  font-size: 0.92em;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.sidebar nav a.active {
  background: var(--color-accent);
  color: #fff;
}

.sidebar nav span.disabled {
  color: rgba(217, 213, 203, 0.45);
  cursor: default;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9em;
}

.topbar-user form {
  margin: 0;
}

.topbar-user .btn {
  padding: 0.45em 0.9em;
  font-size: 0.85em;
}

.topbar-locale {
  display: flex;
  gap: 0.2em;
  background: var(--color-bg);
  border-radius: 999px;
  padding: 0.2em;
}

.topbar-locale button {
  border: none;
  background: transparent;
  padding: 0.3em 0.7em;
  border-radius: 999px;
  font-size: 0.82em;
  font-family: inherit;
  color: var(--color-text-muted);
  cursor: pointer;
}

.topbar-locale button.active {
  background: var(--color-accent);
  color: #fff;
}

.content {
  padding: 2rem;
  flex: 1;
}

/* ---------- Cards & stats ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .stat-value {
  font-size: 1.8em;
  font-weight: 700;
}

.stat-card .stat-label {
  color: var(--color-text-muted);
  font-size: 0.85em;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
}

.empty-state h2 {
  color: var(--color-text);
  font-size: 1.1em;
}

.badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  font-size: 0.75em;
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-muted);
}

.badge-active {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-suspended {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* ---------- Buttons: extra variants ---------- */

.btn-link-plain {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.85em;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
  padding: 0;
}

.btn-link-plain:hover {
  color: var(--color-text);
}

.btn-sm {
  padding: 0.4em 0.8em;
  font-size: 0.82em;
}

.btn-danger {
  background: transparent;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

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

/* ---------- Page header ---------- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
}

/* ---------- One-time credentials box ---------- */

.credentials-box {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.credentials-box h2 {
  color: var(--color-success);
  font-size: 1em;
  margin-bottom: 0.3em;
}

.credentials-box p {
  font-size: 0.88em;
  color: var(--color-text-muted);
  margin-bottom: 1em;
}

.credential-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.6em 0.9em;
  margin-bottom: 0.6em;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.credential-row:last-child {
  margin-bottom: 0;
}

.credential-row .credential-label {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.8em;
  color: var(--color-text-muted);
  min-width: 70px;
}

.credential-row .credential-value {
  flex: 1;
  word-break: break-all;
}

/* ---------- Data tables ---------- */

.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 0.75em 1em;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9em;
  white-space: nowrap;
}

table.data-table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table tbody tr:hover {
  background: var(--color-bg);
}

.row-actions {
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
}

.row-actions form {
  margin: 0;
  display: inline;
}

/* ---------- Forms: multi-column ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 1.5rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.field-error {
  color: var(--color-danger);
  font-size: 0.82em;
  margin-top: 0.3em;
}

.field-help {
  color: var(--color-text-muted);
  font-size: 0.82em;
  margin: 0.3em 0 0;
}

/* ---------- Tab navigation ---------- */

.tab-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}

.tab-nav a {
  padding: 0.7em 1em;
  color: var(--color-text-muted);
  font-size: 0.92em;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-nav a:hover {
  color: var(--color-text);
  text-decoration: none;
}

.tab-nav a.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* ---------- Repeatable rows (contacts, events) ---------- */

.repeat-row {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--color-bg);
}

.repeat-row .form-group:last-child {
  margin-bottom: 0.8em;
}

/* ---------- Prefixed input (e.g. "#hashtag") ---------- */

.input-prefix {
  display: flex;
  align-items: stretch;
}

.input-prefix span {
  display: flex;
  align-items: center;
  padding: 0 0.7em;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--color-text-muted);
  font-size: 0.95em;
}

.input-prefix input {
  border-radius: 0 var(--radius) var(--radius) 0 !important;
}

/* ---------- Small layout utilities ----------
   The CSP (style-src 'self') blocks inline style="" attributes, so every
   one-off spacing tweak needs a real class instead. Keep this list short —
   reach for an existing component class first. */

.mt-md {
  margin-top: 1rem;
}

.mt-lg {
  margin-top: 1.5rem;
}

.mb-lg {
  margin-bottom: 1.5rem;
}

.mb-sm {
  margin-bottom: 0.6rem;
}

.align-self-end {
  align-self: end;
}

.mt-pull-sm {
  margin-top: -0.5em;
}

.text-center {
  text-align: center;
}

.justify-center {
  justify-content: center;
}

.field-note {
  color: var(--color-text-muted);
  font-size: 0.85em;
  margin-top: -0.7em;
  margin-bottom: 1em;
}

.subsection-heading {
  margin-top: 1.5rem;
  font-size: 1em;
}

.card-heading {
  font-size: 1em;
  margin-bottom: 1rem;
}

.wish-message {
  margin: 0 0 0.4em;
  white-space: pre-line;
}

.wish-meta {
  margin: 0 0 0.8em;
}

/* ---------- Invitation Template tab: mode picker ---------- */

.mode-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.mode-option {
  display: flex;
  gap: 0.7em;
  align-items: flex-start;
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
}

/* .selected is set by app.js on every change — :has() would do the same
   job on its own in modern browsers, but isn't supported before Safari
   15.4, and this project targets iOS 15+. */
.mode-option.selected,
.mode-option:has(input:checked) {
  border-color: var(--color-accent);
  background: var(--color-bg);
}

.mode-option input {
  margin-top: 0.25em;
  flex-shrink: 0;
}

.mode-option strong {
  display: block;
  margin-bottom: 0.3em;
  font-size: 0.95em;
}

.mode-option p {
  margin: 0;
  font-size: 0.83em;
  color: var(--color-text-muted);
}

.mode-panel {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--color-bg);
  border-radius: var(--radius);
}

.template-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.template-option {
  cursor: pointer;
  text-align: center;
  font-size: 0.85em;
  display: block;
}

.template-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.template-option img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--radius);
  border: 2px solid var(--color-border);
  margin-bottom: 0.4em;
}

.template-option input:checked + img {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent);
}

.current-card-preview {
  display: block;
  max-width: 240px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  margin-bottom: 0.8rem;
}

/* ---------- Admin template library ---------- */

.template-admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
}

.template-admin-card {
  padding: 0.75rem;
}

.template-admin-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 0.6em;
}

.template-admin-name {
  display: block;
  font-size: 0.92em;
  margin-bottom: 0.3em;
}

/* ---------- Drag-and-drop name-overlay editor ---------- */

.overlay-editor {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 2rem;
  align-items: start;
}

.overlay-canvas-wrap {
  position: sticky;
  top: 1rem;
}

.overlay-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background-size: cover;
  background-position: center;
  background-color: var(--color-bg);
  background-repeat: no-repeat;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  user-select: none;
}

.overlay-box {
  position: absolute;
  cursor: move;
  padding: 0.3em;
  box-sizing: border-box;
  border: 1px dashed rgba(255, 255, 255, 0.75);
}

.overlay-text {
  display: block;
  margin: 0;
  overflow-wrap: break-word;
}

.overlay-resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--color-accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: ew-resize;
}

.overlay-form h3:first-of-type {
  margin-top: 0.5rem;
}

@media (max-width: 900px) {
  .overlay-editor {
    grid-template-columns: 1fr;
  }

  .overlay-canvas-wrap {
    position: static;
  }
}

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 1rem;
  }

  .sidebar-brand {
    display: none;
  }

  .sidebar nav {
    flex-direction: row;
  }

  .content {
    padding: 1.25rem;
  }
}

/* ---------- Photo gallery manager (Phase 8) ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.photo-card {
  position: relative;
  border: 1px solid var(--border-color, #e0ddd6);
  border-radius: 10px;
  background: #fff;
  padding: 0.6rem;
  cursor: grab;
}

.photo-card.dragging {
  opacity: 0.4;
}

.photo-thumb {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.photo-cover-badge {
  position: absolute;
  top: 0.9rem;
  left: 0.9rem;
}

.photo-caption-form {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.photo-caption-form input {
  flex: 1;
  min-width: 0;
  padding: 0.4em 0.6em;
  border: 1px solid #d8d4cb;
  border-radius: 6px;
  font-size: 0.85em;
}

/* ---------- Music picker (Phase 8) ---------- */

audio {
  width: 100%;
  margin-top: 0.4em;
}

/* ---------- Analytics charts (Phase 9) ---------- */

.chart-svg {
  width: 100%;
  height: 140px;
  display: block;
}

.chart-bar {
  fill: var(--brand-accent, #a8763e);
}

/* ---------- Impersonation banner (Phase 9) ---------- */

.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: #3a2a12;
  color: #f7ecd9;
  font-size: 0.9em;
}

.impersonation-banner form {
  margin: 0;
}

/* ---------- Brand footer ("Built by SynaSolution") ---------- */

.brand-footer {
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.8em;
  color: var(--color-text-muted);
}

.brand-footer p {
  margin: 0;
}

.brand-footer a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}

.brand-footer a:hover {
  text-decoration: underline;
}

.brand-footer-sep {
  margin: 0 0.4em;
  color: var(--color-border);
}

/* On the login page the footer sits below the centered card, not inside it
   — see .auth-page's flex-direction: column (added for this). */
.auth-page .brand-footer {
  width: 100%;
}
