/* ---------------------------------------------------------------------------
   Somer Valley Internal — base styles. Brand colours come from CSS variables
   set inline by the layout (--primary, --accent) from admin Branding settings.
--------------------------------------------------------------------------- */

* { box-sizing: border-box; }

:root {
  --primary: #1d4ed8;
  --accent: #0e9f6e;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --radius: 10px;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); }

h1 { font-size: 24px; margin: 18px 0 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; word-break: break-all; }

/* ---- Top bar ---- */
.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand-logo { height: 30px; width: auto; border-radius: 6px; background: #fff; padding: 2px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, 0.15); }
.nav-toggle { display: none; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; padding: 4px 8px; }

@media (max-width: 720px) {
  .nav-toggle { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; }
  body.nav-open .nav { display: flex; }
  .topbar { flex-wrap: wrap; }
}

/* ---- Layout ---- */
.container { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 8px 16px 40px; }
.footer {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 16px;
  justify-content: center;
}
.footer a { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 14px 0;
}

/* ---- Forms ---- */
label { display: block; margin: 10px 0; font-weight: 600; font-size: 14px; }
label small { font-weight: 400; display: block; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="file"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  margin-top: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[type="color"] { margin-top: 5px; height: 42px; width: 80px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; }
input[disabled] { background: #f3f4f6; color: var(--muted); }

.form-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-inline input { width: auto; flex: 1 1 180px; margin-top: 0; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row label { flex: 1 1 200px; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.1); }
.btn-secondary { background: #eef1f5; color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-small { padding: 5px 10px; font-size: 13px; font-weight: 500; }

/* ---- Flash messages ---- */
.flash { padding: 12px 16px; border-radius: 8px; margin: 12px 0; font-size: 14px; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.row-actions form { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #ecfdf5; color: #065f46; }
.badge-danger { background: #fef2f2; color: #991b1b; }
.badge-warn { background: #fffbeb; color: #92400e; }
.badge-primary { background: #eff6ff; color: #1e40af; }
.badge-muted { background: #f3f4f6; color: var(--muted); }

/* ---- Stats & admin tiles ---- */
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; flex: 1 1 120px; text-align: center; }
.stat-num { display: block; font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: 13px; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.admin-tile { text-decoration: none; color: inherit; margin: 0; }
.admin-tile:hover { border-color: var(--primary); }
.admin-tile p { color: var(--muted); font-size: 14px; margin: 0; }

.breadcrumb { font-size: 13px; margin: 14px 0 0; }

/* ---- Posts & feed ---- */
.post-card { padding: 16px 20px; }
.post-important { border-left: 4px solid var(--danger); }
.post-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 6px; }
.post-body { margin: 8px 0; word-wrap: break-word; overflow-wrap: break-word; }
.post-foot { margin-top: 10px; font-size: 13px; }
.comment { padding: 12px 16px; margin: 8px 0; }
.pager { display: flex; gap: 10px; }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check-label input { width: auto; margin: 0; }

.group-row { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.group-row h2 { margin-bottom: 4px; }
.group-row p { margin: 4px 0; }

/* ---- Home layout with sidebars ---- */
.container-wide { max-width: 1240px; }
.home-grid { display: grid; grid-template-columns: 230px minmax(0, 1fr) 230px; gap: 18px; align-items: start; }
.home-feed h1 { margin-top: 4px; }
.home-side { position: sticky; top: 66px; display: flex; flex-direction: column; gap: 10px; }
.quick-btn {
  display: block; background: var(--accent); color: #fff; text-decoration: none;
  font-weight: 700; text-align: center; padding: 18px 14px; border-radius: var(--radius);
  font-size: 15px;
}
.quick-btn:hover { filter: brightness(1.08); }
.side-card { margin: 0; padding: 14px 16px; }
.side-card h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.side-group { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0;
              text-decoration: none; color: inherit; border-bottom: 1px solid var(--border); }
.side-group:last-child { border-bottom: none; }
.side-group:hover { color: var(--primary); }

@media (max-width: 980px) {
  .home-grid { grid-template-columns: 1fr; }
  .home-side { position: static; }
  .home-side:first-child { flex-direction: row; flex-wrap: wrap; }
  .home-side:first-child .quick-btn { flex: 1 1 40%; padding: 14px; }
  .home-side:first-child .side-card { display: none; } /* groups reachable via nav on mobile */
}

.post-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dismiss-form { display: inline-block; margin-left: 10px; }

/* ---- Group page ---- */
.group-banner {
  border-radius: var(--radius);
  min-height: 150px;
  margin-top: 14px;
  background: linear-gradient(120deg, var(--primary), var(--accent));
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.group-banner-overlay {
  width: 100%;
  padding: 40px 22px 14px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
}
.group-banner-overlay h1 { color: #fff; margin: 0; text-shadow: 0 1px 3px rgba(0,0,0,0.4); }

.group-meta { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.group-meta p { margin: 2px 0; }
.group-meta-actions { display: flex; gap: 8px; flex-shrink: 0; }

.group-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.group-side { position: sticky; top: 66px; display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 900px) {
  .group-grid { grid-template-columns: 1fr; }
  .group-side { position: static; }
}

.member-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.member { text-align: center; min-width: 0; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 14px;
}
.member-name { display: block; font-size: 11px; color: var(--muted);
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Editor toolbar & post images ---- */
.editor-toolbar { display: flex; gap: 6px; margin-bottom: 6px; }
.editor-toolbar button {
  background: #eef1f5; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 11px; font: inherit; font-size: 13px; cursor: pointer;
}
.editor-toolbar button:hover { border-color: var(--primary); }

.post-images { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.post-images img {
  max-height: 220px; max-width: 100%; border-radius: 8px;
  border: 1px solid var(--border); display: block;
}

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 14px; margin: 6px 0 12px; }

/* ---- Quick link picture tiles ---- */
.quick-tile {
  display: block; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit;
}
.quick-tile img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.quick-tile span { display: block; padding: 10px 14px; font-weight: 700; }
.quick-tile:hover { border-color: var(--primary); }
@media (max-width: 980px) {
  .home-side:first-child .quick-tile { flex: 1 1 40%; }
  .home-side:first-child .quick-tile img { aspect-ratio: 2.4 / 1; }
}

/* ---- Help centre ---- */
.kb-link { display: block; padding: 8px 0; border-bottom: 1px solid var(--border); text-decoration: none; }
.kb-link:last-of-type { border-bottom: none; }

.kb-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 14px 0; }
.kb-cat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: 2px;
}
.kb-cat-card:hover { border-color: var(--primary); }
.folder-icon { font-size: 26px; }

.kb-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit; font-weight: 600;
}
.kb-row:last-of-type { border-bottom: none; }
.kb-row:hover { color: var(--primary); }
.doc-icon {
  background: var(--accent); border-radius: 9px;
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.kb-row .chev { margin-left: auto; color: var(--muted); font-size: 20px; font-weight: 400; }

.kb-header {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 36px 22px 26px; text-align: center; margin: 14px 0;
}
.kb-header h1 { margin: 0 0 6px; }
.kb-header p { margin: 0; }

.kb-article img { max-width: 100%; border-radius: 8px; }
.kb-img { margin: 14px 0; }
.kb-article h2 { font-size: 20px; margin: 20px 0 8px; }
.kb-article h2:first-child { margin-top: 0; }
.kb-article h3 { font-size: 16px; margin: 16px 0 6px; }
.kb-article ul { margin: 8px 0; padding-left: 22px; }
.kb-article li { margin: 4px 0; }
.kb-video { position: relative; width: 100%; aspect-ratio: 16 / 9; margin: 14px 0;
            border-radius: 8px; overflow: hidden; background: #000; }
.kb-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---- Notifications ---- */
.nav-bell { position: relative; }
.bell-count {
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 700; padding: 1px 6px; margin-left: 4px;
}
.notif { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px;
         margin: 8px 0; text-decoration: none; color: inherit; }
.notif-unread { border-left: 4px solid var(--primary); background: #f7faff; }
.notif:hover { border-color: var(--primary); }

/* ---- Auth pages ---- */
body.bare { justify-content: center; }
body.bare .container { display: flex; align-items: center; justify-content: center; }
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 400px;
  margin: 40px auto;
}
.auth-card h1 { font-size: 18px; color: var(--primary); margin: 0 0 4px; }
.auth-card h2 { font-size: 22px; margin: 0 0 14px; }
.auth-card .btn { width: 100%; margin-top: 12px; }
.auth-links { text-align: center; font-size: 14px; margin-top: 16px; }
