/* ============================================================
   GRANÖGÅRDS SAMFÄLLIGHETSFÖRENING — Global Styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&display=swap');
@import './variables.css';

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--color-ink);
  background-color: var(--color-bg);
  min-height: 100vh;
  padding-top: var(--navbar-height);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
}

img, video {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--color-pine);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-pine-mid);
}

/* --- Layout --- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

.container--prose {
  max-width: var(--container-prose);
}

/* --- Page Header --- */
.page-header {
  padding: var(--space-4) 0 var(--space-8);
}

.page-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--color-ink);
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
}

.page-subtitle {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  color: var(--color-muted);
  margin-top: var(--space-2);
  font-weight: var(--weight-regular);
  font-style: italic;
}

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.card--elevated {
  box-shadow: var(--shadow-md);
  border-color: transparent;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast), box-shadow var(--transition-fast),
              transform var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn--primary:hover {
  background: var(--color-pine-mid);
  border-color: var(--color-pine-mid);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

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

.btn--secondary:hover {
  background: var(--color-pine-light);
  border-color: var(--color-pine-mid);
  color: var(--color-pine-mid);
  box-shadow: var(--shadow-sm);
}

.btn--tertiary,
.btn--ghost {
  background: transparent;
  color: #303030;
  border-color: transparent;
}

.btn--tertiary svg,
.btn--ghost svg {
  color: #303030;
  fill: currentColor;
  stroke: currentColor;
}

.btn--tertiary:hover,
.btn--ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-ink);
}

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

.btn--danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

.btn--sm {
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
}

.btn--lg {
  font-size: var(--text-base);
  padding: var(--space-4) var(--space-8);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* --- Form Elements --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-ink);
}

.form-input,
.form-select,
.form-textarea {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  appearance: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-subtle);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-pine);
  box-shadow: 0 0 0 3px rgba(44, 74, 53, 0.12);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-subtle);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.badge--green  { background: var(--color-success-light); color: var(--color-success); }
.badge--red    { background: var(--color-danger-light);  color: var(--color-danger);  }
.badge--amber  { background: var(--color-warning-light); color: var(--color-warning); }
.badge--blue   { background: var(--color-info-light);    color: var(--color-info);    }
.badge--pine   { background: var(--color-pine-light);    color: var(--color-pine);    }

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--color-border);
  border: none;
  margin: var(--space-6) 0;
}

/* --- Toast / Alerts --- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  border: 1px solid transparent;
}

.alert--success { background: var(--color-success-light); color: #14532d; border-color: #bbf7d0; }
.alert--danger  { background: var(--color-danger-light);  color: #7f1d1d; border-color: #fecaca; }
.alert--info    { background: var(--color-info-light);    color: #1e3a8a; border-color: #bfdbfe; }
.alert--warning { background: var(--color-warning-light); color: #78350f; border-color: #fed7aa; }

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead {
  background: var(--color-surface-alt);
}

th {
  font-weight: var(--weight-semibold);
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: var(--text-xs);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--color-surface-alt);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--color-muted);
}

.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-ink);
  margin-bottom: var(--space-2);
}

/* --- Modal --- */

/* Overlay — covers everything including the navbar */
.modal-overlay {
  display: none; /* shown by JS */
  position: fixed;
  inset: 0;
  z-index: 600; /* above navbar (500) */
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  /* Two-layer bg: dark scrim fades in */
  background: rgba(0, 0, 0, 0);
  transition: background var(--transition-slow);
}

.modal-overlay.is-open {
  display: flex;
  background: rgba(0, 0, 0, 0.55);
}

/* Panel */
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  /* Desktop: fade + subtle lift */
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}

/* Size variants — control max-width on desktop */
.modal--small { max-width: 400px; }
.modal--base  { max-width: 580px; }
.modal--large { max-width: 780px; }

.modal-overlay.is-open .modal {
  opacity: 1;
  transform: translateY(0);
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border-light);
}

.modal__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

.modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-muted);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.modal__close:hover {
  color: var(--color-ink);
  background: var(--color-surface-alt);
}

/* Body content — padding defaults to 16px desktop, overridden by padding attr */
.modal__body {
  font-size: var(--text-sm);
  color: var(--color-muted);
  line-height: var(--leading-relaxed);
  padding: var(--space-6);
}

.modal__body h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-ink);
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

.modal__body h3:first-child { margin-top: 0; }

.modal__body ul, .modal__body ol {
  padding-left: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.modal__body li { list-style: disc; }
.modal__body ol li { list-style: decimal; }
.modal__body ul ul { margin-top: var(--space-2); }
.modal__body ul ul li { list-style: circle; }

.modal__body p { margin-bottom: var(--space-3); }
.modal__body p:last-child { margin-bottom: 0; }

.modal__body strong { color: var(--color-ink); font-weight: var(--weight-semibold); }

/* Navbar hides when modal opens */
.navbar--hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}

/* --- Mobile: slide-up sheet --- */
@media (max-width: 639px) {
  .modal-overlay {
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-width: 100% !important; /* override all size variants on mobile */
    max-height: calc(100vh - var(--space-12));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    /* Slide up from below */
    opacity: 1;
    transform: translateY(100%);
    transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  .modal-overlay.is-open .modal {
    transform: translateY(0);
    opacity: 1;
  }

  .modal__header {
    padding: var(--space-4) var(--space-4);
  }

  /* Default body padding on mobile — matches the header's side padding */
  .modal__body {
    padding: var(--space-4);
  }

}

/* --- Keyboard open (JS adds .is-keyboard + sets --vv-top / --vv-height) ---
   The iOS keyboard overlays the layout viewport without shrinking it, so a
   vh-sized sheet extends behind the keyboard with nothing to scroll. Fit the
   overlay to the visual viewport instead: the sheet is capped to the visible
   area and its body becomes scrollable to reach content under the keyboard. */
.modal-overlay.is-keyboard {
  top: var(--vv-top, 0);
  height: var(--vv-height, 100%);
  bottom: auto;
}
.modal-overlay.is-keyboard .modal {
  max-height: calc(100% - var(--space-12));
}
/* The keyboard's rounded top corners leave slivers where the page shows
   through. Fixed elements render underneath the keyboard, so extend a solid
   panel from the bottom of the visual viewport to the bottom of the screen. */
.modal-overlay.is-keyboard::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  top: calc(var(--vv-top, 0px) + var(--vv-height, 0px));
  bottom: 0;
  background: var(--color-bg);
  pointer-events: none;
}

/* --- Skeleton loader --- */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border) 50%, var(--color-surface-alt) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Admin highlight --- */
.admin-editable {
  position: relative;
  outline: 2px dashed transparent;
  border-radius: var(--radius-sm);
  transition: outline-color var(--transition-fast);
}

.admin-editable:hover {
  outline-color: var(--color-accent);
  cursor: pointer;
}

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.text-muted { color: var(--color-muted); }
.text-sm    { font-size: var(--text-sm); }
.text-xs    { font-size: var(--text-xs); }
.font-medium { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }

.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2      { gap: var(--space-2); }
.gap-3      { gap: var(--space-3); }
.gap-4      { gap: var(--space-4); }
.gap-6      { gap: var(--space-6); }
.mt-4       { margin-top: var(--space-4); }
.mt-6       { margin-top: var(--space-6); }
.mt-8       { margin-top: var(--space-8); }
.w-full     { width: 100%; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .container {
    padding-inline: var(--space-4);
  }

  .page-title {
    font-size: var(--text-2xl);
  }

}
