:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #5d6571;
  --border: #d9dde3;
  --accent: #2459c7;
  --accent-text: #ffffff;
  --error-bg: #fdecec;
  --error-text: #a51d1d;
  --notice-bg: #fff4d6;
  --notice-text: #6b4b00;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2127;
    --text: #e6e8eb;
    --muted: #9aa2ad;
    --border: #343a43;
    --accent: #6f9cff;
    --accent-text: #0d1117;
    --error-bg: #3a1d1f;
    --error-text: #ffb4b4;
    --notice-bg: #3a3118;
    --notice-text: #f3d68a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.user-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.username { color: var(--muted); }

.inline-form { display: inline; margin: 0; }

.content {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.login-card { max-width: 24rem; margin: 2rem auto; }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }

.muted { color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 0.4rem; }
.stack button { margin-top: 0.8rem; }

input[type="text"], input[type="password"], input[type="search"], input[type="date"], select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  padding: 0.55rem 1rem;
  font: inherit;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.link-button {
  padding: 0;
  color: var(--accent);
  background: none;
  text-decoration: underline;
}

.error {
  padding: 0.6rem 0.8rem;
  color: var(--error-text);
  background: var(--error-bg);
  border-radius: var(--radius);
}

/* --- search ------------------------------------------------------------------ */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.search-form { display: flex; gap: 0.5rem; }
.search-form input { flex: 1; min-width: 0; }

/* htmx's own indicator style is disabled (it would be an inline <style>). */
.htmx-indicator { visibility: hidden; margin: 0.4rem 0 0; font-size: 0.9rem; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { visibility: visible; }

.notice {
  padding: 0.6rem 0.8rem;
  background: var(--notice-bg);
  color: var(--notice-text);
  border-radius: var(--radius);
}

.results { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.results li { border-top: 1px solid var(--border); }
.results li:first-child { border-top: 0; }
.results a {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 1rem;
  justify-content: space-between;
  padding: 0.6rem 0.25rem;
  color: var(--text);
  text-decoration: none;
}
.results a:hover, .results a:focus-visible { background: var(--bg); }
.hit-name { font-weight: 500; color: var(--accent); }
.hit-company { color: var(--muted); }

/* --- contact page ------------------------------------------------------------ */

.fields {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  margin: 0;
}
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.normalized { color: var(--muted); font-size: 0.9rem; }

.raw { margin-top: 1.5rem; }
.raw summary { cursor: pointer; color: var(--accent); margin-bottom: 0.75rem; }

@media (max-width: 30rem) {
  .fields { grid-template-columns: 1fr; gap: 0.1rem; }
  .fields dd { margin-bottom: 0.6rem; }
}

/* --- admin log ----------------------------------------------------------------- */

.content-wide { max-width: 80rem; }

.small { font-size: 0.85rem; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.9rem; color: var(--muted); }
.field-wide { grid-column: span 2; }
.filter-actions { display: flex; align-items: center; gap: 1rem; }

.log-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
}

/* Wide tables scroll sideways on narrow screens instead of breaking the layout. */
.table-scroll { overflow-x: auto; }

.log-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.log-table th, .log-table td {
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.log-table th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.log-table tbody tr:hover { background: var(--bg); }
.log-table .num { text-align: right; }
.log-table .query { min-width: 12rem; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.event-login_fail { color: var(--error-text); }

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

@media (max-width: 30rem) {
  .field-wide { grid-column: auto; }
}
