/* BestWay Admin — современный минималистичный дизайн */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #f1f5f9;
  --sidebar-hover: #1e293b;
  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
}

/* Тёмная тема */
body.theme-dark {
  --content-bg: #0f172a;
  --card-bg: #1e293b;
  --card-border: #475569;
  --text: #f8fafc;
  --text-muted: #cbd5e1;
  --sidebar-active: #38bdf8;
}
body.theme-dark .admin-table tbody tr:hover { background: #334155; }
body.theme-dark .admin-table th { color: #cbd5e1; }
body.theme-dark .admin-table td { color: #f8fafc; }
body.theme-dark .admin-table code { background: #334155; color: #e2e8f0; }
body.theme-dark .chat-item { color: #f8fafc; }
body.theme-dark .chat-item:hover { background: #334155; }
body.theme-dark .chat-item.active { background: #0c4a6e; color: #fff; }
body.theme-dark .chat-item-meta { color: #94a3b8; }
body.theme-dark .chat-msg.client { background: #334155; color: #f8fafc; }
body.theme-dark .chat-msg.client .msg-author,
body.theme-dark .chat-msg.client .msg-time { color: #cbd5e1; opacity: 1; }
body.theme-dark .chat-msg.admin .msg-author,
body.theme-dark .chat-msg.admin .msg-time { opacity: 0.9; }
body.theme-dark .chat-header { color: #f8fafc; }
body.theme-dark .chat-empty { color: #94a3b8; }
body.theme-dark .form-control, body.theme-dark .form-select { background: #334155; border-color: #475569; color: #f8fafc; }
body.theme-dark .form-control::placeholder { color: #94a3b8; }
body.theme-dark .form-label { color: #e2e8f0; }
body.theme-dark .admin-card h5 { color: #94a3b8; }
body.theme-dark .admin-card .card-value { color: #f8fafc; }
body.theme-dark .alert-success { background: #14532d; color: #bbf7d0; border-color: #166534; }
body.theme-dark .alert-danger { background: #7f1d1d; color: #fecaca; border-color: #991b1b; }
body.theme-dark .alert-warning { background: #78350f; color: #fde68a; border-color: #92400e; }
body.theme-dark .login-card { background: #1e293b; color: #f8fafc; }
body.theme-dark .login-card h1 { color: #f8fafc; }
body.theme-dark .login-card .form-label { color: #cbd5e1; }
body.theme-dark .login-card .form-control { background: #334155; border-color: #475569; color: #f8fafc; }
body.theme-dark .sql-toggle { color: #cbd5e1; }
body.theme-dark .sql-toggle:hover { background: #334155; color: #f8fafc; }
body.theme-dark .chat-input-row .btn-attach { color: #cbd5e1; border-color: #475569; }
body.theme-dark .chat-input-row .btn-attach:hover { background: #334155; color: #f8fafc; }

* { box-sizing: border-box; }
body { font-family: 'DM Sans', system-ui, sans-serif; margin: 0; color: var(--text); background: var(--content-bg); }

/* Layout */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar-bg);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}
.admin-sidebar-brand {
  padding: 1.25rem 1.5rem; font-weight: 700; font-size: 1.1rem; color: white;
  border-bottom: 1px solid rgba(255,255,255,0.06); text-decoration: none;
}
.admin-sidebar-nav { flex: 1; padding: 1rem 0.5rem; overflow-y: auto; }
.admin-sidebar-nav a {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem;
  color: var(--sidebar-text); text-decoration: none; border-radius: 8px;
  font-size: 0.9rem; font-weight: 500; margin-bottom: 2px;
}
.admin-sidebar-nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-active); }
.admin-sidebar-nav a.active { background: rgba(14,165,233,0.15); color: var(--accent); }
.admin-sidebar-nav .nav-group { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 0.75rem 1rem 0.25rem; }
.admin-sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,0.06); }
.admin-sidebar-footer a { color: var(--sidebar-text); text-decoration: none; font-size: 0.875rem; padding: 0.4rem 0; display: block; }
.admin-sidebar-footer a:hover { color: var(--accent); }
.admin-main { flex: 1; margin-left: 240px; padding: 1.5rem 2rem; min-height: 100vh; }

/* Mobile */
@media (max-width: 768px) {
  .admin-sidebar { width: 64px; padding: 0.5rem 0; }
  .admin-sidebar-brand .brand-text { display: none; }
  .admin-sidebar-nav .nav-text, .admin-sidebar-nav .nav-group { display: none; }
  .admin-sidebar-nav a { justify-content: center; padding: 0.75rem; }
  .admin-main { margin-left: 64px; padding: 1rem; }
}

/* Page header */
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; color: var(--text); }

/* Cards */
.admin-card {
  background: var(--card-bg); border-radius: 12px; border: 1px solid var(--card-border);
  padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.admin-card h5 { font-size: 0.875rem; font-weight: 600; color: var(--text-muted); margin: 0 0 0.5rem; }
.admin-card .card-value { font-size: 1.75rem; font-weight: 700; color: var(--text); }

/* Stat grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.stats-status { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.admin-card-status .card-value { font-size: 1.5rem; }

/* Tables */
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th {
  text-align: left; padding: 0.75rem 1rem; font-weight: 600; color: var(--text-muted);
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--card-border);
}
.admin-table td { padding: 0.75rem 1rem; border-bottom: 1px solid #f1f5f9; }
.admin-table tbody tr:hover { background: #f8fafc; }
.admin-table code { font-size: 0.85em; background: #f1f5f9; padding: 0.2em 0.4em; border-radius: 4px; }

/* Forms */
.form-label { font-weight: 500; color: var(--text); font-size: 0.9rem; }
.form-control, .form-select {
  font-family: inherit; font-size: 0.9rem;
  border-radius: 8px; border: 1px solid var(--card-border); padding: 0.6rem 0.85rem;
}
.form-control:focus, .form-select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}
.admin-form .form-label,
.admin-form .form-control,
.admin-form .form-select { display: block; width: 100%; }
.admin-form .form-control, .admin-form .form-select { margin-bottom: 0; }

/* Buttons */
.btn-admin { background: var(--accent); color: white; border: none; padding: 0.6rem 1.25rem; border-radius: 8px; font-weight: 600; font-size: 0.9rem; cursor: pointer; }
.btn-admin:hover { background: var(--accent-hover); color: white; }
.btn-admin:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-outline-admin { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn-outline-admin:hover { background: rgba(14,165,233,0.1); color: var(--accent); }

/* Alerts */
.alert-admin { padding: 1rem 1.25rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); }
.login-card {
  width: 100%; max-width: 380px; background: white; border-radius: 16px;
  padding: 2rem; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.login-card h1 { font-size: 1.5rem; margin: 0 0 1.5rem; color: var(--text); }
.login-card .form-label { font-weight: 500; color: var(--text-muted); }
.login-card .form-control { padding: 0.75rem; border-radius: 8px; }
.login-card .btn-admin { width: 100%; padding: 0.75rem; margin-top: 0.5rem; }

/* DB editor */
.db-toolbar { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin-bottom: 1rem; }
.db-toolbar .form-select { max-width: 200px; }
.db-toolbar .btn-group { display: flex; gap: 0.5rem; }
.table-wrapper { max-height: 70vh; overflow: auto; border: 1px solid var(--card-border); border-radius: 8px; }
.table-wrapper thead th { position: sticky; top: 0; z-index: 1; background: var(--card-bg) !important; box-shadow: 0 1px 0 var(--card-border); }
.table-wrapper .admin-table th, .table-wrapper .admin-table td { min-width: 80px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.table-wrapper td.editable { cursor: pointer; }
.table-wrapper td.editable:hover { background: #e0f2fe; }
.col-actions { min-width: 90px; }
.hidden { display: none !important; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.sql-toggle { background: transparent; border: 1px solid var(--card-border); color: var(--text-muted); padding: 0.5rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.875rem; margin-bottom: 0.5rem; }
.sql-toggle:hover { background: #f1f5f9; }
.sql-panel { margin-top: 0.5rem; padding-top: 1rem; border-top: 1px solid var(--card-border); }
.sql-panel textarea { font-family: ui-monospace, monospace; font-size: 0.9rem; }

.mb-3 { margin-bottom: 1rem; }

/* Reference page */
.ref-tag { background: #f1f5f9; padding: 0.35rem 0.75rem; border-radius: 6px; font-size: 0.9rem; }
.ref-row { padding: 0.5rem 0; border-bottom: 1px solid #f1f5f9; font-size: 0.9rem; }
.ref-row:last-child { border-bottom: none; }
.ref-price { color: var(--accent); font-weight: 600; }
.ref-row small { color: var(--text-muted); }
body.theme-dark .ref-tag { background: #334155; color: #f8fafc; }
body.theme-dark .ref-row { border-bottom-color: #475569; color: #f8fafc; }
body.theme-dark .ref-row small { color: #94a3b8; }

/* Chats */
.chats-layout { display: flex; gap: 1rem; height: calc(100vh - 4rem); min-height: 400px; }
.chats-sidebar { width: 280px; flex-shrink: 0; background: var(--card-bg); border-radius: 12px; border: 1px solid var(--card-border); overflow: hidden; display: flex; flex-direction: column; }
.chat-filters { display: flex; padding: 0.5rem; gap: 0.25rem; border-bottom: 1px solid var(--card-border); }
.chat-filter-btn { flex: 1; padding: 0.5rem; border: 1px solid var(--card-border); background: transparent; border-radius: 6px; cursor: pointer; font-size: 0.85rem; color: var(--text-muted); }
.chat-filter-btn:hover { background: #f1f5f9; color: var(--text); }
.chat-filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
body.theme-dark .chat-filter-btn:hover { background: #334155; color: #f8fafc; }
.chats-list { flex: 1; overflow-y: auto; }
.chat-header-row { display: flex; align-items: center; gap: 0.5rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--card-border); }
.chat-header-row .chat-header { flex: 1; font-weight: 600; min-width: 0; }
.chat-header-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.status-select { max-width: 180px; font-size: 0.85rem; padding: 0.4rem 0.6rem; }
.btn-archive { padding: 0.4rem 0.75rem; border: 1px solid var(--card-border); background: transparent; border-radius: 6px; cursor: pointer; font-size: 0.85rem; color: var(--text-muted); }
.btn-archive:hover { background: #f1f5f9; color: var(--text); }
body.theme-dark .btn-archive:hover { background: #334155; color: #f8fafc; }
.chat-item { padding: 1rem; border-bottom: 1px solid var(--card-border); cursor: pointer; transition: background 0.15s; }
.chat-item:hover { background: #f8fafc; }
.chat-item.active { background: #e0f2fe; }
.chat-item-title { font-weight: 600; font-size: 0.9rem; }
.chat-item-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.chats-main { flex: 1; display: flex; flex-direction: column; background: var(--card-bg); border-radius: 12px; border: 1px solid var(--card-border); overflow: hidden; min-width: 0; }
.chat-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--card-border); font-weight: 600; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.chat-msg { max-width: 85%; padding: 0.6rem 1rem; border-radius: 12px; font-size: 0.9rem; }
.chat-msg.client { align-self: flex-start; background: #f1f5f9; }
.chat-msg.admin { align-self: flex-end; background: var(--accent); color: white; }
.chat-msg .msg-author { font-size: 0.75rem; opacity: 0.8; margin-bottom: 0.2rem; }
.chat-msg .msg-time { font-size: 0.7rem; opacity: 0.7; margin-top: 0.2rem; }
.chat-input-row { padding: 1rem; border-top: 1px solid var(--card-border); display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.chat-input-row input { flex: 1; min-width: 120px; }
.chat-input-row .btn-attach { padding: 0.6rem; border: 1px solid var(--card-border); background: transparent; border-radius: 8px; cursor: pointer; color: var(--text-muted); }
.chat-input-row .btn-attach:hover { background: #f1f5f9; color: var(--text); }
body.theme-dark .chat-input-row .btn-attach:hover { background: #334155; }
.chat-msg .msg-img { max-width: 280px; max-height: 200px; border-radius: 8px; cursor: pointer; margin-top: 0.25rem; display: block; }
.chat-msg .msg-img:hover { opacity: 0.9; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.95rem; }
.media-lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 9999; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.media-lightbox.hidden { display: none !important; }
.media-lightbox img { max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: 8px; }
.msg-img-wrap { display: inline-block; }
.theme-toggle { padding: 0.5rem 1rem; font-size: 0.85rem; background: transparent; border: 1px solid var(--sidebar-text); color: var(--sidebar-text); border-radius: 6px; cursor: pointer; margin: 0.5rem 1rem; }
.theme-toggle:hover { background: var(--sidebar-hover); }
@media (max-width: 768px) { .chats-layout { flex-direction: column; height: auto; min-height: 500px; } .chats-sidebar { width: 100%; max-height: 200px; } }
