/**
 * ChatAI Platform — design system (PLAIN CSS).
 *
 * Tailwind is loaded via the Play CDN, which does NOT process `@apply` inside
 * external CSS files. So every rule below is written in PLAIN CSS (real
 * properties) and always renders. Tailwind utility classes used directly in
 * the HTML still work (the CDN scans the markup); only this file must avoid
 * `@apply`.
 *
 * Palette: white background + professional green accent.
 *   green-600  #16a34a  (primary)
 *   green-700  #15803d  (hover / active)
 *   green-50   #f0fdf4  (light wash)
 *   green-100  #dcfce7  (light fill / ring)
 *   ink        #0f172a / #111827  (text)
 *   muted      #6b7280  (secondary text)
 *   border     #e5e7eb
 */

/* ================================================================== */
/* Base tokens                                                        */
/* ================================================================== */
:root {
  --green-50:  #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-800: #166534;

  --ink:       #111827;
  --ink-soft:  #374151;
  --muted:     #6b7280;
  --muted-2:   #9ca3af;
  --border:    #e5e7eb;
  --border-2:  #d1d5db;
  --surface:   #ffffff;
  --app-bg:    #f8fafc;

  --sidebar-w: 248px;
  --radius:    0.75rem;   /* rounded-xl */
  --radius-sm: 0.5rem;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow:    0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.bg-app { background-color: var(--app-bg); }

[x-cloak] { display: none !important; }

/* ================================================================== */
/* App shell — fixed sidebar + scrollable main                       */
/* ================================================================== */
.app-shell {
  min-height: 100vh;
}

.app-main {
  min-height: 100vh;
  background-color: var(--app-bg);
  transition: padding-left .2s ease;
}

.app-container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}

/* Desktop: sidebar fixed on the left, content shifted over. */
@media (min-width: 1024px) {
  .app-main { padding-left: var(--sidebar-w); }
}

/* ================================================================== */
/* Mobile top bar                                                     */
/* ================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 56px;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-burger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  background: transparent;
  border: none;
  cursor: pointer;
}
.topbar-burger:hover { background: var(--green-50); color: var(--green-700); }

/* ================================================================== */
/* Sidebar                                                            */
/* ================================================================== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  /* Mobile: off-canvas drawer */
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.sidebar-open { transform: translateX(0); box-shadow: var(--shadow-md); }

@media (min-width: 1024px) {
  .sidebar { transform: translateX(0); box-shadow: none; }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.45);
}

/* Brand block */
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 0.6rem;
  background: linear-gradient(135deg, var(--green-600), var(--green-700));
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.35);
  flex-shrink: 0;
}
.brand-logo-sm { width: 30px; height: 30px; border-radius: 0.5rem; }
.brand-name {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.1;
}
.brand-tenant {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 1px;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
}
.sidebar-close:hover { background: #f3f4f6; color: var(--ink); }

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background-color .15s ease, color .15s ease;
}
.nav-item:hover {
  background: var(--green-50);
  color: var(--green-700);
}
.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--muted-2);
  transition: color .15s ease;
}
.nav-item:hover .nav-icon { color: var(--green-600); }

.nav-item-active {
  background: var(--green-50);
  color: var(--green-700);
}
.nav-item-active::before {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--green-600);
}
.nav-item-active .nav-icon { color: var(--green-600); }

.nav-dot {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  flex-shrink: 0;
}
.nav-dot-warn { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15); }

/* Footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 0.85rem 0.9rem 1rem;
  flex-shrink: 0;
}
.conn-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--green-50);
  margin-bottom: 0.6rem;
}
.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 9999px;
  flex-shrink: 0;
}
.conn-dot-on {
  background: var(--green-500);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}
.conn-dot-off { background: var(--muted-2); }
.conn-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--green-800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conn-label-off { color: var(--muted); }
.conn-status:has(.conn-dot-off) { background: #f9fafb; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: var(--green-100);
  color: var(--green-800);
  font-size: 0.82rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user-email {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}
.signout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.signout-btn:hover { background: #fef2f2; color: #dc2626; }

/* ================================================================== */
/* Page header                                                        */
/* ================================================================== */
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.page-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* ================================================================== */
/* Cards                                                              */
/* ================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1.5rem; }
.card-lg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}
.card-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.card-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* ================================================================== */
/* Stat tiles                                                         */
/* ================================================================== */
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.stat-tile:hover { box-shadow: var(--shadow); border-color: #dbe3ea; }
.stat-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.stat-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 0.4rem;
  background: var(--green-50);
  color: var(--green-600);
}
.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.1;
}
.stat-value-green { color: var(--green-600); }
.stat-value-red   { color: #dc2626; }

/* ================================================================== */
/* Buttons                                                            */
/* ================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease,
              box-shadow .15s ease, transform .05s ease, color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--green-600);
  color: #fff;
  box-shadow: 0 1px 2px rgba(22, 163, 74, 0.3);
}
.btn-primary:hover:not(:disabled) { background: var(--green-700); }

.btn-secondary {
  background: #fff;
  color: var(--ink-soft);
  border-color: var(--border-2);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) { background: #f9fafb; border-color: #c3cbd4; }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-ghost {
  background: transparent;
  color: var(--green-700);
}
.btn-ghost:hover:not(:disabled) { background: var(--green-50); }

.btn-ghost-danger {
  background: transparent;
  color: #dc2626;
}
.btn-ghost-danger:hover:not(:disabled) { background: #fef2f2; }

.btn-lg { padding: 0.7rem 1.3rem; font-size: 0.95rem; }
.btn-block { width: 100%; }

/* ================================================================== */
/* Toggle switch                                                      */
/* ================================================================== */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 46px;
  height: 26px;
  border-radius: 9999px;
  background: #d1d5db;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background-color .18s ease;
}
.toggle:focus-visible { outline: 2px solid var(--green-600); outline-offset: 2px; }
.toggle-on { background: var(--green-600); }
.toggle-knob {
  position: absolute;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform .18s ease;
}
.toggle-on .toggle-knob { transform: translateX(20px); }

/* ================================================================== */
/* Selectable option cards (Reply Mode, etc.)                        */
/* ================================================================== */
.option-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  text-align: left;
  padding: 0.8rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease,
              box-shadow .15s ease;
}
.option-card:hover { border-color: var(--green-200); background: var(--green-50); }
.option-card-selected {
  border-color: var(--green-600);
  background: var(--green-50);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12);
}
.option-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}
.option-card-selected .option-card-title { color: var(--green-700); }
.option-card-desc {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ================================================================== */
/* Forms                                                              */
/* ================================================================== */
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}
.form-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}
.input,
.textarea,
.select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}
.textarea { resize: vertical; }
.textarea-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.input:disabled, .textarea:disabled, .select:disabled {
  background: #f3f4f6;
  color: var(--muted);
  cursor: not-allowed;
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1.1rem;
  padding-right: 2.25rem;
}

/* Checkbox */
.checkbox {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--green-600);
  cursor: pointer;
}
.check-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--ink-soft);
  cursor: pointer;
}

/* Filter pill / segmented control */
.seg {
  display: inline-flex;
  padding: 0.25rem;
  background: #f3f4f6;
  border-radius: 0.6rem;
  gap: 0.2rem;
}
.seg-btn {
  padding: 0.4rem 0.95rem;
  border-radius: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg-btn:hover { color: var(--ink-soft); }
.seg-btn-active {
  background: #fff;
  color: var(--green-700);
  box-shadow: var(--shadow-sm);
}

/* ================================================================== */
/* Badges                                                             */
/* ================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.3;
}
.badge-success { background: var(--green-100); color: var(--green-800); }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f3f4f6; color: #4b5563; }

/* ================================================================== */
/* Alert banners                                                      */
/* ================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--green-50); border-color: var(--green-200); color: var(--green-800); }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ================================================================== */
/* Tables                                                             */
/* ================================================================== */
.table { width: 100%; font-size: 0.875rem; border-collapse: collapse; }
.table th {
  padding: 0.6rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); color: var(--ink-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafafa; }

/* ================================================================== */
/* List rows (reels, inbox)                                           */
/* ================================================================== */
.list-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.list-row:hover { box-shadow: var(--shadow); border-color: #dbe3ea; }

/* ================================================================== */
/* Empty states                                                       */
/* ================================================================== */
.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 9999px;
  background: var(--green-50);
  color: var(--green-600);
  margin-bottom: 1rem;
}
.empty-title { font-size: 1rem; font-weight: 600; color: var(--ink-soft); }
.empty-text { font-size: 0.875rem; margin-top: 0.25rem; }

/* ================================================================== */
/* Toast                                                              */
/* ================================================================== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
}
.toast-success { background: var(--green-700); }

/* ================================================================== */
/* Login                                                              */
/* ================================================================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 50% -10%, var(--green-50), transparent),
    #ffffff;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
  padding: 2rem;
}

/* ================================================================== */
/* Animations / spinner                                               */
/* ================================================================== */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-fade-in { animation: fade-in .25s ease-out; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 1rem; height: 1rem; border-radius: 9999px;
  border: 2px solid rgba(255,255,255,0.5); border-top-color: #fff;
  animation: spin .6s linear infinite;
}

/* ================================================================== */
/* Utilities                                                          */
/* ================================================================== */
.truncate-1, .truncate-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.truncate-1 { -webkit-line-clamp: 1; }
.truncate-2 { -webkit-line-clamp: 2; }

:focus-visible { outline: 2px solid var(--green-600); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}

@media print {
  .sidebar, .topbar, .sidebar-overlay, .no-print { display: none !important; }
  .app-main { padding-left: 0 !important; }
}
