/* ═══════════════════════════════════════════════════════════
   AI Workspace — Full-page chat with thread sidebar
   Terms.Law 2025
   ═══════════════════════════════════════════════════════════ */

:root {
  --ws-sidebar-w: 280px;
  --ws-bg: #f6f8fa;
  --ws-sidebar-bg: #1a1a2e;
  --ws-sidebar-text: #e2e8f0;
  --ws-sidebar-muted: #94a3b8;
  --ws-sidebar-hover: rgba(255,255,255,0.06);
  --ws-sidebar-active: rgba(99,102,241,0.18);
  --ws-sidebar-border: rgba(255,255,255,0.08);
  --ws-accent: #6366f1;
  --ws-accent-light: #818cf8;
  --ws-danger: #ef4444;
}

/* ─── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--ws-bg);
  color: #1a1a2e;
}

/* ─── Layout Grid ──────────────────────────────────────── */
.ws-layout {
  display: grid;
  grid-template-columns: var(--ws-sidebar-w) 1fr;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.ws-layout.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

/* ─── Sidebar ──────────────────────────────────────────── */
.ws-sidebar {
  background: var(--ws-sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease;
  border-right: 1px solid var(--ws-sidebar-border);
}

.sidebar-collapsed .ws-sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

/* Sidebar Header */
.ws-sidebar-header {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--ws-sidebar-border);
  flex-shrink: 0;
}

.ws-sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ws-sidebar-brand a {
  color: var(--ws-sidebar-text);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.ws-sidebar-brand a:hover { opacity: 0.85; }

.ws-collapse-btn {
  background: none;
  border: none;
  color: var(--ws-sidebar-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
  font-size: 18px;
}
.ws-collapse-btn:hover { color: var(--ws-sidebar-text); background: var(--ws-sidebar-hover); }

/* New Chat Button */
.ws-new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--ws-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.ws-new-chat-btn:hover { background: var(--ws-accent-light); }
.ws-new-chat-btn svg { flex-shrink: 0; }

/* Search */
.ws-search-wrap {
  position: relative;
}
.ws-search-input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--ws-sidebar-border);
  border-radius: 6px;
  color: var(--ws-sidebar-text);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.ws-search-input::placeholder { color: var(--ws-sidebar-muted); }
.ws-search-input:focus { border-color: var(--ws-accent); }
.ws-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ws-sidebar-muted);
  pointer-events: none;
  font-size: 13px;
}

/* Thread List */
.ws-thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.ws-thread-list::-webkit-scrollbar { width: 4px; }
.ws-thread-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

/* Group Headers */
.ws-group-label {
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ws-sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Thread Item */
.ws-thread-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--ws-sidebar-text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s;
  position: relative;
}
.ws-thread-item:hover { background: var(--ws-sidebar-hover); }
.ws-thread-item.active { background: var(--ws-sidebar-active); }

.ws-thread-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}
.ws-thread-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.ws-thread-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.ws-thread-preview {
  font-size: 11px;
  color: var(--ws-sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.ws-thread-meta {
  font-size: 10px;
  color: var(--ws-sidebar-muted);
  margin-top: 3px;
  display: flex;
  gap: 6px;
}

/* Thread Actions (visible on hover) */
.ws-thread-actions {
  position: absolute;
  right: 6px;
  top: 6px;
  display: none;
  gap: 2px;
}
.ws-thread-item:hover .ws-thread-actions { display: flex; }
.ws-thread-action-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--ws-sidebar-muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1;
}
.ws-thread-action-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.ws-thread-action-btn.delete:hover { color: var(--ws-danger); }

/* Sidebar Footer */
.ws-sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--ws-sidebar-border);
  flex-shrink: 0;
}
.ws-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ws-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ws-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.ws-user-email {
  font-size: 11px;
  color: var(--ws-sidebar-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-logout-btn {
  background: none;
  border: none;
  color: var(--ws-sidebar-muted);
  cursor: pointer;
  font-size: 11px;
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 4px;
}
.ws-logout-btn:hover { color: var(--ws-danger); background: rgba(255,255,255,0.06); }

/* Empty State */
.ws-empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--ws-sidebar-muted);
}
.ws-empty-state p { font-size: 12px; margin: 6px 0; }
.ws-empty-state .ws-empty-icon { font-size: 28px; margin-bottom: 8px; }

/* ─── Main Area ────────────────────────────────────────── */
.ws-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: #fff;
}

/* Top Bar (only visible when sidebar collapsed) */
.ws-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
.sidebar-collapsed .ws-topbar { display: flex; }

.ws-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  color: #64748b;
  font-size: 18px;
  line-height: 1;
}
.ws-expand-btn:hover { background: #f1f5f9; color: #1a1a2e; }

.ws-topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a2e;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat Container */
.ws-chat-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ─── Workspace Chat Overrides ─────────────────────────── */
/* Make the embedded chat fill the entire main area */
.ws-chat-container #uchat-panel {
  border-radius: 0 !important;
  box-shadow: none !important;
  border: none !important;
  height: 100% !important;
  max-height: 100% !important;
  width: 100% !important;
  max-width: 100% !important;
  position: relative !important;
  margin: 0 !important;
}
.ws-chat-container #uchat-panel .uchat-header {
  display: none !important;
}
.ws-chat-container #uchat-panel .uchat-body {
  height: calc(100vh - 80px) !important;
  max-height: none !important;
}
.sidebar-collapsed .ws-chat-container #uchat-panel .uchat-body {
  height: calc(100vh - 120px) !important;
}
.ws-chat-container #uchat-panel .uchat-input-area {
  border-radius: 0 !important;
  border-left: none !important;
  border-right: none !important;
  border-bottom: none !important;
}
/* Wider message bubbles in workspace */
.ws-chat-container .uchat-msg-content {
  max-width: 720px !important;
}

/* ─── Email Gate Overlay ───────────────────────────────── */
.ws-email-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.ws-email-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.ws-email-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  color: #1a1a2e;
}
.ws-email-card p {
  margin: 0 0 24px;
  color: #64748b;
  font-size: 14px;
}
.ws-email-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}
.ws-email-input:focus { border-color: var(--ws-accent); }
.ws-email-submit {
  width: 100%;
  padding: 12px;
  background: var(--ws-accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.ws-email-submit:hover { background: var(--ws-accent-light); }
.ws-email-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.ws-email-error {
  color: var(--ws-danger);
  font-size: 12px;
  margin-top: 8px;
  display: none;
}
.ws-email-legal {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 16px;
}
.ws-email-legal a { color: var(--ws-accent); }

/* ─── Attorney Card ───────────────────────────────────── */
.ws-attorney-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--ws-sidebar-border);
  flex-shrink: 0;
}
.ws-attorney-card-photo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.ws-attorney-card-info {
  min-width: 0;
}
.ws-attorney-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--ws-sidebar-text);
}
.ws-attorney-card-bar {
  font-size: 10px;
  color: var(--ws-accent-light);
  text-decoration: none;
}
.ws-attorney-card-bar:hover { text-decoration: underline; }
.ws-attorney-card-services {
  font-size: 10px;
  color: var(--ws-sidebar-muted);
  margin-top: 2px;
}
.ws-attorney-card-cta {
  flex-shrink: 0;
  align-self: center;
  background: #059669;
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.ws-attorney-card-cta:hover { background: #047857; }

/* ─── Rename Dialog ────────────────────────────────────── */
.ws-rename-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
.ws-rename-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 40px -8px rgba(0,0,0,0.2);
}
.ws-rename-card h3 { margin: 0 0 12px; font-size: 16px; }
.ws-rename-input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
}
.ws-rename-input:focus { border-color: var(--ws-accent); }
.ws-rename-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.ws-rename-actions button {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.ws-rename-cancel { background: #f1f5f9; color: #64748b; }
.ws-rename-cancel:hover { background: #e2e8f0; }
.ws-rename-save { background: var(--ws-accent); color: #fff; }
.ws-rename-save:hover { background: var(--ws-accent-light); }

/* ─── Loading States ───────────────────────────────────── */
.ws-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #94a3b8;
  font-size: 13px;
}

/* ─── Mobile ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .ws-layout {
    grid-template-columns: 1fr;
  }

  .ws-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--ws-sidebar-w);
    z-index: 9998;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .ws-layout.sidebar-open .ws-sidebar {
    transform: translateX(0);
  }

  .ws-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9997;
  }
  .ws-layout.sidebar-open .ws-sidebar-backdrop { display: block; }

  /* Always show topbar on mobile */
  .ws-topbar { display: flex !important; }

  /* Collapsed state doesn't matter on mobile */
  .sidebar-collapsed .ws-sidebar {
    width: var(--ws-sidebar-w);
    min-width: var(--ws-sidebar-w);
  }

  .ws-chat-container #uchat-panel .uchat-body {
    height: calc(100vh - 120px) !important;
    height: calc(100dvh - 120px) !important;
  }

  .ws-chat-container .uchat-msg-content {
    max-width: 100% !important;
  }

  .ws-email-card {
    padding: 28px 24px;
    max-width: 320px;
  }
}

/* ─── Keyboard Shortcuts Hint ──────────────────────────── */
.ws-kbd {
  display: inline-block;
  padding: 1px 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  font-size: 10px;
  font-family: monospace;
  color: var(--ws-sidebar-muted);
  border: 1px solid rgba(255,255,255,0.1);
}
