/* ═══════════════════════════════════════════════════════════
   ATOMS — Variabili e base
═══════════════════════════════════════════════════════════ */

:root {
  /* Sidebar — tema chiaro */
  --sidebar-bg: #ededf7;
  --sidebar-text: #5c5880;
  --sidebar-text-active: #1c1b2e;
  --sidebar-active-bg: rgba(124,92,191,0.12);
  --sidebar-hover-bg: rgba(124,92,191,0.07);
  --sidebar-border: rgba(0,0,0,0.08);

  /* Main area — tema chiaro */
  --main-bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f0effe;
  --border: #e4e2f0;
  --text-primary: #1c1b2e;
  --text-secondary: #5c5880;
  --text-muted: #9b97b8;

  /* Accento */
  --accent: #7c5cbf;
  --accent-hover: #6b4aaa;
  --accent-text: #ffffff;

  /* Chat */
  --msg-user-bg: #7c5cbf;
  --msg-user-text: #ffffff;
  --msg-assistant-bg: #f1f5f9;
  --msg-assistant-text: #0f172a;
  --msg-thinking-bg: #fefce8;
  --msg-thinking-text: #92400e;

  /* Feedback */
  --ok-bg: #dcfce7;
  --ok-text: #166534;
  --err-bg: #fee2e2;
  --err-text: #991b1b;

  /* Layout */
  --sidebar-width: 240px;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
}

/* Tema scuro */
[data-theme="dark"] {
  --sidebar-bg: #1c1b2e;
  --sidebar-text: #9b97b8;
  --sidebar-text-active: #f0effe;
  --sidebar-active-bg: rgba(139,92,246,0.15);
  --sidebar-hover-bg: rgba(139,92,246,0.08);
  --sidebar-border: rgba(255,255,255,0.07);
  --main-bg: #13121f;
  --surface: #1e1d2e;
  --surface-2: #28273c;
  --border: #35334d;
  --text-primary: #eeedf8;
  --text-secondary: #9b97b8;
  --text-muted: #5c5880;
  --msg-assistant-bg: #1e1d2e;
  --msg-assistant-text: #eeedf8;
  --msg-thinking-bg: #2a2416;
  --msg-thinking-text: #d97706;
  --ok-bg: #0f2e1a;
  --ok-text: #86efac;
  --err-bg: #2e0f0f;
  --err-text: #fca5a5;
}

/* Tema automatico — segue il sistema */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --sidebar-bg: #1c1b2e;
    --sidebar-text: #9b97b8;
    --sidebar-text-active: #f0effe;
    --sidebar-active-bg: rgba(139,92,246,0.15);
    --sidebar-hover-bg: rgba(139,92,246,0.08);
    --sidebar-border: rgba(255,255,255,0.07);
    --main-bg: #13121f;
    --surface: #1e1d2e;
    --surface-2: #28273c;
    --border: #35334d;
    --text-primary: #eeedf8;
    --text-secondary: #9b97b8;
    --text-muted: #5c5880;
    --msg-assistant-bg: #1e1d2e;
    --msg-assistant-text: #eeedf8;
    --msg-thinking-bg: #2a2416;
    --msg-thinking-text: #d97706;
    --ok-bg: #0f2e1a;
    --ok-text: #86efac;
    --err-bg: #2e0f0f;
    --err-text: #fca5a5;
  }
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--main-bg);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ═══════════════════════════════════════════════════════════
   ATOMS — Bottoni
═══════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--text-muted); cursor: not-allowed; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--border); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; margin-top: 12px; padding: 12px; font-size: 0.95rem; }

/* ═══════════════════════════════════════════════════════════
   ATOMS — Form
═══════════════════════════════════════════════════════════ */

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  font-family: inherit;
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

/* ═══════════════════════════════════════════════════════════
   MOLECULES — Sidebar
═══════════════════════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 16px;
}
.logo-icon {
  font-size: 1.4rem;
  color: var(--accent);
  line-height: 1;
}
.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--sidebar-text-active);
  letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════════════════
   MOLECULES — Nav
═══════════════════════════════════════════════════════════ */

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sessions-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 8px;
  border-top: 1px solid var(--sidebar-border);
  padding-top: 8px;
}
.sessions-panel.hidden { display: none; }

.sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 6px;
}
.sessions-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.btn-new-chat {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-new-chat:hover { background: var(--accent); }

.sessions-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 6px;
}
.sessions-list::-webkit-scrollbar { width: 4px; }
.sessions-list::-webkit-scrollbar-track { background: transparent; }
.sessions-list::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 4px; }
.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-track { background: transparent; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chat-box::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.session-item {
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  transition: all 0.15s;
}
.session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.session-date {
  font-size: 0.72rem;
  color: var(--sidebar-text);
  opacity: 0.5;
  flex-shrink: 0;
  white-space: nowrap;
}
.session-item:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }
.session-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); font-weight: 600; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); font-weight: 600; }
.nav-icon { font-size: 1.1rem; }

/* ═══════════════════════════════════════════════════════════
   MOLECULES — Sidebar bottom
═══════════════════════════════════════════════════════════ */

.sidebar-bottom {
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.theme-toggle:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }

.sidebar-controls {
  display: flex;
  gap: 4px;
  padding: 2px 8px;
}
.sidebar-ctrl-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.sidebar-ctrl-btn:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }

.lang-selector { position: relative; }
.lang-popup {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  z-index: 200;
}
.lang-popup.hidden { display: none; }
body.sidebar-top .lang-popup,
body.sidebar-bottom .lang-popup { bottom: unset; top: calc(100% + 8px); }
.lang-flag-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 4px;
  font-size: 1.4rem;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s, border-color 0.15s;
}
.lang-flag-btn:hover { opacity: 0.85; }
.lang-flag-btn.active { opacity: 1; border-color: var(--accent); }
.fi { border-radius: 2px; }

.user-info-wrapper { position: relative; }

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.user-info:hover { background: var(--sidebar-hover-bg); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.account-popup {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #2a2840;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
}
body.sidebar-top .account-popup,
body.sidebar-bottom .account-popup {
  bottom: unset;
  top: calc(100% + 8px);
}
.account-popup.hidden { display: none; }

.account-popup-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.account-popup-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  overflow: hidden;
}
.account-popup-name { font-size: 0.85rem; font-weight: 600; color: var(--sidebar-text-active); }
.account-popup-email { font-size: 0.75rem; color: var(--sidebar-text); }

.account-popup-divider { border: none; border-top: 1px solid var(--sidebar-border); margin: 8px 0; }

.account-popup-btn {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  display: block;
}
.account-popup-btn:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }
.account-popup-btn--danger:hover { background: rgba(239,68,68,0.15); color: #f87171; }
.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sidebar-text-active);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-status { font-size: 0.75rem; color: var(--sidebar-text); }

.lang-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
}
.lang-label { font-size: 0.8rem; color: var(--sidebar-text); white-space: nowrap; }
.lang-selector select {
  flex: 1;
  background: transparent;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.83rem;
  font-family: inherit;
  padding: 4px 6px;
  cursor: pointer;
}
.lang-selector select:focus { outline: none; border-color: var(--accent); }
.lang-selector select option { background: #1e1d2e; color: #eeedf8; }


/* ═══════════════════════════════════════════════════════════
   ORGANISMS — Main
═══════════════════════════════════════════════════════════ */

.main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
}

.tab-content { display: none; }
.tab-content.active { display: flex; flex-direction: column; flex: 1; }

.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.page-header p { color: var(--text-secondary); font-size: 0.93rem; }

/* ═══════════════════════════════════════════════════════════
   MOLECULES — Card
═══════════════════════════════════════════════════════════ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.card-header .card-title { margin-bottom: 0; }

.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ═══════════════════════════════════════════════════════════
   ORGANISMS — Chat
═══════════════════════════════════════════════════════════ */

.chat-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.chat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-height: 300px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

/* ═══════════════════════════════════════════════════════════
   ATOMS — Messaggi
═══════════════════════════════════════════════════════════ */

.msg {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
}
.msg-user {
  background: var(--msg-user-bg);
  color: var(--msg-user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  background: var(--msg-assistant-bg);
  color: var(--msg-assistant-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg-thinking {
  background: var(--msg-thinking-bg);
  color: var(--msg-thinking-text);
  align-self: flex-start;
  font-style: italic;
  font-size: 0.85rem;
  border-bottom-left-radius: 4px;
}

/* ═══════════════════════════════════════════════════════════
   MOLECULES — Chat input
═══════════════════════════════════════════════════════════ */

.file-drop-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.chat-input-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.chat-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.file-name { font-size: 0.8rem; color: var(--text-muted); }

.chat-send-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-textarea {
  flex: 1;
  resize: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.93rem;
  font-family: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.chat-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.btn-send { align-self: flex-end; height: fit-content; }

/* ═══════════════════════════════════════════════════════════
   ATOMS — Liste e risultati
═══════════════════════════════════════════════════════════ */

.item-list { list-style: none; }
.item-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-primary);
}
.item-list li:last-child { border-bottom: none; }
.item-list a { color: var(--accent); text-decoration: none; }
.item-list a:hover { text-decoration: underline; }

.result-msg {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  display: none;
}
.result-ok  { background: var(--ok-bg);  color: var(--ok-text);  display: block; }
.result-err { background: var(--err-bg); color: var(--err-text); display: block; }

/* ═══════════════════════════════════════════════════════════
   MOLECULES — Auth Banner
═══════════════════════════════════════════════════════════ */

.auth-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid #fbbf24;
  border-radius: var(--radius);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  color: var(--text-primary);
  z-index: 100;
}
.auth-banner.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════
   Responsive
═══════════════════════════════════════════════════════════ */

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal-box h3 { margin: 0 0 10px; }
.modal-box p  { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }

/* Popup posizione sidebar */
.sidebar-position-popup {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
}
.dpad {
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 2px;
}
.dpad-top    { grid-column: 2; grid-row: 1; }
.dpad-left   { grid-column: 1; grid-row: 2; }
.dpad-center { grid-column: 2; grid-row: 2; }
.dpad-right  { grid-column: 3; grid-row: 2; }
.dpad-bottom { grid-column: 2; grid-row: 3; }
.sidebar-position-popup.hidden { display: none; }
body.sidebar-top .sidebar-position-popup,
body.sidebar-bottom .sidebar-position-popup {
  bottom: unset;
  top: calc(100% + 8px);
  left: auto;
  right: 0;
}
.sidebar-pos-btn {
  background: none;
  border: none;
  color: var(--sidebar-text);
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}
.sidebar-pos-btn:hover { background: var(--sidebar-hover-bg); }
.sidebar-pos-btn.active { background: var(--sidebar-active-bg); color: var(--accent); }

/* Ghost drag */
.sidebar-drag-ghost {
  position: fixed;
  background: rgba(139,92,246,0.15);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  pointer-events: none;
  z-index: 9999;
  transition: none;
}
.sidebar-drag-ghost.hidden { display: none; }

/* Sidebar in cima (top) */
body.sidebar-top {
  flex-direction: column;
}
body.sidebar-top .sidebar {
  width: 100%; height: auto; min-height: unset;
  flex-direction: row; align-items: center;
  padding: 10px 20px;
  position: sticky; top: 0; z-index: 100;
}
body.sidebar-top .sidebar-logo { border-bottom: none; margin-bottom: 0; padding-bottom: 8px; }
body.sidebar-top .sidebar-nav  { flex-direction: row; border-top: none; padding-top: 0; margin-left: 16px; }
body.sidebar-top .sidebar .sessions-panel { display: none; }
body.sidebar-top .sidebar-bottom { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; gap: 8px; }
body.sidebar-top .main { height: calc(100vh - 60px); max-width: 100%; width: 100%; }
body.sidebar-top .sidebar-position-popup { bottom: unset; top: calc(100% + 8px); left: auto; right: 0; }

/* Sidebar in basso (bottom) */
body.sidebar-bottom {
  flex-direction: column-reverse;
}
body.sidebar-bottom .sidebar {
  width: 100%; height: auto; min-height: unset;
  flex-direction: row; align-items: center;
  padding: 10px 20px;
  position: sticky; bottom: 0; top: unset; z-index: 100;
}
body.sidebar-bottom .sidebar-logo { border-bottom: none; margin-bottom: 0; padding-bottom: 8px; }
body.sidebar-bottom .sidebar-nav  { flex-direction: row; border-top: none; padding-top: 0; margin-left: 16px; }
body.sidebar-bottom .sidebar .sessions-panel { display: none; }
body.sidebar-bottom .sidebar-bottom { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; gap: 8px; }
body.sidebar-bottom .main { height: calc(100vh - 60px); max-width: 100%; width: 100%; }
body.sidebar-bottom .sidebar-position-popup { bottom: calc(100% + 8px); top: unset; left: auto; right: 0; }

/* Chat layout con sessioni nel main (sidebar top/bottom) */
body.sidebar-top #tab-chat.active,
body.sidebar-bottom #tab-chat.active {
  display: flex;
  flex-direction: row;
  gap: 20px;
  align-items: stretch;
  flex: 1;
}
body.sidebar-top .chat-box,
body.sidebar-bottom .chat-box {
  height: calc(100vh - 220px);
  min-height: unset;
  flex: unset;
}
body.sidebar-top #tab-chat > .sessions-panel,
body.sidebar-bottom #tab-chat > .sessions-panel {
  flex: 0 0 var(--sidebar-width);
  background: var(--sidebar-bg);
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--sidebar-border);
  padding: 12px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  box-shadow: none;
  margin: -32px 0 -32px -40px;
}
body.sidebar-top #tab-chat > .sessions-panel .sessions-title,
body.sidebar-bottom #tab-chat > .sessions-panel .sessions-title {
  color: var(--text-primary);
}
body.sidebar-top #tab-chat > .chat-main,
body.sidebar-bottom #tab-chat > .chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Sidebar a destra (right) */
body.sidebar-right {
  flex-direction: row-reverse;
}

@media (max-width: 700px) {
  .sidebar { width: 60px; padding: 16px 8px; }
  .logo-text, .nav-label, .sidebar-bottom .theme-toggle span:last-child,
  .user-name, .user-status { display: none; }
  .sidebar-logo { justify-content: center; padding-bottom: 16px; }
  .nav-item { justify-content: center; padding: 10px; }
  .main { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
}
