/* ============================================================
   Stern Network Outlook Add-in — Sidebar styles
   Design tokens inspired by shadcn/ui (new-york), tuned for
   Outlook's narrow task-pane viewport (320–420px wide).
   ============================================================ */

:root {
  --background: #ffffff;
  --foreground: #0a0a0a;
  --card: #ffffff;
  --card-foreground: #0a0a0a;
  --muted: #f5f5f5;
  --muted-foreground: #737373;
  --border: #e5e5e5;
  --input: #e5e5e5;
  --primary: #0a0a0a;
  --primary-foreground: #fafafa;
  --secondary: #f5f5f5;
  --secondary-foreground: #171717;
  --accent: #f5f5f5;
  --accent-foreground: #171717;
  --destructive: #ef4444;
  --success: #16a34a;
  --warning: #eab308;
  --ring: #0a0a0a;
  --radius: 0.625rem;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.04);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #fafafa;
    --card: #141414;
    --card-foreground: #fafafa;
    --muted: #1f1f1f;
    --muted-foreground: #a1a1a1;
    --border: #262626;
    --input: #262626;
    --primary: #fafafa;
    --primary-foreground: #0a0a0a;
    --secondary: #1f1f1f;
    --secondary-foreground: #fafafa;
    --accent: #1f1f1f;
    --accent-foreground: #fafafa;
    --ring: #fafafa;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.hidden {
  display: none !important;
}

/* ============================================================
   Header
   ============================================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.header-text { min-width: 0; }

.header-text h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  margin: 2px 0 0;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted-foreground);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-foreground);
}

.status--connecting .status-dot { background: var(--warning); animation: pulse 1.5s ease-in-out infinite; }
.status--connected .status-dot { background: var(--success); }
.status--error .status-dot { background: var(--destructive); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, color 120ms;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn:hover {
  background: var(--accent);
  color: var(--accent-foreground);
}

/* ============================================================
   Main scroll area
   ============================================================ */
.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============================================================
   Card
   ============================================================ */
.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 0;
}

.card-eyebrow {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-foreground);
}

.card-body {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-body--flush { padding: 6px 0 0; }

.card--context {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.card--empty {
  text-align: center;
  padding: 28px 20px;
  border-style: dashed;
  background: var(--muted);
}

.card--empty .empty-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  border-radius: 12px;
  background: var(--background);
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

.card--empty .empty-icon svg { width: 22px; height: 22px; }

.card--empty h2 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
}

.card--empty p {
  margin: 0;
  font-size: 12px;
  color: var(--muted-foreground);
  max-width: 240px;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================================
   Email preview
   ============================================================ */
.email-preview {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.email-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.email-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.email-from {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-email {
  margin: 0;
  font-size: 11px;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-subject {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--foreground);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   Buttons
   ============================================================ */
.button-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms, transform 80ms;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--full { width: 100%; }

.btn--primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn--primary:hover:not(:disabled) { background: #262626; }

.btn--secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: var(--border);
}
.btn--secondary:hover:not(:disabled) { background: var(--accent); }

.btn--ghost {
  background: transparent;
  color: var(--foreground);
  border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) { background: var(--accent); }

.icon-sm {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ============================================================
   Sync stats
   ============================================================ */
.muted {
  margin: 0;
  font-size: 12px;
  color: var(--muted-foreground);
}

.muted strong {
  color: var(--foreground);
  font-weight: 600;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  background: var(--muted);
  border-radius: 8px;
}

.stat-value {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stat-label {
  margin: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-foreground);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  background: var(--success);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ============================================================
   Recent list
   ============================================================ */
.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recent-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.recent-list li:first-child { border-top: none; }

.recent-list .recent-empty {
  justify-content: center;
  color: var(--muted-foreground);
  font-style: italic;
  border-top: none;
  padding: 14px;
}

.recent-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.recent-icon svg { width: 12px; height: 12px; }

.recent-text {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.recent-title {
  margin: 0;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-time {
  margin: 0;
  font-size: 10px;
  color: var(--muted-foreground);
}

/* ============================================================
   Footer link
   ============================================================ */
.footer-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  font-size: 12px;
  color: var(--muted-foreground);
  text-decoration: none;
  border-radius: 8px;
  transition: background 120ms, color 120ms;
}

.footer-link:hover {
  background: var(--accent);
  color: var(--accent-foreground);
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--foreground);
  color: var(--background);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

.toast--error { background: var(--destructive); color: #fff; }

.toast-icon { width: 16px; height: 16px; flex-shrink: 0; }

@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Scrollbar */
.main::-webkit-scrollbar { width: 8px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.main::-webkit-scrollbar-thumb:hover { background: var(--muted-foreground); }
