* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #f2f3f5;
  color: #1a1a1a;
}

.hidden { display: none !important; }

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem 0; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem 0; }

/* Login screen */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: #fff;
  padding: 2rem;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  width: 320px;
}

.login-box form {
  display: flex;
  flex-direction: column;
  margin-top: 1rem;
}

/* Dashboard layout */
.topbar {
  background: #1f2937;
  color: #fff;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-bar {
  background: #fff;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid #ddd;
}

/* Cards flow into as many columns as the window fits (one column on narrow screens). */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  grid-auto-flow: row dense; /* smaller cards fill gaps left beside taller ones */
  gap: 1.25rem;
  align-items: start;
  max-width: 1800px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

.card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1.25rem;
  min-width: 0; /* lets wide content (tables) scroll instead of stretching the grid */
}

/* Cards that need the full row, e.g. the employee table */
.card-wide { grid-column: 1 / -1; }
.card-wide table { display: block; overflow-x: auto; }

input[type="file"] { width: 100%; }
.site-bar select { max-width: 420px; }
.site-bar button { margin-top: 0; }

.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: #6b7280;
  padding: 1rem 1.5rem 2rem;
}

@media (max-width: 420px) {
  .card-grid { grid-template-columns: 1fr; padding: 0 0.75rem; }
  .site-bar { flex-wrap: wrap; }
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem 0;
}

input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 0.95rem;
}

textarea { font-family: inherit; resize: vertical; }

button {
  margin-top: 0.75rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 4px;
  background: #2563eb;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}

button:hover { background: #1d4ed8; }

button.secondary {
  background: #e5e7eb;
  color: #1a1a1a;
}

button.secondary:hover { background: #d1d5db; }

button.danger {
  background: #dc2626;
}

button.danger:hover { background: #b91c1c; }

.hint {
  font-size: 0.8rem;
  color: #666;
  margin: 0.25rem 0 0.5rem 0;
}

.error-text {
  color: #dc2626;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.status-text {
  font-size: 0.85rem;
  color: #16a34a;
  min-height: 1.2em;
}

.bg-preview {
  max-width: 100%;
  max-height: 180px;
  display: block;
  margin-top: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

th, td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #eee;
  font-size: 0.9rem;
}

.employee-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.employee-form button { grid-column: span 2; }

.custom-field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.custom-field-row input[type="text"] { flex: 1; }

/* Hide / show cards: a collapsed card shows only its heading and the Show link. */
.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: #2563eb;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
  width: auto;
}
.card-toggle { display: block; margin-top: 0.75rem; margin-left: auto; }
.card.collapsed > :not(h2):not(.card-toggle) { display: none !important; }
.card.collapsed h2 { margin: 0; }
.card.collapsed { display: flex; align-items: baseline; gap: 1rem; }
.card.collapsed .card-toggle { margin-top: 0; }

/* Background image slots: one row per slot, thumbnail beside its controls */
.bg-slots { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }
.bg-slot { display: flex; align-items: center; gap: 0.75rem; min-width: 0; min-height: 56px; }
.bg-slot .bg-preview { width: 90px; height: 56px; object-fit: cover; border-radius: 4px; border: 1px solid #ddd; margin: 0; flex: none; }
.bg-slot input[type=file] { font-size: 0.8rem; min-width: 0; flex: 1; margin: 0; }
.bg-slot .bg-remove { flex: none; }

/* Visitor log */
.log-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }
.log-controls label { display: flex; flex-direction: column; font-size: 0.85rem; margin: 0; }
.log-controls input[type=date] { margin: 0.25rem 0 0; width: auto; }
.log-controls button { margin-top: 0; }
.log-table-wrap { max-height: 480px; overflow: auto; margin-top: 0.5rem; }
#log-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
#log-table th { position: sticky; top: 0; background: #fff; text-align: left; }
#log-table th, #log-table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid #eee; white-space: nowrap; }
#log-table tr.log-open td { background: #fff8e1; }

/* Tabs under the site picker */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  background: #fff;
  padding: 0 1.5rem;
  border-bottom: 1px solid #ddd;
  overflow-x: auto;
}
.tab-bar .tab {
  margin: 0;
  background: none;
  color: #4b5563;
  border-radius: 0;
  border-bottom: 3px solid transparent;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  white-space: nowrap;
  width: auto;
}
.tab-bar .tab:hover { color: #1a1a1a; }
.tab-bar .tab.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }
.tab-hidden { display: none !important; }
.tab-hint { max-width: 1800px; margin: 1.5rem auto; padding: 0 1.5rem; color: #6b7280; }

/* Admin security (authenticator app) */
#mfa-qr { display: block; margin: 8px 0; background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; }
#mfa-key { word-break: break-all; font-family: monospace; }
