/* ═══════════════════════════════════════════════════════
   SGA Segretario AI — Design System
   Light theme "Intelligent Concierge" + Tiffany #0BB5A8
   Font: Inter / JetBrains Mono
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;450;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Variables ─────────────────────────────────────── */
:root {
  /* Surface hierarchy (tonal layering) */
  --bg-deep: #F5F3F3;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F8F6F6;
  --bg-elevated: #F0EEEE;
  --bg-input: #F8F7F7;

  /* Brand */
  --accent: #0BB5A8;
  --accent-glow: rgba(11, 181, 168, 0.10);
  --accent-soft: rgba(11, 181, 168, 0.06);
  --accent-border: rgba(11, 181, 168, 0.25);

  /* Text */
  --text-primary: #1B1C1C;
  --text-secondary: #3C4947;
  --text-muted: #7A8A86;

  /* Status */
  --danger: #E53935;
  --warning: #F9A825;
  --success: #43A047;
  --info: #2196F3;

  --danger-soft: #FFF0F0;
  --warning-soft: #FFF8E1;
  --success-soft: #F0FFF4;
  --info-soft: #E3F2FD;

  /* Borders — ghost borders, tonal shifts */
  --border: rgba(0, 0, 0, 0.06);
  --border-hover: rgba(0, 0, 0, 0.10);

  /* Radii */
  --radius-card: 12px;
  --radius-inner: 8px;
  --radius-badge: 6px;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 64px;

  /* Shadows — tinted with on_surface, never pure black */
  --shadow-card: 0 1px 3px rgba(27, 28, 28, 0.04), 0 1px 2px rgba(27, 28, 28, 0.02);
  --shadow-elevated: 0 4px 12px rgba(27, 28, 28, 0.06);
  --shadow-float: 0 12px 32px -4px rgba(27, 28, 28, 0.08);

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 15px;
  scroll-behavior: smooth;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(11, 181, 168, 0.15);
  touch-action: manipulation;
}
a { color: var(--accent); text-decoration: none; transition: opacity 0.2s; }
a:hover { opacity: 0.85; }
button { font-family: var(--font-sans); cursor: pointer; border: none; outline: none; }
input, textarea, select { font-family: var(--font-sans); outline: none; }
img { max-width: 100%; }

/* ── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.20); }

/* ── Animations ────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-fade { animation: fadeIn 0.8s ease both; }
.animate-slide { animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both; }
.animate-scale { animation: scaleIn 0.5s cubic-bezier(0.16,1,0.3,1) both; }
.animate-slide-left { animation: slideInLeft 0.6s cubic-bezier(0.16,1,0.3,1) both; }
.animate-pulse { animation: pulse 2s ease-in-out infinite; }

/* Staggered delays */
.delay-1 { animation-delay: 0.05s; }
.delay-2 { animation-delay: 0.10s; }
.delay-3 { animation-delay: 0.15s; }
.delay-4 { animation-delay: 0.20s; }
.delay-5 { animation-delay: 0.25s; }
.delay-6 { animation-delay: 0.30s; }
.delay-7 { animation-delay: 0.35s; }
.delay-8 { animation-delay: 0.40s; }

/* ══════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════ */

.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  animation: slideInLeft 0.6s cubic-bezier(0.16,1,0.3,1) both;
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  box-shadow: 1px 0 0 var(--border);
}
.sidebar-logo {
  padding: 20px 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-logo-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-inner);
  background: linear-gradient(135deg, var(--accent), #0d9488);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.sidebar-logo-text strong {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}
.sidebar-logo-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 8px 10px;
  overflow-y: auto;
}
.nav-section-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 16px 12px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-inner);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 450;
  transition: all 0.2s;
  position: relative;
}
.nav-item:hover {
  background: var(--accent-soft);
  color: var(--text-primary);
}
.nav-item.active {
  background: rgba(11, 181, 168, 0.10);
  color: var(--accent);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-item svg,
.nav-item .material-symbols-outlined {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}
.nav-item .material-symbols-outlined {
  font-size: 20px;
  width: auto;
  height: auto;
}
.nav-item.active svg,
.nav-item.active .material-symbols-outlined { opacity: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #0d9488);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-footer-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}
.sidebar-footer-info strong {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer-info .status-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

/* ── Main content ──────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  max-width: calc(100vw - var(--sidebar-width));
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Header ────────────────────────────────────────── */
.header {
  height: var(--header-height);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  animation: fadeIn 0.6s ease both;
}
.header-left h1 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}
.header-left p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Page content ──────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px 32px;
  animation: fadeIn 0.8s ease both;
  max-width: 100%;
  overflow-x: hidden;
}

/* ══════════════════════════════════════════════════════
   COMPONENTS
   ══════════════════════════════════════════════════════ */

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-inner);
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.btn svg { width: 16px; height: 16px; }
.btn .material-symbols-outlined { font-size: 18px; }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: #0aa69a;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(11, 181, 168, 0.25);
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border);
  box-shadow: var(--shadow-card);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(229, 57, 53, 0.15);
}
.btn-danger:hover { background: rgba(229, 57, 53, 0.12); }
.btn-sm { padding: 5px 10px; font-size: 0.76rem; }
.wa-group-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(11,181,168,0.3);
}
.wa-pending-card {
  background: var(--bg-card);
  border: 1px solid rgba(11, 181, 168, 0.15);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-inner);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
  width: 100%;
}
.wa-pending-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.wa-context-summary {
  border-left: 3px solid var(--accent);
  background: #F0FDFA;
  padding: 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.6;
  color: #1a3a36;
  margin-bottom: 12px;
  min-height: 60px;
}
.wa-recent-messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.wa-msg-preview {
  padding: 8px 12px;
  border-radius: 6px;
  background: #FAFAFA;
}
.wa-msg-inbound { border-left: 2px solid #42A5F5; }
.wa-msg-outbound { border-left: 2px solid #66BB6A; }
.wa-pending-subject {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.wa-pending-reason {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 12px;
}
.wa-pending-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.btn-success {
  background: #43A047;
  color: #fff;
  border: none;
}
.btn-success:hover { background: #388E3C; }
.btn-accent {
  background: var(--accent);
  color: #fff;
  border: none;
}
.btn-accent:hover { background: #099e93; }
.wa-link-email {
  font-size: 0.78rem;
  margin-left: auto;
}
.btn-icon {
  padding: 8px;
  border-radius: var(--radius-inner);
}
.btn.loading { pointer-events: none; opacity: 0.7; }
.btn.loading::after {
  content: '';
  width: 14px; height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Stat cards ────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 20px;
  transition: all 0.25s cubic-bezier(0.16,1,0.3,1);
  animation: scaleIn 0.5s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-card);
}
.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.stat-card-header span {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 450;
}
.stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-inner);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon svg { width: 18px; height: 18px; }
.stat-icon .material-symbols-outlined { font-size: 20px; }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}
.stat-card .stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Tabs ──────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-elevated);
  border-radius: var(--radius-inner);
  padding: 3px;
  margin-bottom: 20px;
  width: fit-content;
}
.tab {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 450;
  color: var(--text-secondary);
  background: transparent;
  transition: all 0.2s;
}
.tab:hover { color: var(--text-primary); background: rgba(0,0,0,0.03); }
.tab.active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 500;
  box-shadow: var(--shadow-card);
}

/* ── Email cards ───────────────────────────────────── */
.email-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
  overflow: hidden;
}
a.email-card,
.email-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 16px 18px;
  display: flex;
  gap: 14px;
  transition: all 0.25s cubic-bezier(0.16,1,0.3,1);
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
a.email-card,
.email-card,
.stat-card,
.contact-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(11, 181, 168, 0.15);
}

/* Hover effects only for pointer devices (not touch) */
@media (hover: hover) {
  .email-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated);
    background: var(--bg-card);
  }
  .stat-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated);
  }
  .contact-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated);
  }
}

/* Touch feedback */
.email-card:active,
.stat-card:active,
.contact-card:active {
  background: var(--bg-card-hover);
}

/* Contact avatar */
.contact-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.email-card-body {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.email-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.email-sender {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-company {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.email-subject {
  font-size: 13px;
  font-weight: 450;
  color: var(--text-secondary);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-preview {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* AI detailed summary — clamped to 3 lines max */
.email-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 0;
  border-left: 2px solid var(--accent);
  padding: 8px 12px;
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag {
  font-size: 0.68rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-badge);
  letter-spacing: 0.02em;
}
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-warning { background: var(--warning-soft); color: var(--warning); }
.tag-success { background: var(--success-soft); color: var(--success); }
.tag-info { background: var(--info-soft); color: var(--info); }
.tag-muted { background: var(--bg-elevated); color: var(--text-muted); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.tag-lang {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 0.64rem;
  padding: 2px 6px;
}

/* AI analysis box */
.ai-box {
  background: var(--accent-soft);
  border: 1px solid rgba(11,181,168,0.08);
  border-radius: var(--radius-inner);
  padding: 10px 14px;
  margin-top: 4px;
}
.ai-box-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.ai-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
.ai-box-header span {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ai-box p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
.ai-box .ai-action {
  font-size: 0.76rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: 4px;
}

/* ── Contact cards ─────────────────────────────────── */
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.contact-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 20px;
  display: flex;
  gap: 14px;
  transition: all 0.25s cubic-bezier(0.16,1,0.3,1);
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-card);
}
.contact-info h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}
.contact-info .company {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.contact-info .meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 8px;
  display: flex;
  gap: 12px;
}

/* ── Attachment cards ──────────────────────────────── */
.attachments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.attachment-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 18px;
  transition: all 0.25s cubic-bezier(0.16,1,0.3,1);
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-card);
}
.attachment-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-elevated);
}
.attachment-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-inner);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.attachment-icon.pdf { background: var(--danger-soft); color: var(--danger); }
.attachment-icon.excel { background: var(--success-soft); color: var(--success); }
.attachment-icon.image { background: var(--info-soft); color: var(--info); }
.attachment-icon.doc { background: var(--info-soft); color: #6366f1; }
.attachment-icon.other { background: var(--bg-elevated); color: var(--text-muted); }
.attachment-card h4 {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-card .att-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.attachment-card .att-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.attachment-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

/* ── Thread detail ─────────────────────────────────── */
.thread-header {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 22px;
  margin-bottom: 20px;
  animation: fadeIn 0.6s ease both;
  box-shadow: var(--shadow-card);
}
.thread-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.thread-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.thread-meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.thread-meta-item svg { width: 14px; height: 14px; color: var(--text-muted); }

/* Thread summary card */
.thread-summary-card {
  background: var(--bg-card);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-card);
  padding: 18px 20px;
  margin-bottom: 16px;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-card);
}

/* Thread detail layout */
.thread-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  max-width: 100%;
  overflow: hidden;
}

/* Messages timeline — clean light style */
.messages-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
  min-width: 0;
  overflow: hidden;
  padding: 20px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

/* ── Message bubbles — Outlook email style ─────────────── */
.msg-bubble {
  padding: 14px 18px;
  max-width: 100%;
  animation: slideUp 0.4s cubic-bezier(0.16,1,0.3,1) both;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
  position: relative;
  border-radius: var(--radius-inner);
}

/* Inbound: light gray, blue left border */
.msg-bubble.inbound {
  background: #F8F9FA;
  color: var(--text-primary);
  border-left: 3px solid #2196F3;
  margin-right: 0;
}
/* Outbound: light green, green left border */
.msg-bubble.outbound {
  background: #E8F5E9;
  color: var(--text-primary);
  border-left: 3px solid #43A047;
  margin-left: 0;
}

/* Header: sender + time */
.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.75rem;
  gap: 12px;
}
.msg-bubble.inbound .msg-sender { font-weight: 600; color: #1565C0; }
.msg-bubble.inbound .msg-time { color: var(--text-muted); }
.msg-bubble.outbound .msg-sender { font-weight: 600; color: #2E7D32; }
.msg-bubble.outbound .msg-time { color: var(--text-muted); }

/* ── Message body text ── */
.msg-body-text {
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  min-width: 0;
  color: var(--text-primary);
}

/* ── AI summary label ── */
.msg-ai-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
}

/* ── Original text separator + body ── */
.msg-original-separator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
  user-select: none;
}
.msg-original-separator::before,
.msg-original-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.msg-original-text {
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  color: var(--text-muted);
}

/* ── Badges inside bubble ── */
.msg-bubble .tags { margin-top: 6px; margin-bottom: 0; }

/* msg-original-toggle */
.msg-original-toggle {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* Chat email citation blocks */
.chat-email-inbound {
  margin: 8px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-inner) var(--radius-inner) 0;
  font-size: 0.82rem;
}
.chat-email-outbound {
  margin: 8px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--text-muted);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-inner) var(--radius-inner) 0;
  font-size: 0.82rem;
}

/* ── Reply box ─────────────────────────────────────── */
.reply-box {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 20px;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-card);
}
.reply-box h3 {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.reply-textarea {
  width: 100%;
  min-height: 100px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 0.86rem;
  resize: vertical;
  transition: border-color 0.2s;
}
.reply-textarea:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.reply-textarea::placeholder {
  color: var(--text-muted);
}
.reply-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

/* ── Chat interface ────────────────────────────────── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.chat-msg {
  max-width: 680px;
  padding: 14px 18px;
  border-radius: var(--radius-card);
  font-size: 0.88rem;
  line-height: 1.6;
  animation: slideUp 0.3s cubic-bezier(0.16,1,0.3,1) both;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}
.chat-msg.ai {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
}
.chat-msg.ai .chat-msg-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.chat-input-area {
  padding: 16px 32px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.chat-chip {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 450;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.chat-chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}
.chat-input-row {
  display: flex;
  gap: 10px;
}
.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.88rem;
  transition: border-color 0.2s;
}
.chat-input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.chat-input::placeholder {
  color: var(--text-muted);
}

/* ── Quick chat bar (dashboard bottom) ─────────────── */
.quick-chat {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  padding: 14px 32px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 40;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  animation-delay: 0.4s;
  box-shadow: 0 -2px 8px rgba(27, 28, 28, 0.04);
}
.quick-chat .chat-suggestions { margin-bottom: 10px; }

/* ── Settings sections ─────────────────────────────── */
.settings-section {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 24px;
  margin-bottom: 20px;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-card);
}
.settings-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-section h2 svg { width: 18px; height: 18px; color: var(--accent); }

/* Rules table */
.rules-table {
  width: 100%;
  border-collapse: collapse;
}
.rules-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.rules-table td {
  font-size: 0.84rem;
  color: var(--text-secondary);
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.rules-table tr:hover td {
  background: var(--bg-card-hover);
}

/* ── Contact detail ────────────────────────────────── */
.contact-hero {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 28px;
  margin-bottom: 24px;
  display: flex;
  gap: 20px;
  align-items: center;
  animation: fadeIn 0.6s ease both;
  box-shadow: var(--shadow-card);
}
.contact-hero .contact-avatar-lg {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.contact-hero h2 { font-size: 1.2rem; font-weight: 700; }
.contact-hero .contact-email { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.detail-panel {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 22px;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
  box-shadow: var(--shadow-card);
}
.detail-panel h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-primary);
}

/* ── Search & Filters ──────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.search-input {
  flex: 1;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 10px 14px 10px 36px;
  color: var(--text-primary);
  font-size: 0.86rem;
  transition: border-color 0.2s;
  box-shadow: var(--shadow-card);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%237A8A86' viewBox='0 0 24 24'%3E%3Cpath d='M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z' stroke='%237A8A86' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.search-input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-input::placeholder { color: var(--text-muted); }

.filter-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 450;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.filter-btn:hover,
.filter-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* ── Empty state ───────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  animation: fadeIn 0.8s ease both;
}
.empty-state svg {
  width: 56px; height: 56px;
  color: var(--text-muted);
  margin-bottom: 16px;
  opacity: 0.4;
}
.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.empty-state p {
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* ── Loading skeleton ──────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-inner);
}
.skeleton-card {
  height: 100px;
  margin-bottom: 8px;
  border-radius: var(--radius-card);
}
.skeleton-line {
  height: 14px;
  margin-bottom: 8px;
  width: 70%;
}
.skeleton-line.short { width: 40%; }

/* ── Toast notification ────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border-radius: var(--radius-inner);
  padding: 12px 18px;
  font-size: 0.84rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  animation: slideUp 0.3s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-float);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }

/* ── Analytics ─────────────────────────────────────── */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.analytics-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 22px;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  box-shadow: var(--shadow-card);
}
.analytics-card h3 {
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 16px;
}
.analytics-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.analytics-bar-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  width: 100px;
  flex-shrink: 0;
}
.analytics-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}
.analytics-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
}
.analytics-bar-value {
  font-size: 0.76rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Code/data text ────────────────────────────────── */
.mono { font-family: var(--font-mono); font-size: 0.82rem; }

/* ── Badge ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-badge);
}
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-muted { background: var(--bg-elevated); color: var(--text-muted); }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */

.sidebar-toggle {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 8px;
  color: var(--text-secondary);
  cursor: pointer;
}
.sidebar-toggle svg { width: 20px; height: 20px; }
.sidebar-toggle .material-symbols-outlined { font-size: 22px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 90;
}

@media (max-width: 1200px) {
  .thread-layout { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .msg-bubble { max-width: 100%; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-float);
  }
  .sidebar-overlay.open {
    display: block;
  }
  .sidebar-toggle {
    display: flex;
  }
  .main-content {
    margin-left: 0;
    max-width: 100vw;
  }
  .quick-chat {
    left: 0;
    padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .header { padding: 0 16px; height: 60px; }
  .header-left h1 { font-size: 1.05rem; }
  .header-left p { font-size: 0.82rem; }
  .page-content { padding: 20px 16px 140px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .contacts-grid { grid-template-columns: 1fr; }
  .attachments-grid { grid-template-columns: 1fr 1fr; }
  .email-card { flex-direction: column; }
  .chat-input-area { padding: 12px 16px 16px; }

  /* Font sizes mobile */
  .stat-card-header span { font-size: 0.85rem; }
  .stat-card .stat-value { font-size: 2rem; }
  .stat-card .stat-label { font-size: 0.8rem; }

  .email-sender { font-size: 15px; }
  .email-subject { font-size: 14px; }
  .email-preview { font-size: 14px; }
  .email-time { font-size: 12px; }
  .email-company { font-size: 13px; }
  .email-summary { font-size: 14px; }

  .tag { font-size: 0.75rem; padding: 4px 10px; }
  .tag-lang { font-size: 0.72rem; }

  .contact-avatar { width: 44px; height: 44px; font-size: 0.85rem; }

  /* Tap targets minimi 44px (Apple HIG) */
  .tab { padding: 10px 16px; min-height: 44px; display: flex; align-items: center; }
  .btn { min-height: 44px; }
  .nav-item { min-height: 44px; display: flex; align-items: center; }

  /* Chat chip */
  .chat-chip { font-size: 0.82rem; padding: 8px 14px; }
  .chat-input { font-size: 16px; }

  /* Thread detail mobile */
  .msg-bubble { font-size: 14px; }
  .msg-body-text { font-size: 14px; line-height: 1.6; }
  .msg-original-text { font-size: 13px; }
  .msg-sender { font-size: 14px; }
  .msg-time { font-size: 12px; }
  .reply-textarea { font-size: 16px; }
  .thread-header h2 { font-size: 1.1rem; }
  .detail-panel { font-size: 14px; }
  .detail-panel h3 { font-size: 15px; }

  /* Sidebar mobile */
  .sidebar-nav .nav-item {
    padding: 14px 20px;
    font-size: 0.95rem;
  }
  .sidebar-logo { padding: 18px 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .attachments-grid { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; width: 100%; }
}
