:root {
    --red: #EF3124;
    --red-dark: #d42b1f;
    --blue: #306FEE;
    --blue-dark: #1a5ad9;
    --black: #000000;
    --gray-50: #F7F7F8;
    --gray-100: #eeeef0;
    --gray-200: #dddde0;
    --gray-300: #c4c4c8;
    --gray-400: #9999a0;
    --gray-500: #666670;
    --gray-600: #444450;
    --gray-700: #222230;
    --white: #FFFFFF;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-50);
    color: var(--black);
    min-height: 100vh;
}

/* Chat page */
.chat-container {
    max-width: 760px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--white);
}

.chat-header {
    background: var(--white);
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.chat-header .logo {
    width: 36px;
    height: 36px;
    background: var(--red);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 700;
    font-size: 1.1rem;
}

.chat-header .header-text { flex: 1; }
.chat-header h1 { font-size: 1.1rem; font-weight: 600; color: var(--black); }
.chat-header .subtitle { color: var(--gray-400); font-size: 0.8rem; }

.admin-link {
    color: var(--gray-400);
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.15s;
}
.admin-link:hover { background: var(--gray-100); color: var(--black); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--white);
}

.message {
    max-width: 82%;
    display: flex;
    flex-direction: column;
    animation: fadeInUp 0.25s ease;
}

@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.55;
    font-size: 0.95rem;
    word-wrap: break-word;
}

.message.user .message-content {
    background: var(--blue);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--gray-50);
    color: var(--black);
    border-bottom-left-radius: 4px;
}

.message.assistant .message-content p { margin-bottom: 6px; }
.message.assistant .message-content p:last-child { margin-bottom: 0; }
.message.assistant .message-content ul, .message.assistant .message-content ol { margin: 6px 0 6px 18px; }
.message.assistant .message-content li { margin-bottom: 3px; }
.message.assistant .message-content strong { font-weight: 600; }
.message.assistant .message-content a { color: var(--blue); text-decoration: none; }
.message.assistant .message-content a:hover { text-decoration: underline; }
.message.assistant .message-content em { color: var(--gray-500); }
.message.assistant .message-content blockquote {
    border-left: 3px solid var(--red);
    padding: 8px 12px;
    margin: 8px 0;
    background: var(--white);
    border-radius: 0 8px 8px 0;
    font-size: 0.9rem;
}
.message.assistant .message-content code {
    background: var(--gray-200);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.message.assistant .message-content .cta-block {
    margin-top: 10px;
    padding: 12px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    font-size: 0.88rem;
}

.chat-input {
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 10px;
    background: var(--white);
    flex-shrink: 0;
}

.chat-input textarea {
    flex: 1;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    color: var(--black);
    padding: 10px 16px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border 0.15s;
}
.chat-input textarea:focus { border-color: var(--blue); }
.chat-input textarea::placeholder { color: var(--gray-400); }

.chat-input .new-chat-btn {
    width: 44px; height: 44px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    color: var(--gray-500);
    font-size: 1.3rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}
.chat-input .new-chat-btn:hover { background: var(--gray-100); color: var(--black); }

.chat-input button:not(.new-chat-btn) {
    width: 44px; height: 44px;
    background: var(--blue);
    border: none;
    border-radius: 12px;
    color: var(--white);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-input button:not(.new-chat-btn):hover { background: var(--blue-dark); }
.chat-input button:disabled { background: var(--gray-300); cursor: not-allowed; }

/* Typing indicator */
.typing-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gray-400);
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

/* CTA buttons */
.cta-buttons { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.cta-btn {
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.cta-order {
    background: var(--red);
    color: var(--white);
}
.cta-order:hover { background: var(--red-dark); transform: translateY(-1px); }
.cta-manager {
    background: var(--white);
    color: var(--blue);
    border: 1.5px solid var(--blue);
}
.cta-manager:hover { background: var(--blue); color: var(--white); }

/* Popup */
.popup-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center; justify-content: center;
    animation: fadeIn 0.2s ease;
}
.popup-card {
    background: var(--white);
    border-radius: 16px;
    padding: 32px 28px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    animation: popupSlide 0.3s ease;
}
@keyframes popupSlide { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.popup-icon {
    font-size: 2rem; font-weight: 700;
    width: 56px; height: 56px;
    line-height: 56px;
    margin: 0 auto 12px;
    border-radius: 50%;
}
.popup-icon.ok { background: #f0fdf4; color: #16a34a; }
.popup-icon.info { background: #eff6ff; color: var(--blue); }
.popup-card h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 10px; color: var(--black); }
.popup-card p { font-size: 0.9rem; color: var(--gray-500); margin-bottom: 6px; line-height: 1.5; }
.popup-contact { font-weight: 600; color: var(--black) !important; margin-top: 10px; }
.popup-hours { font-size: 0.8rem !important; color: var(--gray-400) !important; }
.popup-close {
    margin-top: 16px;
    background: var(--red);
    color: var(--white);
    border: none;
    border-radius: 10px;
    padding: 10px 32px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}
.popup-close:hover { background: var(--red-dark); }

/* Login */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--gray-50);
}

.login-form {
    background: var(--white);
    padding: 40px;
    border-radius: 16px;
    border: 1px solid var(--gray-200);
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.06);
}

.login-form .logo-block {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.login-form .logo-sq {
    width: 40px; height: 40px;
    background: var(--red);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: var(--white); font-weight: 700; font-size: 1.2rem;
}

.login-form h1 { font-size: 1.2rem; font-weight: 600; }

.login-form input {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    color: var(--black);
    padding: 12px 14px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border 0.15s;
}
.login-form input:focus { border-color: var(--blue); }

.login-form button {
    background: var(--red);
    color: var(--white);
    border: none;
    border-radius: 10px;
    padding: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.login-form button:hover { background: var(--red-dark); }

.error { color: var(--red); font-size: 0.85rem; text-align: center; }

/* Admin layout */
.admin-layout {
    display: flex;
    min-height: 100vh;
    background: var(--gray-50);
}

.admin-nav {
    width: 250px;
    background: var(--white);
    padding: 20px 14px 16px;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.admin-nav .nav-logo {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 8px 18px; border-bottom: 1px solid var(--gray-100); margin-bottom: 12px;
}

.admin-nav .nav-logo .sq {
    width: 34px; height: 34px;
    background: var(--red);
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    color: var(--white); font-weight: 700; font-size: 0.95rem;
}

.admin-nav .nav-logo span { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }

.admin-nav a {
    color: var(--gray-600);
    text-decoration: none;
    padding: 9px 12px;
    border-radius: 9px;
    font-size: 0.89rem;
    font-weight: 500;
    transition: all 0.12s;
    line-height: 1.2;
}
.admin-nav a:hover { background: var(--gray-50); color: var(--black); }
.admin-nav a.active { background: var(--blue); color: var(--white); box-shadow: 0 2px 8px rgba(48,111,238,0.3); }

.admin-main {
    flex: 1;
    padding: 36px 44px;
    overflow-y: auto;
    max-width: 1180px;
    width: 100%;
}

.admin-main h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    padding: 20px 22px;
    box-shadow: 0 1px 2px rgba(16,24,40,0.04);
    transition: box-shadow 0.15s, transform 0.15s;
}
.stat-card:hover { box-shadow: 0 6px 20px rgba(16,24,40,0.08); transform: translateY(-2px); }

.stat-value { display: block; font-size: 2.1rem; font-weight: 700; color: var(--blue); letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { display: block; font-size: 0.82rem; color: var(--gray-500); margin-top: 6px; font-weight: 500; }

.btn {
    display: inline-block;
    background: var(--red);
    color: var(--white);
    padding: 10px 20px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.15s;
}
.btn:hover { background: var(--red-dark); }

/* Search */
.search-form {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.search-form input {
    flex: 1;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    color: var(--black);
    padding: 10px 14px;
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
}
.search-form input:focus { border-color: var(--blue); }
.search-form button {
    background: var(--blue);
    color: var(--white);
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.9rem;
}
.search-form a { color: var(--gray-500); text-decoration: none; align-self: center; font-size: 0.85rem; }
.search-form a:hover { color: var(--red); }

/* Table */
.chats-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--gray-200);
}
.chats-table th, .chats-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.88rem;
}
.chats-table th { color: var(--gray-500); font-weight: 600; background: var(--gray-50); font-size: 0.8rem; text-transform: uppercase; }
.chats-table tr:last-child td { border-bottom: none; }
.chats-table a { color: var(--blue); text-decoration: none; font-weight: 500; }
.chats-table a:hover { text-decoration: underline; }

/* Chat log */
.chat-log { margin-top: 20px; }
.meta { color: var(--gray-500); font-size: 0.85rem; margin-bottom: 20px; }

.log-message {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 18px;
    margin-bottom: 12px;
}
.log-message.user { border-left: 3px solid var(--blue); }
.log-message.assistant { border-left: 3px solid var(--red); }
.log-role { font-weight: 600; margin-bottom: 4px; font-size: 0.85rem; }
.log-time { color: var(--gray-400); font-size: 0.75rem; margin-bottom: 8px; }
.log-content { white-space: pre-wrap; line-height: 1.6; font-size: 0.9rem; }

.admin-main > a.back-link { color: var(--blue); text-decoration: none; font-size: 0.85rem; font-weight: 500; }
.admin-main > a.back-link:hover { text-decoration: underline; }

/* ============================================================
   Admin v2 — общий layout, навигация, формы, прайс, промпт, чат
   ============================================================ */

/* Navigation */
.admin-nav .spacer { flex: 1; }
.admin-nav .nav-sep { height: 1px; background: var(--gray-200); margin: 8px 4px; }
.admin-nav .nav-group-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--gray-400); padding: 4px 12px; font-weight: 600; }
.admin-nav a.nav-logout { color: var(--red); }
.admin-nav a.nav-logout:hover { background: #fef2f2; color: var(--red); }

/* Page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 4px; }
.page-head .sub { color: var(--gray-500); font-size: 0.85rem; max-width: 60ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn-sm { padding: 8px 14px; font-size: 0.82rem; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-family: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; transition: all .15s; }
.btn-red { background: var(--red); color: #fff; } .btn-red:hover { background: var(--red-dark); }
.btn-blue { background: var(--blue); color: #fff; } .btn-blue:hover { background: var(--blue-dark); }
.btn-ghost { background: var(--white); color: var(--gray-600); border: 1px solid var(--gray-200); } .btn-ghost:hover { background: var(--gray-100); color: var(--black); }
.btn-gray { background: var(--gray-300); color: var(--black); } .btn-gray:hover { background: var(--gray-400); }

/* Status banner */
.status-msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 0.9rem; display: none; }
.status-msg.ok { background: #f0fdf4; color: #16a34a; }
.status-msg.error { background: #fef2f2; color: var(--red); }

/* Price management */
.price-cat { margin-bottom: 18px; background: var(--white); border: 1px solid var(--gray-200); border-radius: 12px; overflow: hidden; }
.price-cat.inactive { opacity: 0.55; }
.price-cat-head { display: flex; align-items: center; gap: 12px; padding: 13px 16px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }
.price-cat-head .title { font-weight: 600; font-size: 1rem; }
.price-cat-head .desc { font-size: 0.8rem; color: var(--gray-400); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.price-cat-head .count { font-size: 0.78rem; color: var(--gray-400); white-space: nowrap; }
.badge { font-size: 0.68rem; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.badge.on { background: #f0fdf4; color: #16a34a; }
.badge.off { background: #fef2f2; color: var(--red); }
.price-item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--gray-100); }
.price-item:last-child { border-bottom: none; }
.price-item.inactive { opacity: 0.45; }
.price-item .body { flex: 1; min-width: 0; }
.price-item .name { font-size: 0.9rem; font-weight: 500; }
.price-item .desc { font-size: 0.78rem; color: var(--gray-500); margin-top: 2px; }
.price-item .url-link { font-size: 0.75rem; color: var(--blue); text-decoration: none; display: inline-block; margin-top: 3px; }
.price-item .url-link:hover { text-decoration: underline; }
.price-item .price { font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
.drag-handle { cursor: grab; color: var(--gray-300); font-size: 1rem; user-select: none; }
.icon-btn { background: none; border: 1px solid var(--gray-200); border-radius: 7px; padding: 5px 10px; cursor: pointer; font-size: 0.76rem; color: var(--gray-600); transition: all .15s; }
.icon-btn:hover { background: var(--gray-100); color: var(--black); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: #fef2f2; }
.empty-row { padding: 16px; color: var(--gray-400); font-size: 0.85rem; }

/* Modal + forms */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 100; display: none; align-items: center; justify-content: center; animation: fadeIn .15s ease; }
.modal-backdrop.open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box { background: var(--white); border-radius: 14px; padding: 24px; max-width: 520px; width: 92%; max-height: 88vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.18); }
.modal-box h3 { margin-bottom: 18px; }
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-field label { font-size: 0.8rem; color: var(--gray-500); font-weight: 500; }
.form-field input, .form-field select, .form-field textarea { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 8px; padding: 9px 12px; font-size: 0.9rem; font-family: inherit; outline: none; transition: border .15s; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--blue); background: var(--white); }
.form-field textarea { resize: vertical; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; margin: 4px 0 16px; }
.modal-actions { display: flex; gap: 8px; }

/* Prompt editor */
.prompt-editor { width: 100%; min-height: 520px; background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 10px; padding: 16px; font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace; font-size: 0.84rem; line-height: 1.6; resize: vertical; outline: none; color: var(--gray-700); }
.prompt-editor:focus { border-color: var(--blue); background: var(--white); }
.hint { font-size: 0.82rem; color: var(--gray-600); background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; line-height: 1.5; }
.hint code { background: var(--gray-200); padding: 1px 6px; border-radius: 4px; font-size: 0.8rem; }

/* Chat test embed (chat UI внутри admin-main) */
.chat-embed { height: calc(100vh - 170px); min-height: 460px; max-width: 880px; border: 1px solid var(--gray-200); border-radius: 16px; overflow: hidden; background: var(--white); display: flex; flex-direction: column; box-shadow: 0 1px 3px rgba(16,24,40,0.05); }
.chat-embed .chat-messages { padding: 22px; gap: 16px; }
.chat-embed .message { max-width: 88%; }
.chat-embed .message-content { font-size: 0.95rem; }
.chat-embed .chat-input { border-top: 1px solid var(--gray-200); padding: 14px 18px; }
