:root {
  /* Popular Systems brand */
  --brand: #00b3ed;
  --brand-dark: #0a7ea4;   /* accessible for white text (4.7:1) */
  --brand-tint: #e8f8fe;

  --bg: #f4f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #667085;
  --line: #e2e8ee;
  --accent: var(--brand-dark);
  --accent-ink: #ffffff;
  --ok: #0f8a4d;
  --warn: #b26a00;
  --danger: #c62828;
  --radius: 12px;
  --tap: 44px;             /* minimum comfortable touch target */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-wrap: break-word;
}
.hidden { display: none !important; }
a { color: var(--brand-dark); }
img { max-width: 100%; }

/* ---------- header ---------- */

header {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 16px; min-height: 60px; position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.2px; }
.brand img { height: 34px; width: auto; display: block; }
.brand .name { font-size: 17px; }

nav { display: flex; gap: 3px; flex-wrap: wrap; }
nav a {
  display: inline-flex; align-items: center;
  padding: 9px 12px; border-radius: 9px; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap;
}
nav a:hover { background: var(--brand-tint); color: var(--ink); }
nav a.active { background: var(--brand-dark); color: #fff; }
nav a .pill {
  display: inline-block; min-width: 19px; padding: 0 6px; margin-left: 7px;
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 11px; line-height: 19px; text-align: center;
}
.spacer { flex: 1; }
.whoami { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
#menu-toggle { display: none; }

main { max-width: 1120px; margin: 0 auto; padding: 22px 18px calc(72px + var(--safe-b)); }
h1 { font-size: 23px; margin: 0 0 4px; letter-spacing: -0.3px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.banner {
  background: #fff6da; color: #6b4c00; padding: 9px 16px;
  font-size: 13px; border-bottom: 1px solid #f0e0b0; text-align: center;
}
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- forms ---------- */

label { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
label.inline { display: flex; align-items: center; gap: 9px; font-weight: 500; margin: 6px 0; min-height: var(--tap); }
input[type=text], input[type=email], input[type=password], input[type=datetime-local],
input[type=number], input[type=file], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink);
  font: inherit; font-size: 16px;   /* 16px stops iOS Safari zooming on focus */
  min-height: var(--tap);
}
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(0, 179, 237, .35); border-color: var(--brand); outline-offset: 0;
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand-dark); }
.help { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

button {
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 10px 16px; border-radius: 9px; min-height: var(--tap);
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
button:hover { background: #eef4f8; }
button.primary { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
button.primary:hover { background: #06657f; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.ok:hover { background: #0b7440; }
button.danger { background: #fff; border-color: #f0c4c4; color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: 6px 11px; font-size: 13.5px; min-height: 34px; }
.row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

/* ---------- tables (become stacked cards on phones) ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
tr:last-child td { border-bottom: 0; }

/* ---------- pieces ---------- */

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; border: 1px solid transparent; white-space: nowrap;
}
.badge.draft, .badge.queued, .badge.cancelled { background: #eef1f4; color: #4b5563; }
.badge.pending_approval { background: #fff1cc; color: #8a5b00; }
.badge.changes_requested { background: #ffe6d5; color: #9a4a00; }
.badge.approved { background: var(--brand-tint); color: #05627f; }
.badge.publishing { background: #e6e0ff; color: #4b2fb5; }
.badge.published { background: #dcf5e5; color: #0b6b38; }
.badge.partially_published { background: #fff1cc; color: #8a5b00; }
.badge.failed, .badge.rejected { background: #ffe0e0; color: #9c1c1c; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px;
  background: #eef2f6; color: #333; margin: 2px 4px 2px 0;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

.stat { text-align: center; }
.stat .n { font-size: 32px; font-weight: 700; line-height: 1.1; color: var(--brand-dark); }
.stat .l { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.issues { background: #fff5f5; border: 1px solid #ffd6d6; border-radius: 9px; padding: 11px 13px; font-size: 13.5px; }
.issues.notes { background: var(--brand-tint); border-color: #bfe9fa; }
.issues ul { margin: 6px 0 0; padding-left: 18px; }
.issues li { margin-bottom: 3px; }
.okbox { background: #f0fbf4; border: 1px solid #c9ecd6; border-radius: 9px; padding: 11px 13px; font-size: 13.5px; }

.channel-pick {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
  cursor: pointer; min-height: var(--tap); font-weight: 500;
}
.channel-pick.on { border-color: var(--brand); background: var(--brand-tint); }
.channel-pick .name { font-weight: 700; }
.channel-pick .meta { font-size: 12.5px; color: var(--muted); }

.counter { font-size: 12.5px; color: var(--muted); }
.counter.over { color: var(--danger); font-weight: 700; }

.preview {
  border: 1px solid var(--line); border-radius: 10px; padding: 13px;
  background: #fff; margin-bottom: 10px; font-size: 14.5px;
}
.preview .head { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 8px; font-size: 13px; }
.preview .text { white-space: pre-wrap; word-break: break-word; }
.preview img { border-radius: 7px; margin-top: 9px; display: block; }

.thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.thumb { position: relative; width: 96px; }
.thumb img, .thumb .file {
  width: 96px; height: 96px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  color: var(--muted); background: #f7f9fb; text-align: center; padding: 4px; overflow: hidden;
}
.thumb button {
  position: absolute; top: -8px; right: -8px; border-radius: 50%;
  padding: 0; width: 28px; height: 28px; min-height: 28px; line-height: 1; font-size: 16px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

.comment { border-left: 3px solid var(--line); padding: 4px 0 4px 12px; margin-bottom: 12px; }
.comment .who { font-size: 12px; color: var(--muted); }
.comment.changes_requested { border-left-color: var(--warn); }
.comment.rejected { border-left-color: var(--danger); }
.comment.approval { border-left-color: var(--ok); }

/* ---------- calendar ---------- */

.cal-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(84px, 1fr)); gap: 5px; min-width: 620px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; font-weight: 700; text-transform: uppercase; }
.cal .day { background: #fff; border: 1px solid var(--line); border-radius: 9px; min-height: 90px; padding: 5px; font-size: 12px; }
.cal .day.other { background: #fafbfc; color: var(--muted); }
.cal .day.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal .day .n { font-weight: 700; font-size: 11px; color: var(--muted); }
.cal .ev {
  display: block; width: 100%; text-align: left; border: 0; padding: 3px 5px; margin-top: 4px;
  border-radius: 5px; font-size: 11px; background: #eef2f6; cursor: pointer; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; font-weight: 600; min-height: 0;
}

/* ---------- misc ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: #16181d; color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 14.5px; z-index: 100; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.22);
}
.toast.err { background: var(--danger); }
.loading { color: var(--muted); padding: 44px; text-align: center; }
.login-wrap { max-width: 400px; margin: 6vh auto; }
.login-wrap .logo { display: block; width: 230px; max-width: 70%; height: auto; margin: 0 auto 22px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
code { background: #eef2f6; padding: 2px 6px; border-radius: 5px; font-size: 13.5px; }

/* ---------- tablet ---------- */

@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ---------- phone ---------- */

@media (max-width: 720px) {
  main { padding: 16px 13px calc(80px + var(--safe-b)); }
  h1 { font-size: 21px; }
  .card { padding: 14px; border-radius: 11px; }

  header {
    flex-wrap: wrap; padding: 8px 13px; gap: 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  #menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--tap); height: var(--tap); min-height: var(--tap); padding: 0;
    font-size: 20px; order: 3;
  }
  .whoami { order: 2; margin-left: auto; font-size: 12px; }
  .whoami .uname { display: none; }
  nav {
    order: 4; width: 100%; display: none;
    flex-direction: column; gap: 2px; padding-bottom: 8px;
  }
  nav.open { display: flex; }
  nav a { padding: 13px 12px; font-size: 15px; min-height: var(--tap); }

  /* Tables reflow into stacked rows — no sideways scrolling to read a post. */
  table thead { display: none; }
  table, table tbody, table tr, table td { display: block; width: 100%; }
  table tr {
    border: 1px solid var(--line); border-radius: 10px;
    padding: 10px 12px; margin-bottom: 10px; background: #fff;
  }
  table td { border: 0; padding: 3px 0; }
  table td:empty { display: none; }
  table td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: 10.5px; text-transform: uppercase;
    letter-spacing: .5px; color: var(--muted); font-weight: 700; margin-bottom: 1px;
  }

  .row > button, .row > .full { flex: 1 1 auto; }
  .toast { left: 13px; right: 13px; transform: none; max-width: none; }
  .thumb, .thumb img, .thumb .file { width: 84px; }
  .thumb img, .thumb .file { height: 84px; }
}

@media (max-width: 360px) {
  .brand .name { display: none; }
}

/* ---------- print ---------- */

@media print {
  header, .banner, .toast, button { display: none !important; }
  body { background: #fff; }
}

/* ---------- version panel on the login page ---------- */

.version {
  margin-top: 18px; padding: 14px 16px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; color: var(--muted);
}
.version dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; }
.version dt { font-weight: 700; color: var(--ink); white-space: nowrap; }
.version dd { margin: 0; text-align: right; }
.version .vfoot {
  display: flex; align-items: center; gap: 7px; justify-content: center;
  margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 12px;
}
.vdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.vdot.mock { background: #d98500; }
.vdot.live { background: var(--ok); }

/* The user's name in the header links to their account page. */
.whoami .uname { color: var(--muted); text-decoration: none; font-weight: 600; }
.whoami .uname:hover { color: var(--brand-dark); text-decoration: underline; }
