/* frontend/static/css/main.css */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600&display=swap');

/* ══════════════════════════════════════════════════════════════════════════════
   DESIGN TOKENS
══════════════════════════════════════════════════════════════════════════════ */
:root {
  --teal:       #0d9488;
  --teal-d:     #0f766e;
  --teal-l:     #f0fdfa;
  --teal-m:     #99f6e4;

  --bg:         #f8fafc;
  --bg-2:       #f1f5f9;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --border-d:   #cbd5e1;

  --text:       #0f172a;
  --text-2:     #475569;
  --text-3:     #94a3b8;

  --amber:      #d97706;
  --amber-l:    #fffbeb;
  --red:        #ef4444;
  --red-l:      #fef2f2;
  --green:      #10b981;
  --green-l:    #f0fdf4;
  --indigo:     #6366f1;
  --indigo-l:   #eef2ff;

  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-sans:  'DM Sans', system-ui, sans-serif;

  --radius:     14px;
  --radius-sm:  8px;
  --radius-xs:  6px;

  --shadow-xs:  0 1px 2px rgba(0,0,0,.05);
  --shadow:     0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --shadow-md:  0 4px 8px rgba(0,0,0,.06), 0 12px 32px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 16px rgba(0,0,0,.08), 0 24px 48px rgba(0,0,0,.10);
}

/* ══════════════════════════════════════════════════════════════════════════════
   RESET
══════════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: var(--font-sans); cursor: pointer; }
input, textarea, select { font-family: var(--font-sans); }

/* ══════════════════════════════════════════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-d); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════════════════════════════════════════ */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse   { 0%,100% { opacity:.35; transform:scale(.85); } 50% { opacity:1; transform:scale(1); } }
@keyframes spin    { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════════════════════
   LAYOUT HELPERS
══════════════════════════════════════════════════════════════════════════════ */
.hidden  { display: none !important; }
.flex    { display: flex; }
.col     { flex-direction: column; }
.gap-8   { gap: 8px; }
.gap-12  { gap: 12px; }
.gap-16  { gap: 16px; }
.center  { align-items: center; justify-content: center; }
.between { justify-content: space-between; }
.grow    { flex: 1; min-width: 0; }

/* ══════════════════════════════════════════════════════════════════════════════
   AUTH PAGE
══════════════════════════════════════════════════════════════════════════════ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0f2fe 0%, #f0fdfa 50%, #faf5ff 100%);
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .4s ease;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.auth-logo-icon {
  width: 44px; height: 44px;
  background: var(--teal);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.auth-logo-text h1 {
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 1.2;
  color: var(--text);
}
.auth-logo-text p { font-size: 12px; color: var(--text-3); margin-top: 1px; }

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 28px;
  gap: 4px;
}
.auth-tab {
  flex: 1; padding: 8px;
  border: none; border-radius: 6px;
  background: transparent;
  font-size: 13.5px; font-weight: 500;
  color: var(--text-2);
  transition: all .15s ease;
  cursor: pointer;
}
.auth-tab.active {
  background: var(--surface);
  color: var(--teal);
  box-shadow: var(--shadow-xs);
  font-weight: 600;
}

.auth-error {
  background: var(--red-l);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 16px;
  border: 1px solid #fca5a5;
}

/* ══════════════════════════════════════════════════════════════════════════════
   FORMS
══════════════════════════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--text-2);
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
  outline: none;
}
.form-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,.1);
}
.form-input::placeholder { color: var(--text-3); }
select.form-input { appearance: auto; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ══════════════════════════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-teal {
  background: var(--teal);
  color: #fff;
}
.btn-teal:hover  { background: var(--teal-d); }
.btn-teal:active { transform: scale(.98); }

.btn-outline {
  background: transparent;
  color: var(--teal);
  border: 1.5px solid var(--teal);
}
.btn-outline:hover { background: var(--teal-l); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--bg-2); }

.btn-danger {
  background: var(--red-l);
  color: var(--red);
  border: 1px solid #fca5a5;
}
.btn-danger:hover { background: #fecaca; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Primary auth button */
.btn-primary {
  width: 100%;
  height: 44px;
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: background .15s ease, transform .1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.btn-primary:hover  { background: var(--teal-d); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════════════════════════════════════ */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar — WHITE ────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: width .2s ease;
}

.sidebar-toggle {
  position: absolute;
  top: 18px;
  right: 10px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 20;
  color: var(--text-3);
  padding: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  transition: color .15s ease, transform .2s ease;
}
.sidebar-toggle:hover { color: var(--text); border-color: var(--teal); }
.sidebar-toggle svg { width: 12px; height: 12px; }

.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-item > span:not(.nav-item-icon),
.sidebar.collapsed .medico-info,
.sidebar.collapsed .logout-btn,
.sidebar.collapsed .sidebar-disclaimer { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .sidebar-logo { justify-content: center; padding: 16px 12px; }
.sidebar.collapsed .medico-badge { justify-content: center; padding: 10px; }
.sidebar.collapsed .medico-avatar { margin: 0; }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo-icon {
  width: 38px; height: 38px;
  background: var(--teal-l);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-logo-text span {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font-sans);
  display: block;
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-item:hover  { background: var(--bg-2); color: var(--text); }
.nav-item.active { background: var(--teal-l); color: var(--teal); font-weight: 600; }

.nav-item-icon {
  width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--text-3);
  transition: color .15s ease;
}
.nav-item:hover  .nav-item-icon { color: var(--text-2); }
.nav-item.active .nav-item-icon { color: var(--teal); }

/* ── Top bar ── */
.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.top-bar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

/* ── Bell button ── */
.bell-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
.bell-count-label {
  font-size: 13px;
  font-weight: 700;
  color: #ef4444;
  display: none;
  white-space: nowrap;
}
.bell-btn {
  position: relative;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  color: var(--text-2);
}
.bell-btn:hover { background: var(--border); }
.bell-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 11px; font-weight: 800;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  display: none;
  align-items: center; justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--surface);
  line-height: 1;
  box-shadow: 0 2px 6px rgba(239,68,68,.4);
}

/* ── Notification dropdown (Facebook style) ── */
.notif-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 12px;
  width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.16);
  z-index: 300;
  overflow: hidden;
  display: none;
  animation: ndSlideIn .15s ease;
}
@keyframes ndSlideIn {
  from { opacity:0; transform: translateY(-6px); }
  to   { opacity:1; transform: translateY(0); }
}
.notif-dropdown.open { display: block; }
.nd-header {
  padding: 16px 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nd-header-title { font-size: 20px; font-weight: 700; }
.nd-mark-all {
  font-size: 12px; font-weight: 600;
  color: var(--teal);
  background: none; border: none; cursor: pointer; padding: 4px 8px;
  border-radius: 6px;
}
.nd-mark-all:hover { background: var(--teal-l); }
.nd-section-label {
  padding: 6px 18px 4px;
  font-size: 12px; font-weight: 700;
  color: var(--text);
}
.nd-list { max-height: 420px; overflow-y: auto; }
.nd-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  border-radius: 0;
  transition: background .12s;
  position: relative;
}
.nd-item:hover { background: var(--bg); }
.nd-item.unread { background: #dbeafe; border-left: 3px solid var(--teal); }
.nd-item.unread:hover { background: #bfdbfe; }
.nd-item:not(.unread) { border-left: 3px solid transparent; }
.nd-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.nd-body { flex: 1; min-width: 0; padding-top: 2px; }
.nd-text { font-size: 13.5px; line-height: 1.4; color: var(--text); }
.nd-text strong { font-weight: 600; }
.nd-time { font-size: 12px; color: var(--teal); font-weight: 600; margin-top: 3px; }
.nd-time.read { color: var(--text-3); font-weight: 400; }
.nd-dot {
  width: 11px; height: 11px;
  background: var(--teal);
  border-radius: 50%;
  flex-shrink: 0;
  align-self: center;
}
.nd-empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.nd-backdrop {
  position: fixed; inset: 0;
  z-index: 299;
  display: none;
}
.nd-backdrop.open { display: block; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.medico-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-2);
}
.medico-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--teal-l);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  color: var(--teal);
  flex-shrink: 0;
}
.medico-info { flex: 1; min-width: 0; }
.medico-name {
  font-size: 13px; font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.medico-spec { font-size: 11px; color: var(--text-3); }

.logout-btn {
  background: none; border: none;
  color: var(--text-3);
  font-size: 15px;
  cursor: pointer; padding: 4px;
  transition: color .15s ease;
  display: flex; align-items: center; justify-content: center;
}
.logout-btn:hover { color: var(--red); }

/* ── Main content ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
}

.page-header {
  padding: 24px 32px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.page-title {
  font-family: var(--font-serif);
  font-size: 26px;
  color: var(--text);
  line-height: 1.2;
}
.page-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}
.page-body { padding: 28px 32px; flex: 1; }

/* ══════════════════════════════════════════════════════════════════════════════
   STAT CARDS
══════════════════════════════════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  animation: slideUp .3s ease both;
}
.stat-card:nth-child(2) { animation-delay: .05s; }
.stat-card:nth-child(3) { animation-delay: .1s; }

.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 6px;
}
.stat-value {
  font-family: var(--font-serif);
  font-size: 40px;
  line-height: 1;
  color: var(--teal);
}
.stat-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ══════════════════════════════════════════════════════════════════════════════
   CARD
══════════════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: slideUp .35s ease both;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-weight: 600; font-size: 15px; color: var(--text); }
.card-body  { padding: 0; }

/* ══════════════════════════════════════════════════════════════════════════════
   TABLE
══════════════════════════════════════════════════════════════════════════════ */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.table td {
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
  color: var(--text);
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr {
  transition: background .12s ease;
  cursor: pointer;
}
.table tbody tr:hover { background: var(--teal-l); }

/* ══════════════════════════════════════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #16a34a; }
.badge-amber  { background: #fef3c7; color: #d97706; }
.badge-teal   { background: var(--teal-l); color: var(--teal); }
.badge-red    { background: var(--red-l); color: var(--red); }
.badge-gray   { background: #f1f5f9; color: #64748b; }

/* ══════════════════════════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.48);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .2s ease;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 32px;
  width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
}
.modal-title {
  font-family: var(--font-serif);
  font-size: 22px;
  margin-bottom: 4px;
  color: var(--text);
}
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.modal-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 10px;
  margin-top: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--teal-l);
}

/* ══════════════════════════════════════════════════════════════════════════════
   DOT MENU
══════════════════════════════════════════════════════════════════════════════ */
.dot-menu-btn {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: none; border: none;
  cursor: pointer;
  color: var(--text-3);
  opacity: 0;
  transition: background .15s ease, color .15s ease, opacity .15s ease;
}
.table tbody tr:hover .dot-menu-btn { opacity: 1; }
.dot-menu-btn:hover { background: var(--bg-2); color: var(--text); }

.dot-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 172px;
  z-index: 999;
  padding: 4px 0;
  animation: slideUp .15s ease;
}
.dot-menu-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 14px;
  text-align: left; background: none; border: none;
  font-size: 13.5px; font-family: var(--font-sans);
  color: var(--text); cursor: pointer;
  transition: background .1s ease;
}
.dot-menu-item:hover  { background: var(--bg-2); }
.dot-menu-danger      { color: var(--red); }
.dot-menu-danger:hover { background: var(--red-l); }
.dot-menu-divider     { height: 1px; background: var(--border); margin: 4px 0; }

/* ══════════════════════════════════════════════════════════════════════════════
   DUP ALERT
══════════════════════════════════════════════════════════════════════════════ */
.dup-alert {
  background: var(--amber-l);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #78350f;
  margin-bottom: 14px;
  animation: slideUp .2s ease;
}

/* ══════════════════════════════════════════════════════════════════════════════
   STORICO ROWS
══════════════════════════════════════════════════════════════════════════════ */
.storico-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: background .15s ease;
}
.storico-row:hover { background: var(--teal-l); border-color: var(--teal-m); }
.storico-data   { font-size: 12.5px; color: var(--text-3); min-width: 80px; flex-shrink: 0; }
.storico-motivo { flex: 1; font-size: 13.5px; font-weight: 500; }

/* ══════════════════════════════════════════════════════════════════════════════
   CHAT LAYOUT
══════════════════════════════════════════════════════════════════════════════ */
.chat-layout {
  display: flex;
  height: calc(100vh - 65px);
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
}

/* Chat topbar with integrated progress */
.chat-topbar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-patient-name { font-weight: 600; font-size: 15px; color: var(--text); }
.chat-patient-sub  { font-size: 12px; color: var(--text-3); }

/* Inline progress inside topbar */
.progress-track {
  height: 3px;
  background: var(--bg-2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--teal);
  transition: width .5s ease, background .3s ease;
}
.progress-fill.followup { background: var(--amber); }

/* Legacy progress-bar-wrap (kept for JS compatibility) */
.progress-bar-wrap {
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: var(--text-3);
  margin-bottom: 6px;
}

/* Messages */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column;
  gap: 12px;
}

.msg-row { display: flex; align-items: flex-start; gap: 10px; animation: slideUp .25s ease; }
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.msg-avatar.bot  { background: var(--teal); color: #fff; font-size: 16px; }
.msg-avatar.user { background: var(--bg-2); font-size: 16px; }

.msg-bubble {
  max-width: 70%;
  padding: 11px 15px;
  font-size: var(--chat-font, 14.5px);
  line-height: 1.6;
  box-shadow: var(--shadow-xs);
}
.msg-bubble.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  color: var(--text);
}
.msg-bubble.user {
  background: var(--teal);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}

.typing-dots { display: flex; gap: 5px; padding: 4px 0; align-items: center; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--teal);
  animation: pulse 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

/* Chat input */
.chat-input-wrap {
  padding: 16px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end;
  flex-shrink: 0;
}
.chat-textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14.5px;
  resize: none;
  max-height: 100px;
  outline: none;
  background: var(--bg);
  transition: border-color .15s ease, background .15s ease;
}
.chat-textarea:focus { border-color: var(--teal); background: var(--surface); }
.chat-send {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--teal); color: #fff; border: none;
  font-size: 17px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.chat-send:hover    { background: var(--teal-d); }
.chat-send:disabled { background: var(--border); cursor: not-allowed; }

/* ══════════════════════════════════════════════════════════════════════════════
   REPORT PANEL
══════════════════════════════════════════════════════════════════════════════ */
.report-panel {
  width: 340px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.report-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
}
.report-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 10px;
}
.report-field {
  display: flex; gap: 10px;
  margin-bottom: 6px;
  font-size: 13.5px;
}
.report-field-label {
  color: var(--text-3);
  min-width: 130px;
  flex-shrink: 0;
}
.report-field-value { font-weight: 500; color: var(--text); }

.report-tag {
  display: inline-block;
  background: var(--teal-l); color: var(--teal);
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 12.5px;
  margin: 2px;
}
.report-tag.orange { background: var(--amber-l); color: var(--amber); }

.consiglio-item {
  background: var(--amber-l);
  border-left: 3px solid var(--amber);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 8px;
  color: #78350f;
}

.report-actions {
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 8px;
}

.note-textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color .15s ease;
  font-family: var(--font-sans);
  background: var(--surface);
}
.note-textarea:focus { border-color: var(--teal); }

/* ══════════════════════════════════════════════════════════════════════════════
   SCHEDA CLINICA
══════════════════════════════════════════════════════════════════════════════ */
.scheda-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.scheda-section { padding: 16px 20px; }
.scheda-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 10px;
}
.scheda-print-header {
  display: none;
  font-size: 13px; color: var(--text-2);
  border-bottom: 2px solid var(--teal);
  padding-bottom: 10px; margin-bottom: 20px;
  line-height: 1.6;
}

/* ══════════════════════════════════════════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════════════════════════════════════════ */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px;
  color: var(--text-3); text-align: center;
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: .3; }
.empty-state-text { font-size: 15px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.empty-state-sub  { font-size: 13px; color: var(--text-3); }

/* ══════════════════════════════════════════════════════════════════════════════
   SPINNER
══════════════════════════════════════════════════════════════════════════════ */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
  display: inline-block;
}
.spinner.dark {
  border-color: rgba(13,148,136,.2);
  border-top-color: var(--teal);
}

/* ══════════════════════════════════════════════════════════════════════════════
   PAZIENTE SEARCH BAR
══════════════════════════════════════════════════════════════════════════════ */
.paz-search-wrap {
  position: relative;
  margin-bottom: 16px;
}
.paz-search-wrap .search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.paz-search-wrap .form-input {
  padding-left: 40px;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.paz-search-wrap .search-count {
  position: absolute;
  right: 14px; top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-3);
}

/* Paz avatar (storico modal) */
.paz-avatar {
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* Paz loading */
.paz-loading {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 0; color: var(--text-3); font-size: 13.5px;
}

/* ══════════════════════════════════════════════════════════════════════════════
   STAT CARD HELPERS
══════════════════════════════════════════════════════════════════════════════ */
.stat-inner  { display: flex; justify-content: space-between; align-items: flex-start; }
.stat-card.indigo { border-left-color: var(--indigo); }
.stat-card.amber  { border-left-color: var(--amber); }

.stat-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon-teal   { background: var(--teal-l);   color: var(--teal); }
.stat-icon-indigo { background: var(--indigo-l); color: var(--indigo); }
.stat-icon-amber  { background: var(--amber-l);  color: var(--amber); }

/* ══════════════════════════════════════════════════════════════════════════════
   TABLE CELL HELPERS
══════════════════════════════════════════════════════════════════════════════ */
.name-cell   { display: flex; align-items: center; gap: 10px; }
.row-avatar  {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--teal-l); color: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.td-actions  { display: flex; gap: 6px; justify-content: flex-end; }

/* ══════════════════════════════════════════════════════════════════════════════
   PATIENT MODAL
══════════════════════════════════════════════════════════════════════════════ */
.patient-modal-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.patient-modal-name   { font-family: var(--font-serif); font-size: 22px; color: var(--text); }
.patient-modal-sub    { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.patient-contacts     { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.patient-contact      { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }

/* ══════════════════════════════════════════════════════════════════════════════
   LINK MODAL
══════════════════════════════════════════════════════════════════════════════ */
.link-box {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  margin-bottom: 16px;
}
.link-box-url {
  flex: 1; font-size: 12.5px; word-break: break-all;
  color: var(--teal); font-family: monospace;
}
.email-send-row { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }

/* Share buttons */
.share-buttons {
  display: flex; gap: 10px; margin: 16px 0;
}
.share-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 10px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; font-family: var(--font-sans);
  text-decoration: none; cursor: pointer; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-2);
  transition: all .2s;
}
.share-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.share-whatsapp { color: #25d366; border-color: #25d366; }
.share-whatsapp:hover { background: #25d366; color: white; }
.share-sms { color: #3b82f6; border-color: #3b82f6; }
.share-sms:hover { background: #3b82f6; color: white; }
.share-email-toggle { color: var(--teal); border-color: var(--teal); }
.share-email-toggle:hover { background: var(--teal); color: white; }
.info-note {
  background: var(--amber-l);
  border-left: 3px solid var(--amber);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px; font-size: 13px;
  color: #78350f; margin-bottom: 20px;
  line-height: 1.55;
}

/* ══════════════════════════════════════════════════════════════════════════════
   CHAT COMPLETE INDICATOR
══════════════════════════════════════════════════════════════════════════════ */
.chat-complete {
  width: 100%; text-align: center;
  color: var(--text-3); font-size: 13.5px;
  padding: 12px 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

/* Modal subtitle */
.modal-subtitle { font-size: 13.5px; color: var(--text-2); margin-bottom: 16px; line-height: 1.5; }

/* ══════════════════════════════════════════════════════════════════════════════
   PRINT
══════════════════════════════════════════════════════════════════════════════ */
@media print {
  .sidebar, .page-header .btn, .page-header button,
  .modal-overlay, #modal-root { display: none !important; }
  .app-shell { display: block !important; }
  .main-content { overflow: visible !important; }
  .page-header { border: none; padding: 0 0 16px; }
  .page-body { padding: 0; }
  .scheda-print-header { display: block !important; }
  .scheda-grid { grid-template-columns: repeat(2,1fr); gap: 12px; }
  .scheda-section, .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
  .note-textarea { border: 1px solid #ccc; min-height: 60px; }
  .report-tag { border: 1px solid #999; background: transparent !important; }
  .report-tag.orange { border-color: #d97706; }
  .table tbody tr:hover { background: transparent !important; }
  a, button { display: none !important; }
  .page-header .page-title, .page-header .page-subtitle { display: block !important; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .sidebar-logo-text, .nav-item span:not(.nav-item-icon), .medico-info { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-logo { justify-content: center; padding: 16px 12px; }
  .sidebar-logo-icon { margin: 0; }
  .medico-badge { justify-content: center; padding: 10px; }
  .medico-avatar { margin: 0; }
  .logout-btn { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .report-panel { width: 300px; }
  .notif-dropdown { width: calc(100vw - 80px); right: 4px; }
}
