:root {
  --blue: #3390ec;
  --blue-dark: #2b7fd4;
  --bg: #fff;
  --chat-bg: #8ba4b8;
  --chat-bg-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/svg%3E");
  --in: #fff;
  --out: #eeffde;
  --muted: #707579;
  --border: #dadce0;
  --danger: #e53935;
  --media-max-w: 280px;
  --media-max-h: 320px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); overflow: hidden; }
#app { height: 100%; }
.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }
.topbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: calc(8px + var(--safe-top)) 12px 8px;
  background: var(--blue); color: #fff;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-brand { gap: 8px; }
.topbar-logo { flex-shrink: 0; object-fit: contain; background: transparent !important; }
.icon-btn { border: 0; background: transparent; color: inherit; width: 40px; height: 40px; border-radius: 50%; font-size: 22px; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.login-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; gap: 14px; }
.logo { width: 128px; height: 128px; margin: 0 auto 8px; object-fit: contain; display: block; background: transparent !important; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.field label { font-size: 13px; color: var(--muted); display:block; margin-bottom:6px; }
.field input { width:100%; border:1px solid var(--border); border-radius:12px; padding:14px 16px; font-size:16px; }
.login-hint { text-align:center; font-size:13px; color:var(--muted); margin:0; }
.btn { border:0; border-radius:12px; padding:14px; font-size:16px; font-weight:600; cursor:pointer; }
.btn-primary { background:var(--blue); color:#fff; width:100%; }
.error { color:var(--danger); text-align:center; min-height:20px; font-size:14px; }
.chat-list { flex:1; overflow-y:auto; -webkit-overflow-scrolling:touch; background:#fff; }
.chat-item { display:flex; gap:12px; padding:10px 14px; border-bottom:1px solid #ebebeb; cursor:pointer; align-items:center; }
.chat-item:active { background:#f4f4f5; }
.avatar { width:54px; height:54px; border-radius:50%; background:linear-gradient(135deg,#5b9bd5,var(--blue)); color:#fff; display:flex; align-items:center; justify-content:center; font-size:20px; font-weight:600; flex-shrink:0; }
.chat-meta { flex:1; min-width:0; }
.chat-title { font-weight:600; font-size:16px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-preview { color:var(--muted); font-size:14px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:2px; }
.chat-time { color:var(--muted); font-size:12px; flex-shrink:0; }
.chat-side { display:flex; flex-direction:column; align-items:flex-end; gap:6px; flex-shrink:0; }
.badge { min-width:22px; height:22px; padding:0 6px; border-radius:11px; background:var(--blue); color:#fff; font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; }
.chat-header { gap:8px; }
.chat-header-main { display:flex; align-items:center; gap:12px; flex:1; min-width:0; }
.chat-header-avatar { width:42px; height:42px; border-radius:50%; background:rgba(255,255,255,.22); color:#fff; display:flex; align-items:center; justify-content:center; font-size:18px; font-weight:700; flex-shrink:0; }
.chat-header-text { min-width:0; }
.chat-header-name { font-size:17px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-header-status { font-size:13px; opacity:.85; margin-top:1px; }
.messages { flex:1; overflow-y:auto; padding:10px 10px 16px; background-color:var(--chat-bg); background-image:var(--chat-bg-pattern); -webkit-overflow-scrolling:touch; }
.bubble-row { display:flex; margin-bottom:6px; padding:0 4px; }
.bubble-row.out { justify-content:flex-end; }
.bubble { max-width:min(420px, 78vw); padding:7px 11px 6px; border-radius:12px; box-shadow:0 1px 1px rgba(0,0,0,.08); word-wrap:break-word; position:relative; }
.bubble.has-media { padding:3px; max-width:calc(var(--media-max-w) + 6px); }
.bubble.in { background:var(--in); border-top-left-radius:4px; }
.bubble.out { background:var(--out); border-top-right-radius:4px; }
.bubble .sender { font-size:13px; font-weight:600; color:var(--blue); margin:4px 8px 2px; }
.bubble .text { font-size:15px; line-height:1.3125; white-space:pre-wrap; word-break:break-word; overflow-wrap:anywhere; padding:0 2px; margin:0; }
.bubble .time { font-size:11px; color:var(--muted); text-align:right; margin-top:3px; padding:0 2px; }
.bubble .time.media-time { position:absolute; right:8px; bottom:6px; margin:0; padding:2px 6px; border-radius:10px; background:rgba(0,0,0,.45); color:#fff; font-size:11px; line-height:1.2; pointer-events:none; }
.bubble-media { display:block; overflow:hidden; border-radius:10px; line-height:0; max-width:var(--media-max-w); min-width:120px; min-height:90px; background:#e8ecf0; }
.bubble.in .bubble-media { border-top-left-radius:4px; }
.bubble.out .bubble-media { border-top-right-radius:4px; }
.bubble-media img, .bubble-media video { display:block; width:auto; height:auto; max-width:var(--media-max-w); max-height:var(--media-max-h); object-fit:contain; cursor:pointer; }
.bubble-media .msg-photo.loading-img { filter: blur(6px); opacity:.85; transition: filter .15s ease, opacity .15s ease; }
.bubble-media .msg-photo:not(.loading-img) { filter:none; opacity:1; }
.bubble-media video { cursor:default; background:#000; }
.bubble .file-link { color:var(--blue); font-size:15px; word-break:break-all; display:inline-block; padding:4px 6px; }
.composer { flex:0 0 auto; display:flex; align-items:flex-end; gap:6px; padding:6px 8px calc(6px + var(--safe-bottom)); background:#fff; border-top:1px solid #e0e0e0; }
.composer textarea { flex:1; resize:none; border:0; border-radius:22px; padding:10px 14px; font-size:16px; font-family:inherit; max-height:120px; min-height:42px; background:#f0f2f5; }
.lightbox { position:fixed; inset:0; z-index:20; background:rgba(0,0,0,.92); display:flex; align-items:center; justify-content:center; padding:16px; overflow:hidden; touch-action:none; }
.lightbox.hidden { display:none !important; }
.lightbox img { max-width:100%; max-height:100%; object-fit:contain; transform-origin:center center; user-select:none; -webkit-user-drag:none; }
.lightbox-close { position:absolute; top:calc(12px + var(--safe-top)); right:12px; border:0; background:rgba(255,255,255,.15); color:#fff; width:40px; height:40px; border-radius:50%; font-size:20px; cursor:pointer; }
.lightbox-save { position:absolute; top:calc(12px + var(--safe-top)); right:60px; border:0; background:rgba(255,255,255,.15); color:#fff; width:40px; height:40px; border-radius:50%; font-size:20px; cursor:pointer; }
.composer .send, .composer .attach { width:40px; height:40px; border:0; border-radius:50%; background:var(--blue); color:#fff; font-size:18px; cursor:pointer; flex-shrink:0; }
.composer .attach { background:transparent; color:var(--muted); font-size:22px; }
.empty, .loading { padding:24px; text-align:center; color:var(--muted); }
.modal { position:fixed; inset:0; background:rgba(0,0,0,.45); display:none; align-items:center; justify-content:center; z-index:10; padding:16px; }
.modal.open { display:flex; }
.modal-box { background:#fff; border-radius:16px; width:100%; max-width:420px; max-height:80vh; overflow:hidden; display:flex; flex-direction:column; }
.modal-head { padding:16px; font-weight:700; border-bottom:1px solid #eee; }
.modal-body { overflow-y:auto; padding:8px; }
.user-pick { padding:12px 16px; border-bottom:1px solid #f0f0f0; cursor:pointer; }
.user-pick:active { background:#f5f5f5; }
.menu-btn { width:100%; text-align:left; border:0; background:#f5f7fa; border-radius:12px; padding:14px 16px; font-size:16px; margin-bottom:8px; cursor:pointer; }
.menu-btn:active { background:#e8ecf1; }
.menu-btn-active { background:#e3f2fd !important; border:1px solid #90caf9; }
.chat-icon-pin, .chat-icon-mute { font-size:12px; margin-right:4px; opacity:.75; }
.chat-item.pinned { background:#f8fbff; }
.user-check { display:block; padding:8px 4px; font-size:15px; cursor:pointer; }
.user-check input { margin-right:8px; }
.checks { max-height:200px; overflow-y:auto; border:1px solid var(--border); border-radius:12px; padding:8px 12px; }
.members-list { display:flex; flex-direction:column; gap:4px; }
.member-row { display:flex; align-items:center; gap:12px; padding:10px 6px; border-bottom:1px solid #f0f0f0; }
.member-row:last-child { border-bottom:0; }
.member-avatar { width:42px; height:42px; border-radius:50%; background:linear-gradient(135deg,#5b9bd5,var(--blue)); color:#fff; display:flex; align-items:center; justify-content:center; font-size:17px; font-weight:600; flex-shrink:0; }
.member-meta { min-width:0; flex:1; }
.member-name { font-size:15px; font-weight:600; }
.modal-box.modal-wide { max-width: min(720px, 96vw); }
.modal-wide .modal-body { padding: 16px; }
.sch-menu-btn { width: 100%; margin-bottom: 10px; }
.sch-cards { display: flex; flex-direction: column; gap: 12px; max-height: 58vh; overflow-y: auto; padding-right: 2px; }
.sch-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #f8f9fb; }
.sch-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 600; font-size: 14px; color: #111; }
.sch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sch-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.sch-field input, .sch-field select, .sch-field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-size: 14px; box-sizing: border-box; background: #fff; min-height: 42px;
}
.sch-field textarea { min-height: 72px; resize: vertical; }
.sch-field-full { grid-column: 1 / -1; }
.sch-reminds { display: flex; flex-direction: column; gap: 8px; }
.sch-remind-row { display: flex; gap: 8px; align-items: center; }
.sch-remind-row input { flex: 1; }
.sch-icon-btn { border: 0; background: #eef1f5; border-radius: 8px; font-size: 13px; cursor: pointer; color: #555; padding: 8px 10px; white-space: nowrap; }
.sch-icon-btn:hover { background: #e2e6eb; }
.sch-add-remind { margin-top: 4px; width: auto !important; padding: 8px 14px !important; font-size: 13px !important; }
.sch-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; align-items: center; }
.sch-actions .btn { padding: 12px 16px; font-size: 15px; }
.sch-actions .btn-primary { flex: 1; min-width: 160px; }
.sch-actions label { display: flex; align-items: center; gap: 8px; font-size: 14px; flex-wrap: wrap; }
.sch-actions input[type="date"] { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.sch-list-cards { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto; }
.sch-list-item { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: #fff; }
.sch-list-item-title { font-weight: 600; font-size: 15px; margin-bottom: 6px; line-height: 1.35; }
.sch-list-item-meta { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.sch-list-item-foot { margin-top: 10px; }
.sch-status { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.sch-status-done { background: #e8f5e9; color: #2e7d32; }
.sch-status-failed { background: #ffebee; color: #c62828; }
.sch-status-sent { background: #e3f2fd; color: #1565c0; }
.sch-status-scheduled { background: #f3e5f5; color: #6a1b9a; }
@media (min-width: 600px) {
  .sch-grid { grid-template-columns: 1fr 1fr 1fr; }
  .modal-box.modal-wide { max-width: min(860px, 96vw); }
}
.task-card { padding: 4px 0; }
.task-card-title { font-weight: 600; margin-bottom: 4px; }
.task-card-meta { font-size: 12px; margin-bottom: 2px; }
.task-card-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.task-card-actions .btn { flex: 1; min-width: 110px; padding: 8px; font-size: 14px; }
.task-fail-comment { font-size: 12px; margin-top: 4px; }
.task-popup-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.task-popup-box { background: #fff; border-radius: 16px; padding: 20px; max-width: 420px; width: 100%; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.task-popup-box h3 { margin: 0 0 12px; font-size: 18px; }
.chat-search-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: #f8f9fb;
}
.chat-search-bar input {
  flex: 1; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; box-sizing: border-box;
}
.group-status-tap { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.member-row-clickable { cursor: pointer; border-radius: 10px; }
.member-row-clickable:hover, .member-row-clickable:focus { background: #f0f4f8; outline: none; }
.msg-sender { font-size: 12px; font-weight: 600; color: #3390ec; margin: 0 4px 3px; cursor: pointer; }
.msg-sender:hover { text-decoration: underline; }
.bubble-row.search-hidden { display: none !important; }
.bubble-row.search-hit .bubble { box-shadow: 0 0 0 2px rgba(51,144,236,.35); }
.contacts-search-wrap { margin-bottom: 10px; }
.contacts-search-wrap input {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; box-sizing: border-box;
}
.member-status { font-size:13px; color:var(--muted); margin-top:2px; }
.member-status.online { color:var(--blue); font-weight:500; }
.settings-body { flex:1; overflow-y:auto; padding:16px; }
.settings-profile { display:flex; gap:14px; align-items:center; padding:12px 0 20px; }
.settings-avatar { border-radius:18px; object-fit:contain; background:transparent; }
.settings-section { font-size:13px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; margin:16px 0 8px; }
.settings-row { display:flex; justify-content:space-between; align-items:center; padding:14px 0; border-bottom:1px solid #f0f0f0; font-size:16px; }
.settings-row input { width:22px; height:22px; }
.settings-foot { text-align:center; margin-top:24px; font-size:13px; }
.muted { color:var(--muted); }
.btn-danger { background:var(--danger); color:#fff; width:100%; margin-top:8px; }
.hidden { display:none !important; }
