:root {
  --ink: #0f1720;
  --ink-soft: #4b5a6b;
  --muted: #8592a3;
  --line: #e2e6ea;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --accent: #3b6ef6;
  --accent-ink: #1d3fa0;
  --ok: #1a9c6e;
  --ok-bg: #e6f7f0;
  --warn: #b5820c;
  --warn-bg: #fbf1dc;
  --danger: #c0392b;
  --radius: 8px;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

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

/* A <button> made to look and sit like an inline text link -- used for
   destructive actions that need to be real POST forms (CSRF-protected)
   instead of plain GET links. */
.link-btn {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; font-size: 12px; color: var(--accent-ink);
  text-decoration: none; cursor: pointer; display: inline;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger-link { color: #c0392b; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
.wrap-narrow { max-width: 440px; }
main.wrap { padding-top: 28px; padding-bottom: 60px; }

/* ---- top nav ---- */
.topnav { background: var(--ink); color: #fff; }
.topnav-inner { display: flex; align-items: center; justify-content: space-between; height: 54px; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; letter-spacing: 0.2px; }
.brand:hover { text-decoration: none; opacity: 0.9; }
.brand-mark {
  width: 28px; height: 28px; object-fit: contain;
}
.topnav-links a { color: #cfd8e3; margin-left: 20px; font-size: 13px; }
.topnav-links a:hover { color: #fff; }

/* ---- panels ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head-actions { display: flex; gap: 10px; align-items: center; }

/* ---- stat cards (e.g. mileage summary strip) ---- */
.stat-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.stat-card {
  flex: 1 1 160px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat-value { font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn-danger { background: #fdecea; color: var(--danger); border-color: #f5c6c0; }
.btn-block { width: 100%; margin-top: 6px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- badges ---- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-role-admin { background: #e8edff; color: var(--accent-ink); }
.badge-role-employee { background: #f1f0f4; color: #6b6478; }
.badge-status-pending { background: var(--warn-bg); color: var(--warn); }
.badge-status-approved { background: var(--ok-bg); color: var(--ok); }
.badge-status-rejected { background: #fdecea; color: var(--danger); }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); border-bottom: 1px solid var(--line); padding: 8px 10px; }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.row-actions a, .row-actions button { margin-right: 10px; font-size: 12px; }

/* ---- forms ---- */
.form-row { margin-bottom: 16px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="date"], input[type="time"], input[type="file"], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; color: var(--ink); background: #fff; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 110, 246, 0.15);
}
.hint { font-size: 12px; color: var(--muted); margin: 5px 0 0; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.icon-fetch-row { display: flex; gap: 8px; align-items: flex-start; }
.icon-fetch-row input { flex: 1; }
.icon-preview { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 6px; object-fit: contain; padding: 4px; background: #fff; flex-shrink: 0; }

/* ---- empty state ---- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .btn { margin-top: 10px; }

/* ---- alerts ---- */
.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c0; }
.alert-success { background: var(--ok-bg); color: var(--ok); border: 1px solid #b7e4d1; }
.alert-info { background: #eaf1ff; color: var(--accent-ink); border: 1px solid #c9dbff; }

/* ---- login/register ---- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #0f1720 0%, #1c2a3a 100%); }
.login-card { background: #fff; width: 360px; padding: 32px 30px; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.login-mark { width: 48px; height: 48px; object-fit: contain; margin-bottom: 14px; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card p { margin: 0 0 18px; }

/* ---- link grid (the shared directory) ---- */
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.link-card {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  position: relative;
}
.link-card:hover { border-color: var(--accent); }
.link-card-icon { width: 36px; height: 36px; border-radius: 6px; object-fit: contain; flex-shrink: 0; background: #fff; }
.link-card-body { min-width: 0; flex: 1; }
.link-card-title { font-weight: 600; color: var(--ink); }
.link-card-title:hover { text-decoration: none; }
.link-card-desc { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-card-admin-actions { position: absolute; top: 6px; right: 6px; display: none; gap: 4px; }
.link-card:hover .link-card-admin-actions { display: flex; }
.link-card-admin-actions a { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; font-size: 11px; color: var(--ink-soft); }

@media (max-width: 720px) {
  .link-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .link-grid { grid-template-columns: 1fr; }
}

/* ---- checkboxes (post pin, etc.) ---- */
.checkbox-row { display: flex; flex-direction: column; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.checkbox-label input { width: auto; }

.form-row-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.path-generate-row { display: flex; gap: 8px; }
.path-generate-row input { flex: 1; }
.path-generate-row .btn { flex: 0 0 auto; white-space: nowrap; }

/* ---- QR panel ---- */
.qr-row { display: flex; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.qr-image { width: 140px; height: 140px; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 8px; }
.qr-image-large { width: 220px; height: 220px; }

/* ---- library grid (QR codes) ---- */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.library-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; gap: 12px; align-items: flex-start; }
.library-card .qr-image { width: 72px; height: 72px; padding: 4px; flex-shrink: 0; }
.library-card-body { min-width: 0; }

@media (max-width: 720px) {
  .form-row-inline { grid-template-columns: 1fr; }
  .path-generate-row { flex-wrap: wrap; }
  .path-generate-row input { flex: 1 1 100%; }
}

/* ---- weather widget ---- */
.weather-widget {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
}
.weather-icon { font-size: 36px; line-height: 1; }

/* ---- posts ---- */
.post-preview {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.post-preview:last-child { border-bottom: none; padding-bottom: 0; }
.post-preview-title {
  display: block;
  font-weight: 600;
  color: var(--ink);
  margin: 2px 0 2px;
}
.post-preview-title:hover { color: var(--accent-ink); }
.post-full { scroll-margin-top: 70px; }
.post-body {
  white-space: pre-wrap;
  line-height: 1.6;
  margin-top: 10px;
  color: var(--ink-soft);
}

/* ---- link categories ---- */
.link-category-heading {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 24px 0 10px;
  font-weight: 700;
}
.link-category-heading:first-of-type { margin-top: 0; }

/* ---- directory ---- */
.directory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.directory-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 0;
}
.directory-card-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.directory-initial {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.directory-bio {
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ---- events ---- */
.badge-expiry-soon { background: var(--warn-bg); color: var(--warn); }
.past-events { margin-top: 24px; }
.past-events summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 0;
}

/* ---- time clock ---- */
.badge-expiry-expired { background: #fdecea; color: var(--danger); }
.timeclock-status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.timeclock-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.timeclock-buttons button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.timeclock-range-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.timeclock-range-form input[type="date"] {
  width: auto;
}
.row-anomaly { background: #fdecea33; }

/* ---- mileage ---- */
.badge-ssl-on { background: var(--ok-bg); color: var(--ok); }
.drop-zone {
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--muted);
  font-size: 14px;
}
.drop-zone:hover, .drop-zone.drag {
  border-color: var(--accent);
  background: rgba(59, 110, 246, 0.04);
  color: var(--ink);
}
.drop-zone strong { color: var(--accent-ink); }

/* ---- admin hub ---- */
.admin-hub-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}
/* Tuned per grid's actual item count (4 destination tiles, 3 quick-add
   tiles) rather than a generic auto-fill, which left an orphaned card
   alone in its own row with a large empty gap beside it at several common
   tablet widths (a real, measured bug -- not just a hypothetical one). */
@media (min-width: 680px) {
  .admin-hub-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .admin-hub-grid-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 960px) {
  .admin-hub-grid-4 { grid-template-columns: repeat(4, 1fr); }
}
.admin-hub-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 0;
  color: var(--ink);
  transition: border-color .15s, transform .1s;
}
.admin-hub-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}
.admin-hub-icon {
  font-size: 26px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 10px;
  flex-shrink: 0;
}
