/* Admin screens. Built to work on a phone and a desktop. */
* { box-sizing: border-box; }
:root {
  --ink: #1d2430;
  --navy: #14284b;
  --link: #0a5a86;
  --btn: #0a5a86;
  --danger: #9b1c16;
  --bg: #f2f5f9;
  --card: #fff;
  --line: #d5dbe3;
  --muted: #3d4754;
  --focus: #0a5a86;
  --admin-mobile-bar-h: 60px;
}
html, body { margin: 0; }
body { font: 17px/1.5 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--link); }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}

.admin-shell { display: flex; min-height: 100vh; align-items: stretch; }
.admin-sidebar {
  width: 240px; flex: 0 0 240px; background: var(--navy); color: #fff;
  display: flex; flex-direction: column; padding: 20px 0 16px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { color: #fff; font-weight: 700; padding: 8px 20px 20px; text-decoration: none; font-size: 1.1rem; }
.admin-sidebar nav { display: flex; flex-direction: column; gap: 4px; padding: 0 10px; }
.admin-sidebar nav a {
  color: #fff; text-decoration: none; min-height: 44px; display: flex; align-items: center;
  padding: 8px 12px; border-radius: 8px;
}
.admin-sidebar nav a:hover, .admin-sidebar nav a:focus-visible { background: rgba(255,255,255,.12); }
.admin-sidebar nav a[aria-current="page"] { background: #1d4e7c; font-weight: 700; }
.sidebar-logout { margin-top: auto; padding: 16px 20px; }
.sidebar-logout button.link { color: #fff; }
.admin-content { flex: 1; min-width: 0; }
.admin-mobile-bar { display: none; z-index: 40; }
.admin-main { max-width: 860px; margin: 0 auto; padding: 24px 20px 48px; }
body.is-wide .admin-main { max-width: 1100px; }
body.is-login { background: var(--bg); }
.login-main { max-width: 420px; margin: 12vh auto; background: var(--card); padding: 28px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

h1 { font-size: 1.6rem; color: var(--navy); margin: 0 0 12px; }
h2 { font-size: 1.15rem; color: var(--navy); margin: 0 0 10px; }
.card { background: var(--card); border-radius: 10px; padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stack { display: grid; gap: 12px; }
.stack label, label { display: grid; gap: 4px; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; min-width: 160px; }
input, textarea, select { font: inherit; font-size: 17px; padding: 12px; border: 1px solid #8b95a3; border-radius: 8px; width: 100%; background: #fff; color: var(--ink); }
button, .button {
  font: inherit; background: var(--btn); color: #fff; border: 0; padding: 12px 18px;
  border-radius: 8px; min-height: 44px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
button.big, .button.big { width: 100%; font-size: 1.1rem; padding: 16px; }
button.danger { background: var(--danger); }
button.small { padding: 8px 12px; min-height: 44px; font-size: .95rem; }
button.link { background: none; padding: 8px 0; min-height: 44px; text-decoration: underline; color: inherit; }
form.inline { display: inline; }
.flash { padding: 14px 16px; border-radius: 8px; background: #e6f4ea; color: #0d3b1e; font-weight: 600; border: 1px solid #b7dfc2; }
.flash.error { background: #fdecea; color: #6b1210; border-color: #f5c2c0; }

.save-bar {
  position: sticky;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(0,0,0,.08);
  padding: 12px 16px;
  margin-top: 8px;
  border-radius: 8px;
}
.save-bar .save-status { font-weight: 600; color: var(--muted); }
.save-bar .save-status.is-dirty { color: #7a4d00; }
.save-bar .save-status.is-saved { color: #0d3b1e; }
button.save-btn, .save-btn {
  min-width: 160px; font-weight: 700; font-size: 1.05rem;
}
.photo-chosen { color: var(--muted); font-size: .95rem; }
.photo-chosen-img { display: block; max-width: 240px; max-height: 160px; object-fit: cover; border-radius: 8px; margin-top: 8px; }
.counter { margin: -4px 0 0; color: var(--muted); font-size: .95rem; }
.counter.over { color: var(--danger); font-weight: 700; }
.recipients { font-weight: 600; color: var(--navy); margin: 0; }
details { margin-top: 8px; }
summary { cursor: pointer; color: var(--link); padding: 10px 0; min-height: 44px; }
.numbers { list-style: none; padding: 0; margin: 0; }
.numbers li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.log, .member-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.log th, .log td, .member-table th, .member-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.member-table .actions { white-space: nowrap; }
.search-row { margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.search-row input { flex: 1 1 160px; min-width: 0; }
.search-row button, .search-row .button { flex: 0 0 auto; }
img, video, iframe, svg { max-width: 100%; }
.preview-frame, .spot-preview { max-width: 100%; }
input[type="file"] { max-width: 100%; }
.member-table td, .log td { overflow-wrap: break-word; word-break: break-word; }
.preview { background: #fff; border-left: 4px solid var(--btn); padding: 12px; margin: 0 0 16px; }
progress { width: 100%; height: 20px; }
.list a { display: flex; align-items: center; min-height: 44px; padding: 8px 0; font-size: 1.1rem; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.thumb { background: #fff; padding: 8px; border-radius: 8px; display: grid; gap: 6px; }
.thumb img { width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 4px; }
.secret, .wrap-any { word-break: break-all; font-size: 1rem; }
.hint { color: var(--muted); }
.hint a { color: var(--link); }
.empty { padding: 16px; background: #eef2f7; border-radius: 8px; color: var(--muted); }

.stat-grid, .action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0 0 20px; }
.stat-card, .action-card { background: var(--card); border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); text-decoration: none; color: inherit; display: block; min-height: 88px; }
.action-card { display: flex; align-items: center; font-weight: 700; color: var(--navy); min-height: 56px; }
.stat-card .label { color: var(--muted); font-size: .9rem; display: block; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: var(--navy); }

.composer { display: grid; gap: 16px; }
@media (min-width: 800px) {
  .composer.has-preview { grid-template-columns: 1fr 220px; align-items: start; }
}
.phone-preview {
  background: #1d2430; color: #fff; border-radius: 24px; padding: 36px 16px 20px; min-height: 220px;
  position: relative; box-shadow: inset 0 0 0 3px #445;
}
.phone-preview::before { content: ""; position: absolute; top: 12px; left: 50%; width: 60px; height: 8px; margin-left: -30px; background: #445; border-radius: 8px; }
.phone-preview p { background: #2b3340; border-radius: 12px; padding: 10px 12px; margin: 0; font-size: .95rem; white-space: pre-wrap; word-break: break-word; min-height: 3em; }
.phone-caption { font-size: .85rem; color: var(--muted); margin: 8px 0 0; text-align: center; }

.editor-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.editor-tools button { background: #44506a; min-height: 44px; min-width: 44px; }
.editor-tools button[aria-pressed="true"] { background: var(--navy); }
.editor-chrome { display: grid; gap: 8px; }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: #8b95a3; background: #fff; }
.ql-toolbar.ql-snow { border-radius: 8px 8px 0 0; }
.ql-container.ql-snow { border-radius: 0 0 8px 8px; font: 17px/1.5 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; min-height: 260px; }
.ql-editor { min-height: 260px; }
.ql-editor img { max-width: 100%; height: auto; }
/* View HTML: a plain textarea. 16px or larger stops iPhone zooming in on tap. */
textarea.html-view { display: block; min-height: 260px; font-family: ui-monospace, monospace; font-size: 16px; line-height: 1.45; resize: vertical; }
.editor { display: grid; gap: 0; min-width: 0; }
.editor [hidden], .editor .ql-toolbar[hidden], .editor textarea[hidden] { display: none !important; }
.editor.is-html .editor-chrome { margin-bottom: 8px; }
/* PDF button: a word, not an icon, so it needs room. 44px tall like the other tools on a phone. */
.ql-snow.ql-toolbar button.ql-pdf {
  width: auto; min-width: 44px; height: auto; min-height: 28px; padding: 2px 10px;
  display: inline-flex; align-items: center; gap: 6px; float: none;
  font-weight: 700; font-size: .9rem; color: #1d2430; white-space: nowrap;
  border: 1px solid #8b95a3; border-radius: 6px; background: #f2f5f9;
}
.ql-snow.ql-toolbar button.ql-pdf .clip-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ql-snow.ql-toolbar button.ql-pdf:hover, .ql-snow.ql-toolbar button.ql-pdf:focus-visible { color: #06c; }
.editor-status { margin: 8px 0 0; font-weight: 600; color: #7a4d00; }
.editor-status.is-busy, .save-status.is-busy { color: var(--muted); }
.editor-status.is-error, .save-bar .save-status.is-error { color: var(--danger); }
.field { display: grid; gap: 4px; min-width: 0; }
.field-label { font-weight: 600; }
.preview-frame { width: 100%; min-height: 520px; border: 1px solid #8b95a3; border-radius: 8px; background: #fff; }
.preview-panel h2 { margin-top: 8px; }
.photo-card { display: grid; gap: 8px; }
.photo-places { margin: 0; padding-left: 18px; font-size: .9rem; }
.photo-places a { color: var(--link); }
.spot-preview { width: 100%; height: 180px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
@media (min-width: 900px) {
  .edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
}

@media (max-width: 800px) {
  .admin-mobile-bar {
    display: flex; align-items: center; gap: 12px; background: var(--navy); color: #fff;
    padding: 8px 12px; position: sticky; top: 0; z-index: 40; min-height: 52px;
  }
  .nav-toggle {
    background: #1d4e7c; color: #fff; min-height: 44px; min-width: 44px; padding: 8px 14px;
  }
  .admin-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100%; z-index: 45;
    transform: translateX(-110%); transition: transform .2s ease; box-shadow: none;
  }
  .admin-sidebar.is-open { transform: none; box-shadow: 4px 0 16px rgba(0,0,0,.25); }
  body.nav-open { overflow: hidden; }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35;
  }
  .admin-shell { display: block; }
  .admin-main { padding: 16px 16px 40px; }
  body.has-save-bar,
  body:has(.save-bar) { --save-bar-space: 108px; }
  html { scroll-padding-bottom: calc(var(--save-bar-space) + 16px); }
  body.has-save-bar .admin-main,
  .admin-main:has(.save-bar) {
    padding-bottom: calc(var(--save-bar-space) + 16px);
  }
  form.js-save-form:has(.save-bar) {
    padding-bottom: var(--save-bar-space);
  }
  .save-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    margin: 0;
    border-radius: 0;
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(0,0,0,.14);
    background: #fff;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    box-sizing: border-box;
  }
  .save-bar .save-status {
    font-size: 1rem;
    text-align: center;
    line-height: 1.3;
  }
  .save-bar .save-btn {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    font-size: 1.1rem;
  }

  .login-main { margin: 24px 16px; padding: 20px 16px; width: auto; }

  .editor-chrome {
    position: sticky;
    top: var(--admin-mobile-bar-h);
    z-index: 20;
    background: var(--bg);
    padding: 8px 0;
  }
  .editor-tools button { flex: 1 1 auto; }
  .ql-toolbar.ql-snow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 4px;
    padding: 6px 8px;
  }
  .ql-toolbar.ql-snow .ql-formats {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    margin: 0;
    gap: 2px;
  }
  .ql-snow.ql-toolbar button {
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .ql-snow.ql-toolbar button.ql-pdf { width: auto; min-width: 56px; height: 44px; padding: 0 12px; font-size: 1rem; }
  .ql-toolbar.ql-snow .ql-picker {
    height: 44px;
  }
  .ql-toolbar.ql-snow .ql-picker-label {
    display: flex;
    align-items: center;
    height: 44px;
    padding: 0 8px;
    box-sizing: border-box;
  }
  .ql-toolbar.ql-snow .ql-header,
  .ql-toolbar.ql-snow .ql-header .ql-picker-label {
    width: 7.5em;
    min-width: 7.5em;
  }
  .ql-toolbar.ql-snow .ql-picker-options {
    max-width: calc(100vw - 32px);
  }
  .ql-container.ql-snow, .ql-editor, textarea.html-view { min-height: 220px; }

  form.stack .row:not(.search-row) {
    flex-direction: column;
    align-items: stretch;
  }
  form.stack .row:not(.search-row) button,
  form.stack .row:not(.search-row) .button,
  form.stack .row:not(.search-row) a {
    width: 100%;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  details button { width: 100%; }

  .member-table thead, .log thead, .member-table tr:first-child th, .log tr:first-child th { display: none; }
  .member-table, .log, .member-table tbody, .log tbody { display: block; width: 100%; }
  .member-table tr, .log tr {
    display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    margin: 0 0 10px; padding: 6px 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05);
  }
  .member-table td, .log td {
    display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 8px 6px;
  }
  .member-table td::before, .log td::before {
    content: attr(data-label); font-weight: 700; color: var(--navy); flex: 0 0 30%;
  }
  .member-table td.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; white-space: normal; align-items: center; }
  .member-table td.actions a,
  .member-table td.actions button {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
  }
  .member-table td.actions a {
    font-weight: 700;
    background: #e8eef4;
    color: var(--navy);
    border-radius: 8px;
    text-decoration: none;
  }
}

