:root {
  --bg: #0f172a; --panel: #1e293b; --panel2: #263449; --text: #e5e7eb; --muted: #94a3b8;
  --accent: #22c55e; --accent2: #16a34a; --user: #2563eb; --danger: #ef4444; --warn: #f59e0b;
  --radius: 14px; --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: #93c5fd; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* --- приложение (чат) --- */
body.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--sat)) 12px 8px; background: var(--panel); border-bottom: 1px solid #334155; }
.brand { font-weight: 700; letter-spacing: .3px; }
.badge { flex: 1; text-align: center; font-variant-numeric: tabular-nums; background: #14532d; color: #bbf7d0; padding: 4px 10px; border-radius: 999px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { margin-left: auto; display: flex; gap: 4px; }
.iconbtn { background: transparent; border: 0; color: var(--text); font-size: 20px; padding: 6px 8px; border-radius: 10px; text-decoration: none; }
.iconbtn:active { background: var(--panel2); }

.panel { background: var(--panel2); padding: 10px 14px; border-bottom: 1px solid #334155; }
.ex-title { font-weight: 600; }
.ex-plan { color: var(--muted); font-size: 14px; }
.timers { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.timer-box { display: flex; flex-direction: column; align-items: center; min-width: 76px; }
.timer-box .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rest-btn { flex: 1; background: var(--accent); color: #052e16; border: 0; border-radius: 12px; padding: 12px; font-weight: 700; font-size: 16px; }
.rest-btn:active { background: var(--accent2); }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 6px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; flex-direction: column; margin: 6px 0; max-width: 88%; }
.msg.user { align-self: flex-end; margin-left: auto; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: var(--radius); background: var(--panel); white-space: normal; word-wrap: break-word; }
.msg.user .bubble { background: var(--user); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { border-bottom-left-radius: 4px; }
.bubble ul { margin: 4px 0 4px 18px; padding: 0; }
.bubble code { background: #0b1220; padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.meta { font-size: 11px; color: var(--muted); margin: 3px 6px 0; }
.dots { letter-spacing: 3px; color: var(--muted); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.tools { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-block; font-size: 12px; background: #0b1220; color: #cbd5e1; padding: 2px 8px; border-radius: 999px; border: 1px solid #334155; }
.chip.bad { border-color: var(--danger); color: #fca5a5; }
.gif { margin: 6px 0 0; max-width: 100%; }
.gif img { width: 100%; max-width: 360px; border-radius: 12px; display: block; background: #000; }
.gif figcaption { font-size: 12px; color: var(--muted); margin-top: 2px; }
.linkcard { display: inline-block; margin-top: 6px; padding: 8px 12px; background: var(--panel); border-radius: 10px; text-decoration: none; }
.attach-note { font-size: 12px; color: #dbeafe; margin-top: 4px; }

.banner { margin: 0 12px 6px; padding: 8px 12px; border-radius: 10px; font-size: 14px; background: var(--panel2); }
.banner.warn { background: #78350f; color: #fef3c7; }
.banner.ok { background: #14532d; color: #dcfce7; }

.actions { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 8px; scrollbar-width: none; }
.actions::-webkit-scrollbar { display: none; }
.action { flex: 0 0 auto; background: var(--panel2); color: var(--text); border: 1px solid #334155; border-radius: 999px; padding: 8px 16px; font-size: 15px; }
.action:active { background: var(--accent); color: #052e16; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + var(--sab)); background: var(--panel); border-top: 1px solid #334155; }
.composer textarea { flex: 1; resize: none; border: 1px solid #334155; background: #0b1220; color: var(--text); border-radius: 18px; padding: 10px 14px; font: inherit; max-height: 140px; outline: none; }
.sendbtn { background: var(--accent); color: #052e16; border: 0; border-radius: 50%; width: 42px; height: 42px; font-size: 18px; }
.attach-preview { padding: 0 12px 8px; background: var(--panel); display: flex; gap: 6px; flex-wrap: wrap; }
.attach-preview b { cursor: pointer; margin-left: 4px; }

/* --- простые страницы (вход, админ) --- */
body.page { padding: calc(16px + var(--sat)) 12px calc(16px + var(--sab)); min-height: 100dvh; }
.card { max-width: 960px; margin: 0 auto; background: var(--panel); border-radius: var(--radius); padding: 20px; }
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card h2 { font-size: 17px; margin: 22px 0 8px; }
.muted { color: var(--muted); }
.error { color: #fca5a5; min-height: 1.2em; }
.form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid #334155; background: #0b1220; color: var(--text); }
.form button, .filters button, .card form > button { background: var(--accent); color: #052e16; border: 0; border-radius: 10px; padding: 12px; font-weight: 700; }
.nav { margin-bottom: 8px; color: var(--muted); }
.filters { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.filters select { font: inherit; padding: 8px; border-radius: 8px; background: #0b1220; color: var(--text); border: 1px solid #334155; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { border-bottom: 1px solid #334155; padding: 6px 6px; text-align: left; vertical-align: top; }
.tbl tr.bad td { background: #3f1d1d; }
.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre { background: #0b1220; padding: 10px; border-radius: 10px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
details { margin: 6px 0; }
button.small { font-size: 12px; padding: 4px 8px; border-radius: 8px; border: 1px solid #334155; background: var(--panel2); color: var(--text); }
