/* RSI Online Report — branding & layout
   Colors approximate RSI "Team Green": blue primary, green accent.
   Confirm exact hex from RSI brand guide (see PLAN.md §8). */
:root {
  --rsi-blue:        #00529B;
  --rsi-blue-dark:   #003E7E;
  --rsi-blue-light:  #e8f1fa;
  --rsi-green:       #6CB33F;
  --rsi-green-dark:  #4e8a2c;
  --ink:             #1c2430;
  --muted:           #5a6b7b;
  --line:            #e2e8ef;
  --bg:              #f4f7fa;
  --white:           #ffffff;
  --danger:          #c0392b;
  --radius:          10px;
  --shadow:          0 2px 10px rgba(0,40,90,.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--rsi-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar { background: var(--rsi-blue); color: #fff; box-shadow: var(--shadow); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: #fff; color: var(--rsi-blue); font-weight: 800; letter-spacing: .5px; border: 3px solid var(--rsi-green); }
.brand-text { font-weight: 600; font-size: 1.05rem; }
.topnav { display: flex; align-items: center; gap: 14px; }
.user-name { color: #dce8f4; font-size: .9rem; }
.role-pill { font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; padding: 3px 9px; border-radius: 999px; background: var(--rsi-green); color: #fff; font-weight: 700; }

/* Layout */
.container { max-width: 1180px; margin: 0 auto; padding: 28px 20px; }
.sitefooter { color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); margin-top: 40px; padding: 18px 0; background: #fff; }
.sitefooter .container { padding: 0 20px; }

/* Buttons */
.btn { display: inline-block; padding: 10px 18px; border-radius: var(--radius); border: 0; font-weight: 600; cursor: pointer; font-size: .95rem; }
.btn-primary { background: var(--rsi-green); color: #fff; }
.btn-primary:hover { background: var(--rsi-green-dark); text-decoration: none; }
.btn-ghost { background: rgba(255,255,255,.15); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,.28); text-decoration: none; }

/* Cards / grid */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card h2 { margin: 0 0 14px; font-size: 1.05rem; }

/* Stat tiles */
.stat { text-align: left; }
.stat .num { font-size: 2rem; font-weight: 800; color: var(--rsi-blue); }
.stat .label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .4px; }
.stat .num.green { color: var(--rsi-green-dark); }

/* Tables */
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
table.data tr:hover td { background: var(--rsi-blue-light); }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--rsi-blue-light); color: var(--rsi-blue-dark); }
.badge.pending { background: #fff3cd; color: #8a6d1b; }
.badge.approved { background: #e3f3d8; color: var(--rsi-green-dark); }

/* Auth pages */
.auth-wrap { min-height: 70vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 32px; border-top: 5px solid var(--rsi-green); }
.auth-card h1 { margin: 0 0 4px; font-size: 1.4rem; color: var(--rsi-blue); }
.auth-card .sub { color: var(--muted); margin: 0 0 22px; font-size: .92rem; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.field input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; }
.field input:focus { outline: none; border-color: var(--rsi-blue); box-shadow: 0 0 0 3px var(--rsi-blue-light); }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c2; }
.auth-switch { text-align: center; margin-top: 18px; font-size: .85rem; color: var(--muted); }

/* Portal landing */
.portal-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-top: 26px; }
@media (max-width: 760px) { .portal-pick { grid-template-columns: 1fr; } }
.portal-card { display: block; text-align: center; padding: 30px 20px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow); color: var(--ink); }
.portal-card:hover { text-decoration: none; transform: translateY(-3px); transition: .15s; border-color: var(--rsi-green); }
.portal-card .pc-icon { font-size: 2.2rem; }
.portal-card h3 { margin: 10px 0 4px; color: var(--rsi-blue); }
.portal-card p { color: var(--muted); font-size: .88rem; margin: 0; }

.page-title { margin: 0 0 6px; color: var(--rsi-blue); }
.page-sub { color: var(--muted); margin: 0 0 24px; }
.section-gap { margin-top: 24px; }
canvas { max-width: 100%; }

/* Admin sub-navigation */
.admin-nav { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 24px; border-bottom: 2px solid var(--line); }
.admin-nav a { padding: 9px 14px; font-size: .9rem; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.admin-nav a:hover { color: var(--rsi-blue); text-decoration: none; }
.admin-nav a.active { color: var(--rsi-blue); border-bottom-color: var(--rsi-green); }

/* Page header row (title + primary action) */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .page-title, .page-head .page-sub { margin-bottom: 0; }

/* Button variants & sizes */
.btn-secondary { background: var(--rsi-blue); color: #fff; }
.btn-secondary:hover { background: var(--rsi-blue-dark); text-decoration: none; }
.btn-outline { background: #fff; color: var(--rsi-blue); border: 1px solid var(--line); }
.btn-outline:hover { border-color: var(--rsi-blue); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #9b2d22; text-decoration: none; }
.btn-sm { padding: 5px 11px; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Forms (build on existing .field) */
.field textarea, .field select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; font-family: inherit; background: #fff; }
.field textarea:focus, .field select:focus { outline: none; border-color: var(--rsi-blue); box-shadow: 0 0 0 3px var(--rsi-blue-light); }
.field .hint { color: var(--muted); font-size: .8rem; margin-top: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
@media (max-width: 680px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.form-actions .spacer { flex: 1; }

/* Table action cells & toolbar */
.table-actions { white-space: nowrap; text-align: right; }
.table-actions a, .table-actions button { margin-left: 6px; }
.inline-form { display: inline; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.search-input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: .92rem; min-width: 220px; }

.alert-success { background: #e3f3d8; color: var(--rsi-green-dark); border: 1px solid #c2e0a8; }
.alert-info { background: var(--rsi-blue-light); color: var(--rsi-blue-dark); border: 1px solid #c5dcf0; }
.badge.inactive, .badge.revoked { background: #eceff1; color: var(--muted); }
.badge.retired { background: #fdecea; color: var(--danger); }
.muted-link { color: var(--muted); font-size: .85rem; }

/* Card header row (title + inline control, e.g. chart parameter picker) */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-head .search-input { min-width: 0; font-size: .88rem; padding: 6px 10px; }

/* Visit form & detail */
.visit-subhead { font-size: .82rem; text-transform: uppercase; letter-spacing: .5px; color: var(--rsi-blue); margin: 18px 0 10px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.reading-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 680px) { .reading-grid { grid-template-columns: repeat(2, 1fr); } }
.reading-grid .field label { font-size: .8rem; }
.chem-usage td { padding: 6px 8px; }
.chem-usage input, .chem-usage select { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: .9rem; }
.chem-usage input:focus, .chem-usage select:focus { outline: none; border-color: var(--rsi-blue); }

/* Role pill color by role (login accounts list) */
.role-pill.role-admin { background: var(--rsi-blue); }
.role-pill.role-technician { background: var(--rsi-green); }
.role-pill.role-customer { background: #6b7b8c; }
.role-pill.role-dealer { background: #b07d1a; }

/* Print letterhead (hidden on screen, shown when printing a report) */
.print-only { display: none; }
.print-letterhead .pl-brand { font-size: 1.2rem; font-weight: 800; color: var(--rsi-blue); }
.print-letterhead .pl-mark { color: var(--rsi-green-dark); }
.print-letterhead .pl-title { font-size: 1.5rem; font-weight: 700; margin: 6px 0 14px; }
.print-letterhead .pl-meta { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.print-letterhead .pl-meta th { text-align: left; width: 12%; color: var(--muted); font-size: .8rem; text-transform: uppercase; padding: 3px 8px 3px 0; vertical-align: top; }
.print-letterhead .pl-meta td { padding: 3px 16px 3px 0; font-weight: 600; }

/* ---- Responsive / mobile pass ---- */
@media (max-width: 600px) {
  .container { padding: 18px 14px; }
  .topbar-inner { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .brand-text { font-size: .95rem; }
  .topnav { gap: 8px; }
  .user-name { display: none; }
  .page-head { flex-direction: column; align-items: stretch; }
  /* Wide tables scroll horizontally instead of breaking the layout. */
  table.data { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---- Print ---- */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .sitefooter, .admin-nav, .toolbar, .page-head .btn, .page-head .topnav,
  .table-actions, .form-actions, button, .muted-link, canvas, #paramPick { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: 12px; }
  .print-only { display: block; }
  a { color: #000; text-decoration: none; }
  table.data { display: table; white-space: normal; font-size: .85rem; }
}

/* --- Flyer admin ------------------------------------------------------- */
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form select { min-width: 260px; padding: 9px 10px; border: 1px solid #c9d4de; border-radius: 8px; font: inherit; }

/* Web-address field: https:// [ slug ] .domain */
.slug-row { display: flex; align-items: stretch; flex-wrap: wrap; }
.slug-row input { flex: 1 1 160px; min-width: 120px; border-radius: 0 !important; text-align: center; }
.slug-proto, .slug-domain {
  display: flex; align-items: center; padding: 0 10px; background: #eef2f6;
  border: 1px solid #c9d4de; color: var(--muted); font-size: .9rem; white-space: nowrap;
}
.slug-proto  { border-right: 0; border-radius: 8px 0 0 8px; }
.slug-domain { border-left: 0;  border-radius: 0 8px 8px 0; }

/* Small rich-text box in the flyer editor */
.rte { border: 1px solid #c9d4de; border-radius: 8px; overflow: hidden; background: #fff; }
.rte-tools { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; background: #f5f8fb; border-bottom: 1px solid var(--line); }
.rte-tools button {
  min-width: 34px; padding: 5px 9px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; cursor: pointer; font: inherit; font-size: .86rem; color: var(--ink);
}
.rte-tools button:hover { background: #fff; border-color: #c9d4de; }
.rte-area { min-height: 200px; max-height: 460px; overflow-y: auto; padding: 14px 16px; line-height: 1.55; }
.rte-area:focus { outline: 2px solid var(--rsi-green); outline-offset: -2px; }
.rte-area h3 { color: var(--rsi-blue); font-size: 1.1rem; margin: 16px 0 6px; }
.rte-area p { margin: 0 0 10px; }
.rte-area ul, .rte-area ol { margin: 0 0 10px; padding-left: 22px; }
.rte-area img { max-width: 100%; height: auto; }

/* Enquiries already dealt with sit back visually */
.row-done { opacity: .55; }
