:root {
  --bg: #070910;
  --panel: #10131c;
  --panel-2: #171b25;
  --border: #262b36;
  --text: #e9ecf2;
  --muted: #95a0b5;
  --accent: #7c5cff;
  --accent-2: #9d8cff;
  --cyan: #4dd7ff;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: radial-gradient(circle at top, #121428 0, var(--bg) 42%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

#app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 245px;
  flex: 0 0 245px;
  background: rgba(16,19,28,.92);
  border-right: 1px solid var(--border);
  padding: 1.1rem .75rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-size: 1.08rem; font-weight: 800; margin-bottom: 1rem; color: var(--accent-2); }
.nav-label { color: #616b80; font-size: 10px; letter-spacing: 1.2px; margin: 1rem 0 .25rem; }
.nav-item {
  display: block; width: 100%; text-align: left; text-decoration: none;
  color: var(--muted); padding: .52rem .65rem; border-radius: 8px;
  font-size: .87rem; margin-bottom: .12rem; background: transparent; border: 0; cursor: pointer;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  color: white; background: linear-gradient(90deg, rgba(124,92,255,.35), rgba(77,215,255,.12));
  box-shadow: inset 2px 0 var(--accent);
}
.logout { margin-top: 1.3rem; color: var(--danger) !important; }

.content { flex: 1; min-width: 0; padding: 1.4rem 1.6rem 3rem; }
.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1.2rem; }
h1 { font-size: 1.45rem; margin-bottom: .1rem; }
h3 { font-size: 1rem; margin-bottom: .75rem; }
.muted { color: var(--muted); }
code { background: #151a24; padding: .15rem .35rem; border-radius: 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: .9rem; margin-bottom: 1rem; }
.stat-card, .card {
  background: rgba(16,19,28,.82);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.16);
  padding: 1rem;
}
.stat-card span { color: var(--muted); font-size: .78rem; }
.stat-card strong { display: block; font-size: 1.85rem; margin-top: .3rem; color: #fff; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit,minmax(340px,1fr)); gap: 1rem; }
.card { margin-bottom: 1rem; }
.kv-list { display: grid; gap: .45rem; }
.kv-list > div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid #222733; padding: .42rem 0; }
.kv-list > div:last-child { border-bottom: 0; }
.kv-list span { color: var(--muted); }
.kv-list strong { text-align: right; overflow-wrap: anywhere; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 190px; padding-top: 20px; }
.bar-group { flex: 1; min-width: 30px; text-align: center; }
.bar-pair { display: flex; justify-content: center; gap: 4px; height: 145px; align-items: flex-end; }
.bar { width: 12px; border-radius: 4px 4px 0 0; min-height: 2px; background: var(--accent); }
.bar.total { opacity: .42; }
.bar.ai { background: linear-gradient(#4dd7ff, var(--accent)); }
.bar-label { font-size: .68rem; color: var(--muted); margin-top: .3rem; }
.bar-value { font-size: .68rem; color: var(--text); }

.badge { padding: 3px 10px; border-radius: 999px; background: var(--warning); color: #15171c; font-size: .74rem; font-weight: 700; }
.badge.online, .badge.success { background: rgba(52,211,153,.18); color: var(--success); }
.badge.offline, .badge.danger { background: rgba(248,113,113,.14); color: var(--danger); }
.badge.warn { background: rgba(251,191,36,.16); color: var(--warning); }
.status-good { color: var(--success); }
.status-warn { color: var(--warning); }
.status-bad { color: var(--danger); }

.btn, .btn-primary {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: .48rem .8rem; border-radius: 8px; cursor: pointer; font-size: .85rem;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #5c3cff); border: 0; color: white; font-weight: 650; }
.btn.danger { color: var(--danger); border-color: #3a2424; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .58rem .6rem; border-bottom: 1px solid var(--border); font-size: .84rem; vertical-align: top; }
th { color: #71809c; font-size: 10px; letter-spacing: .7px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.035); cursor: pointer; }
.selected td { background: rgba(124,92,255,.12); }

.split { display: grid; grid-template-columns: 380px minmax(0,1fr); gap: 1rem; align-items: start; }
.list-pane, .detail-pane { background: rgba(16,19,28,.82); border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem; min-height: 360px; }
.list-pane { overflow: auto; max-height: 70vh; }
.detail-pane { padding: 1rem; }
.bubble { max-width: 85%; padding: .55rem .7rem; border-radius: 10px; margin-bottom: .5rem; font-size: .86rem; white-space: pre-wrap; }
.bubble.customer { background: var(--panel-2); margin-right: auto; }
.bubble.ai { background: linear-gradient(135deg, #7158ff, #4f35cc); color: white; margin-left: auto; }
.bubble.admin { background: rgba(52,211,153,.2); border: 1px solid rgba(52,211,153,.35); margin-left: auto; }
.bubble .meta { font-size: .68rem; opacity: .75; margin-top: .25rem; }
.reply-row { display: flex; gap: .5rem; margin-top: .8rem; }
.reply-row input { flex: 1; min-width: 0; }

input, select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .48rem .65rem;
}
input:focus, select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.12); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit,minmax(160px,1fr)) auto; gap: .5rem; align-items: end; }
.form-row input, .form-row select { width: 100%; }

.timeline { display: grid; gap: .55rem; }
.timeline div { border-bottom: 1px solid #202532; padding-bottom: .45rem; }
.timeline span { color: var(--muted); font-size: .78rem; }
.profile-list { display: grid; gap: .6rem; }
.profile-item { background: #151a24; border: 1px solid #252b38; padding: .7rem; border-radius: 9px; }
.qr-wrap { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.qr-wrap img { width: 230px; height: 230px; object-fit: contain; background: white; border-radius: 8px; }
.security { border-color: rgba(251,191,36,.25); background: rgba(251,191,36,.045); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 345px; background: rgba(16,19,28,.9); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.6rem; box-shadow: 0 25px 80px rgba(0,0,0,.35); }
.login-card .brand { margin-bottom: .5rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .84rem; color: var(--muted); margin: .65rem 0; }
.error { color: var(--danger); font-size: .85rem; min-height: 1.1rem; margin-top: .45rem; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin: 1rem 0 .2rem; }
.auth-tab { padding: .5rem; border: 1px solid var(--border); background: rgba(255,255,255,.03); border-radius: 8px; color: var(--muted); font-size: .84rem; cursor: pointer; }
.auth-tab.active { border-color: var(--accent); color: var(--foreground); background: rgba(99,102,241,.12); }
.auth-divider { margin: .9rem 0 .6rem; text-align: center; color: var(--muted); font-size: .75rem; }
.btn-google { display: block; text-align: center; padding: .6rem; border-radius: 9px; border: 1px solid var(--border); background: rgba(255,255,255,.06); color: var(--foreground); font-size: .86rem; text-decoration: none; }
.btn-google:hover { background: rgba(255,255,255,.1); }

.safety-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem 1.2rem; margin-top: .9rem; }
.safety-field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.safety-field > span { font-size: .88rem; font-weight: 600; color: var(--foreground); }
.safety-field input, .safety-field select { width: 100%; box-sizing: border-box; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: rgba(255,255,255,.05); color: var(--foreground); font-size: .92rem; }
.safety-field .hint { font-size: .78rem; line-height: 1.45; color: var(--muted); margin: 0; min-height: 3.2em; }
.safety-actions { display: flex; align-items: center; gap: .8rem; margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.safety-actions .muted { font-size: .82rem; }

@media (max-width: 900px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .split, .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
}

.password-wrap { display: flex; align-items: center; gap: .4rem; margin-top: .3rem; }
.password-wrap input { flex: 1; }
.pw-toggle { border: 1px solid var(--border); background: rgba(255,255,255,.05); color: var(--foreground); border-radius: 8px; padding: .45rem .6rem; cursor: pointer; font-size: .9rem; line-height: 1; }

.chat-widget { position: fixed; right: 20px; bottom: 20px; z-index: 9999; }
.chat-toggle { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 24px; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: transform .15s ease; }
.chat-toggle:hover { transform: scale(1.05); }
.chat-panel { position: fixed; right: 20px; bottom: 90px; width: min(360px, calc(100vw - 40px)); height: 460px; max-height: calc(100vh - 120px); display: flex; flex-direction: column; background: var(--panel); color: var(--foreground); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 40px rgba(0,0,0,.35); overflow: hidden; }
.chat-panel.hidden { display: none; }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-close { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); }
.chat-messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 85%; padding: 8px 10px; border-radius: 12px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.chat-msg.bot { align-self: flex-start; background: rgba(255,255,255,.06); }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; min-width: 0; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,.05); color: var(--foreground); }

.assistant-shell { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.assistant-messages { flex: 1; overflow: auto; padding: 1.2rem; display: flex; flex-direction: column; gap: 1rem; }
.assistant-msg { max-width: 80%; padding: .75rem 1rem; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.assistant-msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.assistant-msg.bot { align-self: flex-start; background: rgba(255,255,255,.06); }
.assistant-form { display: flex; gap: .6rem; padding: 1rem; border-top: 1px solid var(--border); align-items: flex-end; }
  .assistant-form textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,.05); color: var(--foreground); font-family: inherit; font-size: .95rem; overflow-y: auto; }
.assistant-foot { padding: 0 1rem 1rem; font-size: .8rem; }
.assistant-action { margin-top: .4rem; display: inline-block; }

/* ===== Responsif HP ===== */
@media (max-width: 640px) {
  #app-view { flex-direction: column; }
  .content { padding: .8rem; }
  .sidebar {
    width: 100%; flex: 0 0 auto; height: auto; max-height: none; position: sticky; top: 0; z-index: 50;
    padding: .5rem .6rem; border-right: 0; border-bottom: 1px solid var(--border);
    background: rgba(16,19,28,.98);
    display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center;
    overflow-x: auto; overflow-y: hidden; gap: .3rem; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar .brand { flex: 0 0 auto; margin: 0 .5rem 0 .2rem; font-size: .9rem; white-space: nowrap; }
  .nav-label, .sidebar > .nav-label { display: none; }
  .nav-item { flex: 0 0 auto; width: auto; margin: 0; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; padding: 0 .75rem; font-size: .86rem; border-radius: 10px; }
  .logout { margin-top: 0; }
  .page-head { flex-direction: column; align-items: stretch; gap: .6rem; }
  .page-head .btn { width: 100%; min-height: 44px; }

  .assistant-shell { height: calc(100dvh - 268px); min-height: 280px; border-radius: 12px; }
  .assistant-messages { padding: .8rem; gap: .7rem; }
  .assistant-msg { max-width: 92%; font-size: 15px; }
  .assistant-msg.bot::before { content: 'Sorin Chatbot'; display: block; font-size: 11px; color: var(--accent-2); margin-bottom: 3px; font-weight: 700; }
  .assistant-form textarea::placeholder { color: #8e99b5; }
  .assistant-form { padding: .6rem .6rem calc(.6rem + env(safe-area-inset-bottom)); gap: .5rem; }
  .sidebar { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); padding-right: 1.5rem; }
  .assistant-form textarea { font-size: 16px; min-height: 44px; padding: .65rem .75rem; }
  .assistant-form .btn-primary { min-height: 44px; padding: 0 1rem; }
  .assistant-foot { display: none; }

  .safety-grid { grid-template-columns: 1fr; }
  .safety-actions { flex-direction: column; align-items: stretch; }
  .safety-actions .btn-primary { min-height: 44px; }
  input, select, textarea { font-size: 16px; }
  .btn, .btn-primary { min-height: 44px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .assistant-shell { height: calc(100dvh - 200px); }
}
