:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel2: #182338;
  --line: rgba(255,255,255,.08);
  --text: #e8eef9;
  --muted: #8b9bb8;
  --green: #22c55e;
  --green2: #16a34a;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --radius: 14px;
  --sidebar: 260px;
  --font: "Be Vietnam Pro", system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #163024 0%, transparent 50%),
              radial-gradient(900px 500px at 100% 0%, #1a2744 0%, transparent 45%),
              var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(100%, 420px);
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent), var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.login-card .brand {
  display: flex; align-items: center; gap: .85rem;
  margin-bottom: 1.5rem;
}
.login-card .brand img {
  width: 48px; height: 48px; border-radius: 12px; background: #fff;
}
.login-card h1 { font-size: 1.35rem; letter-spacing: -.02em; }
.login-card p { color: var(--muted); font-size: .9rem; margin-top: .2rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .4rem; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .8rem 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(34,197,94,.55);
  box-shadow: 0 0 0 3px rgba(34,197,94,.15);
}
.field textarea { min-height: 100px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 0; border-radius: 12px; padding: .75rem 1.15rem;
  font-weight: 700; cursor: pointer; transition: .2s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-primary {
  background: linear-gradient(135deg, var(--green), var(--green2));
  color: #fff; width: 100%;
  box-shadow: 0 10px 24px rgba(22,163,74,.25);
}
.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text);
}
.btn-danger { background: rgba(239,68,68,.15); color: #fecaca; border: 1px solid rgba(239,68,68,.3); }
.btn-sm { padding: .45rem .75rem; font-size: .85rem; border-radius: 10px; }
.alert {
  padding: .75rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-size: .9rem;
}
.alert-error { background: rgba(239,68,68,.12); color: #fecaca; border: 1px solid rgba(239,68,68,.25); }
.alert-ok { background: rgba(34,197,94,.12); color: #bbf7d0; border: 1px solid rgba(34,197,94,.25); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 1rem; text-align: center; }

/* Shell */
.app { display: none; min-height: 100vh; }
.app.is-on { display: grid; grid-template-columns: var(--sidebar) 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: rgba(10,16,28,.9);
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem;
  display: flex; flex-direction: column; gap: .5rem;
  backdrop-filter: blur(12px);
}
.side-brand {
  display: flex; align-items: center; gap: .7rem;
  padding: .5rem .6rem 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: .5rem;
}
.side-brand img { width: 40px; height: 40px; border-radius: 10px; background: #fff; }
.side-brand strong { display: block; font-size: .95rem; }
.side-brand span { font-size: .75rem; color: var(--muted); }
.nav-btn {
  display: flex; align-items: center; gap: .7rem;
  width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--muted);
  padding: .75rem .85rem; border-radius: 12px;
  font-weight: 600; cursor: pointer;
}
.nav-btn:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav-btn.active { background: rgba(34,197,94,.12); color: var(--green); }
.nav-btn i { width: 1.1rem; text-align: center; }
.side-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); }
.main { padding: 1.25rem 1.5rem 2.5rem; min-width: 0; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 1rem;
  justify-content: space-between; align-items: center;
  margin-bottom: 1.25rem;
}
.topbar h2 { font-size: 1.35rem; letter-spacing: -.02em; }
.topbar .meta { color: var(--muted); font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Cards / tables */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat .value { font-size: 1.7rem; font-weight: 800; margin-top: .25rem; letter-spacing: -.03em; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-bottom: 1rem;
}
.panel h3 { font-size: 1rem; margin-bottom: .85rem; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: .65rem;
  margin-bottom: 1rem; align-items: center;
}
.toolbar .search {
  flex: 1; min-width: 180px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .7rem 1rem;
}
.table-wrap { overflow: auto; border-radius: 12px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: .75rem .9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: rgba(0,0,0,.2); }
tr:hover td { background: rgba(255,255,255,.02); }
.thumb {
  width: 48px; height: 48px; border-radius: 10px; object-fit: cover;
  background: #0a1628; border: 1px solid var(--line);
}
.badge {
  display: inline-block; font-size: .75rem; font-weight: 700;
  padding: .2rem .55rem; border-radius: 999px;
  background: rgba(59,130,246,.15); color: #93c5fd;
}
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3,8,18,.72);
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal-backdrop.is-open { display: flex; }
.modal {
  width: min(100%, 720px);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.35rem;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.modal.modal-lg { width: min(100%, 920px); }
.modal.modal-xl { width: min(100%, 1080px); max-height: min(96vh, 960px); }
.field textarea[rows="12"] { min-height: 220px; font-size: .92rem; line-height: 1.55; }

/* News rich editor */
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-bottom: .5rem;
  padding: .45rem;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
}
.editor-toolbar button {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: .35rem .6rem;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}
.editor-toolbar button:hover { border-color: rgba(34,197,94,.45); color: var(--green); }
.editor-wrap {
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: #0c1424;
}
.rich-editor {
  min-height: 320px;
  max-height: 48vh;
  overflow: auto;
  padding: 1rem 1.1rem;
  outline: none;
  line-height: 1.7;
  font-size: .95rem;
}
.rich-editor:empty:before {
  content: attr(data-placeholder);
  color: var(--muted);
}
.rich-editor h2 {
  font-size: 1.15rem;
  margin: 1rem 0 .5rem;
  color: var(--green);
}
.rich-editor p { margin: 0 0 .85rem; }
.rich-editor ul { margin: 0 0 .85rem 1.2rem; }
.rich-editor blockquote {
  margin: .75rem 0;
  padding: .6rem .9rem;
  border-left: 3px solid var(--green);
  background: rgba(34,197,94,.08);
  color: #cbd5e1;
}
.article-preview {
  background: #f8fafc;
  color: #0f172a;
  border-radius: 14px;
  padding: 1.25rem 1.4rem;
  max-height: 55vh;
  overflow: auto;
  border: 1px solid rgba(255,255,255,.08);
}
.article-preview h1 {
  font-size: 1.45rem;
  line-height: 1.3;
  margin: 0 0 .75rem;
  color: #0f172a;
}
.article-preview .lead {
  color: #475569;
  border-left: 3px solid #22c55e;
  padding-left: .85rem;
  margin-bottom: 1rem;
  font-weight: 500;
}
.article-preview h2 {
  font-size: 1.1rem;
  margin: 1.25rem 0 .5rem;
  color: #14532d;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: .25rem;
}
.article-preview p { margin: 0 0 .85rem; line-height: 1.75; color: #1e293b; }
.article-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 1rem;
}
.news-lang-pane { animation: fade .2s ease; }
.news-lang-pane[hidden] { display: none !important; }
.draft-status {
  color: var(--amber);
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.gallery-editor {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: .5rem;
  min-height: 92px;
  padding: .5rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel2);
}
.gallery-editor .gal-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #0a1628;
  display: flex;
  flex-direction: column;
}
.gallery-editor .gal-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery-editor .gal-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border: 0; border-radius: 999px;
  background: rgba(0,0,0,.7); color: #fff; cursor: pointer; font-size: 14px; line-height: 1;
}
.gallery-editor .gal-cap {
  width: 100%;
  border: 0;
  background: #0a1628;
  color: var(--text);
  font-size: .72rem;
  padding: .35rem .4rem;
}
.gallery-editor .empty { color: var(--muted); font-size: .85rem; grid-column: 1 / -1; }
.media-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0a1628;
  display: flex;
  flex-direction: column;
}
.media-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.media-card .media-cap {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-size: .75rem;
  padding: .4rem .45rem;
}
.media-card .media-del {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px; border: 0; border-radius: 999px;
  background: rgba(239,68,68,.9); color: #fff; cursor: pointer;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; gap: 1rem;
}
.modal header h3 { font-size: 1.15rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .6rem;
  max-height: none; overflow: auto;
  padding: .25rem;
}
.media-item {
  border: 2px solid transparent;
  border-radius: 10px; overflow: hidden; cursor: pointer;
  aspect-ratio: 1; background: #0a1628;
}
.media-item img { width: 100%; height: 100%; object-fit: cover; }
.media-item.selected { border-color: var(--green); }
.preview-img {
  width: 100%; max-height: 180px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line); background: #0a1628;
}
.tabs { display: flex; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); border-radius: 999px; padding: .4rem .9rem;
  font-weight: 600; cursor: pointer; font-size: .85rem;
}
.tab.active { background: rgba(34,197,94,.12); color: var(--green); border-color: rgba(34,197,94,.35); }
.page { display: none; }
.page.is-active { display: block; }

/* Nav badge */
.nav-badge {
  margin-left: auto;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
}
.nav-btn { position: relative; }
.nav-btn .nav-badge { position: static; }

/* Live chat admin */
.chat-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  min-height: calc(100vh - 160px);
}
.chat-list-panel, .chat-thread-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-list-panel { padding: .85rem; }
.chat-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: .4rem; }
.chat-item {
  text-align: left;
  background: var(--panel2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: .7rem .8rem;
  cursor: pointer;
  width: 100%;
  transition: .15s;
}
.chat-item:hover { border-color: var(--line); }
.chat-item.active { border-color: rgba(34,197,94,.45); background: rgba(34,197,94,.08); }
.chat-item .phone { font-weight: 700; display: flex; justify-content: space-between; gap: .5rem; }
.chat-item .preview { color: var(--muted); font-size: .8rem; margin-top: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .meta-line { color: var(--muted); font-size: .72rem; margin-top: .2rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.chat-item .dot {
  min-width: 1.1rem; height: 1.1rem; border-radius: 999px; background: var(--red);
  color: #fff; font-size: .65rem; font-weight: 800; display: inline-grid; place-items: center;
}
.chat-thread-empty {
  flex: 1; display: grid; place-items: center; color: var(--muted); padding: 2rem;
}
.chat-thread { display: flex; flex-direction: column; height: 100%; min-height: 420px; }
.chat-thread-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  padding: .9rem 1rem; border-bottom: 1px solid var(--line);
}
.chat-thread-head .meta { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.chat-thread-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.chat-ai-toggle {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .85rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.chat-msgs {
  flex: 1; overflow: auto; padding: 1rem; display: flex; flex-direction: column; gap: .65rem;
  background: rgba(0,0,0,.15); min-height: 280px; max-height: calc(100vh - 320px);
}
.msg-row { display: flex; }
.msg-row.customer { justify-content: flex-start; }
.msg-row.admin, .msg-row.ai { justify-content: flex-end; }
.msg-bubble {
  max-width: 78%; padding: .65rem .85rem; border-radius: 14px;
  background: var(--panel2); border: 1px solid var(--line); font-size: .9rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.msg-row.admin .msg-bubble { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.25); }
.msg-row.ai .msg-bubble { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.25); }
.msg-row.customer .msg-bubble { background: var(--panel); }
.msg-who { display: block; font-size: .7rem; font-weight: 700; color: var(--muted); margin-bottom: .25rem; text-transform: uppercase; }
.msg-time { display: block; font-size: .68rem; color: var(--muted); margin-top: .35rem; opacity: .8; }
.chat-compose {
  display: flex; gap: .6rem; padding: .85rem; border-top: 1px solid var(--line); align-items: flex-end;
}
.chat-compose textarea {
  flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem .85rem; resize: vertical; min-height: 52px; outline: none;
}
.chat-compose textarea:focus { border-color: rgba(34,197,94,.5); }

/* Leads / notifs */
.status-pill {
  display: inline-block; padding: .2rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}
.status-new { background: rgba(245,158,11,.15); color: var(--amber); }
.status-called, .status-done { background: rgba(34,197,94,.12); color: var(--green); }
.status-closed { background: rgba(139,155,184,.15); color: var(--muted); }
.status-open, .status-human { background: rgba(59,130,246,.12); color: var(--blue); }
.status-lead { background: rgba(245,158,11,.15); color: var(--amber); }
.notif-list { display: flex; flex-direction: column; gap: .55rem; }
.notif-item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: .85rem 1rem; display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start;
}
.notif-item.unread { border-color: rgba(34,197,94,.35); background: rgba(34,197,94,.06); }
.notif-item h4 { font-size: .95rem; margin-bottom: .2rem; }
.notif-item p { color: var(--muted); font-size: .85rem; }
.notif-item time { color: var(--muted); font-size: .75rem; white-space: nowrap; }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; min-height: auto; }
  .chat-list { max-height: 220px; }
}
.mobile-toggle {
  display: none; position: fixed; top: .85rem; left: .85rem; z-index: 50;
  background: var(--panel); border: 1px solid var(--line);
  width: 44px; height: 44px; border-radius: 12px; color: var(--text); cursor: pointer;
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .app.is-on { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 280px);
    z-index: 60; transform: translateX(-105%); transition: .25s;
  }
  .sidebar.is-open { transform: none; }
  .mobile-toggle { display: grid; place-items: center; }
  .main { padding-top: 4rem; }
  .grid-2 { grid-template-columns: 1fr; }
}
