/* Group Portal – mobile first */
:root {
  --green: #075e54;
  --green-2: #128c7e;
  --accent: #25d366;
  --bg: #f0f2f5;
  --chat-bg: #efeae2;
  --card: #fff;
  --text: #111b21;
  --muted: #667781;
  --mine: #d9fdd3;
  --web: #e7f3ff;
  --danger: #c62828;
  --radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--green-2); }
main { max-width: 1000px; margin: 0 auto; padding: 12px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--green); color: #fff;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #fff; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.topbar nav a:hover { background: rgba(255,255,255,.15); }
.topbar .back { color: #fff; text-decoration: none; font-size: 30px; line-height: 1; padding: 0 6px 4px 0; }

/* ---------- General ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 14px; }
.tag { background: #e9edef; color: var(--muted); border-radius: 4px; padding: 1px 6px; font-size: 11px; margin-left: 4px; font-weight: normal; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.flash { margin: 10px auto; max-width: 1000px; padding: 10px 14px; border-radius: 8px; background: #e7f6ec; color: #1b5e20; }
.flash-err { background: #fdecea; color: var(--danger); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
code { background: #eee; padding: 1px 4px; border-radius: 4px; }

.btn {
  display: inline-block; border: 1px solid #d1d7db; background: #fff; color: var(--text);
  padding: 9px 14px; border-radius: 8px; font-size: 15px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f5f6f6; }
.btn-primary { background: var(--green-2); border-color: var(--green-2); color: #fff; }
.btn-primary:hover { background: var(--green); }
.btn-danger { color: var(--danger); border-color: #f1b5b5; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; }

label { display: block; font-size: 14px; color: var(--muted); }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); padding: 10px 12px; margin-top: 4px;
  border: 1px solid #d1d7db; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
input.big { width: 22px; height: 22px; accent-color: var(--green-2); }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; align-items: end; } }
form.inline { display: inline; }
.filter { margin-bottom: 10px; }

/* ---------- Admin tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 20px; background: #fff; color: var(--text); text-decoration: none; white-space: nowrap; font-size: 14px; }
.tabs a.active { background: var(--green-2); color: #fff; }

/* ---------- Tables (become cards on mobile) ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eef0f1; vertical-align: middle; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table tr.muted td { opacity: .55; }
.table .actions { white-space: nowrap; text-align: right; }
@media (max-width: 699px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid #eef0f1; border-radius: 8px; margin-bottom: 10px; padding: 6px 10px; }
  .table td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  .table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 13px; }
  .table .actions { justify-content: flex-start; flex-wrap: wrap; }
}

/* ---------- Login ---------- */
.login-page main { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; text-align: center; }
.login-card label { text-align: left; }
.login-card .logo { font-size: 46px; }
.login-card h2 { margin: 0; }

/* ---------- Group list ---------- */
.group-list { list-style: none; margin: 0; padding: 0; background: #fff; border-radius: var(--radius); overflow: hidden; }
.group-list li + li { border-top: 1px solid #eef0f1; }
.group-list a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; text-decoration: none; }
.group-list a:hover { background: #f5f6f6; }
.avatar { flex: 0 0 46px; height: 46px; border-radius: 50%; background: var(--green-2); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 19px; }
.g-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.g-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-time { color: var(--muted); font-size: 12px; align-self: flex-start; padding-top: 4px; }

/* ---------- Chat ---------- */
.chat-page { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.chat-page main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0; max-width: none; width: 100%; }
.chat-page .flash { margin: 6px; }
.chat { flex: 1; overflow-y: auto; background: var(--chat-bg); padding: 10px 10px 16px; -webkit-overflow-scrolling: touch; }
.messages { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.older { display: block; margin: 4px auto 10px; }
.day { align-self: center; background: #fff; color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.msg { align-self: flex-start; max-width: min(80%, 560px); background: #fff; border-radius: 8px; padding: 6px 9px 4px; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg.web { background: var(--web); }
.msg .who { font-size: 13px; font-weight: 600; color: var(--green-2); margin-bottom: 2px; }
.msg .who .phone { color: var(--muted); font-weight: normal; font-size: 12px; }
.msg .badge { background: #cfe3ff; color: #1a4f8b; border-radius: 4px; font-size: 10px; padding: 0 4px; margin-left: 6px; font-weight: normal; }
.msg .text { white-space: pre-wrap; }
.msg .time { text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg .photo { display: block; max-width: 100%; max-height: 360px; border-radius: 6px; margin: 2px 0; }
.msg .sticker { width: 140px; height: 140px; object-fit: contain; }
.msg audio { max-width: 260px; }
.msg .doc { display: inline-block; padding: 8px 10px; background: rgba(0,0,0,.05); border-radius: 6px; text-decoration: none; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; background: #f0f2f5;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid #e0e0e0;
}
.composer.readonly { justify-content: center; color: var(--muted); font-size: 14px; padding: 14px; }
.composer-main { flex: 1; min-width: 0; }
.composer textarea { margin: 0; resize: none; border-radius: 20px; padding: 10px 14px; max-height: 140px; font-size: 16px; }
.file-name { font-size: 13px; color: var(--green-2); padding: 0 6px 6px; cursor: pointer; }
.attach { font-size: 22px; cursor: pointer; padding: 8px 2px; color: var(--muted); }
.send { flex: 0 0 44px; height: 44px; border-radius: 50%; border: 0; background: var(--green-2); color: #fff; font-size: 18px; cursor: pointer; }
.send:disabled { opacity: .5; }

/* ---------- WhatsApp QR ---------- */
.wa-card { text-align: center; }
.wa-card img { background: #fff; padding: 8px; border: 1px solid #eee; border-radius: 8px; max-width: 100%; height: auto; }
.wa-card .steps { text-align: left; max-width: 460px; margin: 14px auto 0; }

/* Mobile: a little more room for thumbs */
@media (max-width: 699px) {
  .topbar nav a { padding: 6px 7px; font-size: 13px; }
  main { padding: 8px; }
  .card { padding: 12px; }
}

/* ---------- Shifts ---------- */
.shift-banner { background: #fff4e5; color: #8a4b00; }
.tag-shift { background: #ffe0b2; color: #8a4b00; }
.shift-list { list-style: none; margin: 0; padding: 0; }
.shift-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid #eef0f1; }
.shift-row:last-child { border-bottom: 0; }
.shift-row .who { font-weight: 600; }
.shift-row .state { font-size: 13px; color: var(--muted); }
.shift-row .state.on { color: #8a4b00; font-weight: 600; }
.shift-row .btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-shift { background: #fb8c00; border-color: #fb8c00; color: #fff; }
.btn-shift:hover { background: #ef6c00; }
details.custom { margin-top: 12px; }
details.custom summary { cursor: pointer; color: var(--green-2); }
input[type=datetime-local] { width: 100%; font: inherit; padding: 10px 12px; margin-top: 4px; border: 1px solid #d1d7db; border-radius: 8px; }

/* ---------- AI ---------- */
.msg.ai { background: #f3e8ff; }
.msg .badge-ai { background: #e1c8ff; color: #5b21b6; }
.tag-ai { background: #e1c8ff; color: #5b21b6; }
.ai-box { border-left: 4px solid #8b5cf6; }
textarea.tall { min-height: 120px; resize: vertical; }
.kb-item { border-bottom: 1px solid #eef0f1; padding: 10px 0; }
.kb-item:last-child { border-bottom: 0; }
.kb-q { font-weight: 600; }
.kb-a { white-space: pre-wrap; color: #333; font-size: 15px; margin: 4px 0; }
.kb-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stat { display: inline-block; background: #f0f2f5; border-radius: 8px; padding: 8px 12px; margin: 0 6px 6px 0; font-size: 14px; }
.stat strong { font-size: 18px; display: block; }
