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

/* ── Tokens ── */
:root {
  --color-bg: #f9f6f1;
  --color-surface: #ffffff;
  --color-primary: #e36b2d;
  --color-primary-hover: #c85a20;
  --color-text: #1a1a1a;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --font: system-ui, -apple-system, sans-serif;
}

/* ── Base ── */
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

[hidden] {
  display: none !important;
}

/* ── Nav ── */
header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}

nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
}

.nav-links a {
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.nav-links a:hover {
  color: var(--color-primary);
}

/* ── Main layout ── */
main {
  flex: 1;
  min-height: 0; /* required for flex child to shrink below content size */
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: 1fr;
  gap: 1.5rem;
}

/* ── Map ── */
#map-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

#map {
  height: 100%;
}

.food-drop-marker {
  background: var(--color-primary);
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
}

.food-drop-marker:hover {
  background: var(--color-primary-hover);
}

.leaflet-popup-content a.popup-directions {
  background: var(--color-primary);
  border-radius: var(--radius);
  color: #ffffff;
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 0.75rem;
  padding: 0.45rem 0.7rem;
  text-align: center;
  text-decoration: none;
  width: 100%;
}

.leaflet-popup-content a.popup-directions:hover,
.leaflet-popup-content a.popup-directions:focus,
.leaflet-popup-content a.popup-directions:visited {
  background: var(--color-primary-hover);
  color: #ffffff;
}

/* ── Post list ── */
#post-list {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem;
}

.post-list-header {
  margin-bottom: 0.75rem;
}

#post-list h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

#posts {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.post-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.875rem;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.post-card:hover,
.post-card:focus-visible {
  border-color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(227, 107, 45, 0.16);
  outline: none;
  transform: translateY(-1px);
}

.post-card-active {
  border-color: var(--color-primary);
  box-shadow: inset 3px 0 0 var(--color-primary), 0 4px 12px rgba(227, 107, 45, 0.14);
}

.post-card-header {
  align-items: start;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.post-card h3 {
  color: var(--color-text);
  font-size: 1rem;
  line-height: 1.25;
}

.post-time-badge {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  color: #9a3412;
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  padding: 0.35rem 0.45rem;
  white-space: nowrap;
}

.post-card p {
  color: var(--color-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.post-card .post-location {
  color: var(--color-text);
  font-weight: 600;
  margin-top: 0.65rem;
}

.post-meta {
  margin-top: 0.25rem;
}

.post-empty {
  color: var(--color-muted);
  font-size: 0.9rem;
  line-height: 1.4;
  padding: 0.5rem 0;
}

/* ── Admin dashboard ── */
.admin-layout {
  display: block;
  overflow: auto;
}

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

.admin-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.admin-header p {
  color: var(--color-muted);
  font-size: 0.95rem;
}

button {
  border: 0;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0.625rem 0.875rem;
}

button:hover {
  background: var(--color-primary-hover);
}

.button-link {
  background: var(--color-primary);
  border-radius: var(--radius);
  color: #ffffff;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  padding: 0.625rem 0.875rem;
  text-decoration: none;
}

.button-link:hover,
.button-link:focus {
  background: var(--color-primary-hover);
}

.secondary-link {
  background: #f3f4f6;
  color: var(--color-text);
}

.secondary-link:hover,
.secondary-link:focus {
  background: #e5e7eb;
}

.admin-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.admin-dialog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
  left: 50%;
  margin: 0;
  max-width: 720px;
  padding: 1rem;
  position: fixed;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 2rem));
}

.admin-dialog::backdrop {
  background: rgba(17, 24, 39, 0.45);
}

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

.dialog-header h2 {
  font-size: 1.125rem;
}

.confirm-dialog {
  max-width: 420px;
}

.confirm-message {
  color: var(--color-text);
  font-size: 0.95rem;
}

.icon-button {
  align-items: center;
  background: transparent;
  color: var(--color-muted);
  display: inline-flex;
  font-size: 1.5rem;
  height: 2rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 2rem;
}

.icon-button:hover {
  background: #f3f4f6;
  color: var(--color-text);
}

.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  color: var(--color-muted);
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  font-weight: 700;
  gap: 0.375rem;
  text-transform: uppercase;
}

input,
select,
textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font: inherit;
  padding: 0.625rem 0.75rem;
  text-transform: none;
}

.password-field {
  display: block;
  position: relative;
}

.password-field input {
  padding-right: 3rem;
  width: 100%;
}

.password-toggle {
  align-items: center;
  background: transparent;
  border-radius: 50%;
  color: var(--color-muted);
  display: inline-flex;
  height: 2rem;
  justify-content: center;
  padding: 0;
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2rem;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: #f3f4f6;
  color: #4b5563;
}

.password-toggle svg {
  height: 1.15rem;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 1.15rem;
}

textarea {
  resize: vertical;
}

.form-wide {
  grid-column: 1 / -1;
}

.location-results {
  margin-top: -0.5rem;
}

#location-suggestions {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.5rem;
}

#location-suggestions:empty {
  border: 0;
  padding: 0;
}

#location-suggestions li {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.suggestion-button {
  background: #f9fafb;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.75rem;
  text-align: left;
  width: 100%;
}

.suggestion-button:hover {
  background: #f3f4f6;
}

.suggestion-button span {
  color: var(--color-muted);
  display: block;
  font-size: 0.85rem;
  font-weight: 400;
  margin-top: 0.25rem;
}

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

.secondary-button {
  background: #f3f4f6;
  color: var(--color-text);
}

.secondary-button:hover {
  background: #e5e7eb;
}

.danger-button {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.45rem 0.7rem;
}

.danger-button:hover {
  background: #fecaca;
}

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

.table-icon-button {
  align-items: center;
  background: #f3f4f6;
  color: var(--color-text);
  display: inline-flex;
  height: 2rem;
  justify-content: center;
  padding: 0;
  width: 2rem;
}

.table-icon-button:hover {
  background: #e5e7eb;
}

.table-icon-button.danger-button {
  background: #fee2e2;
  color: #991b1b;
}

.table-icon-button.danger-button:hover {
  background: #fecaca;
}

.table-icon-button svg {
  height: 1rem;
  width: 1rem;
}

.form-message {
  color: var(--color-muted);
  font-size: 0.9rem;
  margin-top: 0.75rem;
  min-height: 1.25rem;
}

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

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--color-border);
  padding: 0.875rem 1rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f3f4f6;
  color: var(--color-muted);
  font-size: 0.75rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  font-size: 0.9rem;
}

td span {
  color: var(--color-muted);
  display: block;
  margin-top: 0.25rem;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.status-badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 0;
  padding: 0.25rem 0.5rem;
  text-transform: uppercase;
}

.status-active {
  background: #dcfce7;
  color: #166534;
}

.status-inactive {
  background: #fee2e2;
  color: #991b1b;
}

/* ── Sign in ── */
.auth-layout {
  align-items: center;
  display: flex;
  justify-content: center;
  max-width: 960px;
  overflow: auto;
}

.auth-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  padding: 2rem;
  width: 100%;
}

.auth-panel-success {
  display: block;
  max-width: 560px;
}

.auth-panel-success .auth-copy {
  display: none;
}

.auth-copy {
  align-self: center;
}

.auth-kicker {
  color: var(--color-primary);
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
}

.auth-copy h1 {
  font-size: 2rem;
  line-height: 1.1;
  margin-bottom: 0.75rem;
}

.auth-copy p:not(.auth-kicker) {
  color: var(--color-muted);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 34rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-success {
  align-self: center;
  margin: 0 auto;
  max-width: 28rem;
  text-align: center;
}

.auth-success-icon {
  align-items: center;
  background: #dcfce7;
  border-radius: 50%;
  color: #166534;
  display: flex;
  height: 3rem;
  justify-content: center;
  margin: 0 auto 1rem;
  width: 3rem;
}

.auth-success-icon svg {
  height: 1.5rem;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
  width: 1.5rem;
}

.auth-success h1,
.auth-success h2 {
  color: var(--color-text);
  font-size: 1.5rem;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.auth-success p {
  color: var(--color-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

.password-requirement {
  color: var(--color-muted);
  font-size: 0.8rem;
  line-height: 1.4;
  margin-top: -0.5rem;
}

.auth-options {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.auth-options a {
  color: var(--color-primary);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.auth-options a:hover {
  color: var(--color-primary-hover);
}

.checkbox-label {
  align-items: center;
  flex-direction: row;
  font-size: 0.9rem;
  font-weight: 600;
  gap: 0.5rem;
  text-transform: none;
}

.checkbox-label input {
  accent-color: var(--color-primary);
  height: 1rem;
  width: 1rem;
}

.auth-note {
  color: var(--color-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: center;
}

.auth-note a,
.auth-note a:visited {
  color: var(--color-primary);
  font-weight: 800;
  text-decoration: none;
}

.auth-note a:hover,
.auth-note a:focus {
  color: var(--color-primary-hover);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    padding: 1rem;
  }

  #map-container {
    min-height: 45vh;
  }

  #post-list {
    max-height: none;
  }

  .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .auth-panel {
    grid-template-columns: 1fr;
    padding: 1.25rem;
  }

  .auth-copy h1 {
    font-size: 1.6rem;
  }
}
