/* ============================================================
   HQ Agent — Application Shell Styles
   Responsive layout: expandable sidebar + main content area
   ============================================================ */

/* Ensure CSS display rules never override the HTML hidden attribute */
[hidden] {
  display: none !important;
}

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

:root {
  /* Brand tokens */
  --color-primary: #1a56db;
  --color-primary-hover: #1e40af;
  --color-primary-light: #eff6ff;

  /* Neutrals */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-border-subtle: #f1f5f9;

  /* Text */
  --color-text-primary: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;

  /* Sidebar */
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #64748b;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --sidebar-active-text: #ffffff;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);

  /* Topbar */
  --topbar-height: 56px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

  /* Typography */
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

html,
body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-primary);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* --- App Layout -------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar ----------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition:
    width var(--transition-slow),
    transform var(--transition-slow);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* Sidebar header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  min-height: var(--topbar-height);
  flex-shrink: 0;
}

.sidebar-logo-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
  overflow: hidden;
}

/* Landing view */
.landing-module:not([hidden]) {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.landing-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.landing-logo {
  width: 480px;
  max-width: 80vw;
  height: auto;
  border-radius: var(--radius-md);
}

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

.logo-text {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  opacity: 1;
  transition: opacity var(--transition-slow);
}

.sidebar.collapsed .logo-text {
  opacity: 0;
  pointer-events: none;
}

/* Toggle button */
.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--sidebar-text);
  border-radius: 2px;
  transition:
    transform var(--transition-base),
    opacity var(--transition-base);
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.nav-list {
  list-style: none;
}

.nav-item {
  margin: var(--space-1) var(--space-2);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  text-decoration: none;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
  white-space: nowrap;
  position: relative;
}

.nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: #fff;
}

.nav-item.active .nav-link {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-item.coming-soon .nav-link {
  opacity: 0.5;
  cursor: not-allowed;
}

.nav-item.coming-soon .nav-link:hover {
  background: none;
  color: var(--sidebar-text);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-label {
  font-size: 13.5px;
  font-weight: 500;
  opacity: 1;
  transition: opacity var(--transition-slow);
}

.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge {
  opacity: 0;
  pointer-events: none;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text-muted);
  padding: 2px 6px;
  border-radius: 20px;
}

/* Tooltip for collapsed state */
.sidebar.collapsed .nav-item {
  position: relative;
}

/* Sidebar footer */
.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.sidebar-version {
  font-size: 11px;
  color: var(--sidebar-text-muted);
  white-space: nowrap;
  overflow: hidden;
}

/* --- Main Content ------------------------------------------ */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-slow);
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* --- Topbar ------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
}

.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  transition: background var(--transition-fast);
}

.topbar-menu-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.topbar-menu-btn:hover {
  background: var(--color-border-subtle);
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13.5px;
}

.breadcrumb-root {
  color: var(--color-text-muted);
  font-weight: 500;
}

.breadcrumb-sep {
  color: var(--color-text-muted);
}

.breadcrumb-current {
  color: var(--color-text-primary);
  font-weight: 600;
}

/* --- Page Content ------------------------------------------ */
.page-content {
  flex: 1;
  padding: var(--space-8) var(--space-8);
  max-width: 960px;
  width: 100%;
}

/* --- Module Header ----------------------------------------- */
.module-header {
  margin-bottom: var(--space-8);
}

.module-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.module-subtitle {
  color: var(--color-text-secondary);
  font-size: 14.5px;
}

/* --- Empty State ------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-12) var(--space-8);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.empty-icon {
  width: 64px;
  height: 64px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.empty-icon svg {
  width: 100%;
  height: 100%;
}

.empty-state h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-3);
}

.empty-state p {
  color: var(--color-text-secondary);
  max-width: 380px;
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

.coming-soon-note {
  margin-top: var(--space-3);
  font-size: 12px;
  color: var(--color-text-muted);
}

/* --- Auth Gate (Login Screen) ------------------------------ */
.auth-gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  background: var(--sidebar-bg);
}

.signin-logo {
  width: 320px;
  max-width: 80vw;
  height: auto;
  border-radius: var(--radius-md);
}

.login-btn {
  min-width: 160px;
}

.auth-error {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  color: #dc2626;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

/* --- Topbar User Widget ------------------------------------ */
.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-user-name {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    opacity var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-border-subtle);
  color: var(--color-text-primary);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: 12.5px;
}

/* --- Contracts Module -------------------------------------- */
.contracts-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-12) var(--space-8);
  background: var(--color-surface);
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-lg);
  gap: var(--space-3);
}

.contracts-empty-icon {
  width: 44px;
  height: 44px;
  color: var(--color-text-muted);
}

.contracts-empty-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.contracts-empty-text {
  font-size: 12.5px;
  color: var(--color-text-muted);
  max-width: 280px;
  line-height: 1.5;
}

.contracts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-6);
}

/* --- Dropzone ---------------------------------------------- */
#contractsUpload {
  margin-bottom: var(--space-6);
}

.dropzone-full {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-8);
  text-align: center;
  background: var(--color-border-subtle);
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    background var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  user-select: none;
}

.dropzone-full:hover,
.dropzone-full.drag-active {
  border-color: var(--color-primary);
  background: #eff6ff;
}

.dropzone-full.dropzone-uploading {
  opacity: 0.6;
  pointer-events: none;
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  color: var(--color-text-muted);
  transition: color var(--transition-fast);
}

.dropzone-full:hover .dropzone-icon,
.dropzone-full.drag-active .dropzone-icon {
  color: var(--color-primary);
}

.dropzone-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.dropzone-subtext {
  font-size: 13px;
  color: var(--color-text-muted);
}

.dropzone-types {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: center;
}

.dropzone-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--color-border);
  color: var(--color-text-secondary);
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}

.upload-progress {
  margin-top: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.upload-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  width: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  animation: progress-indeterminate 1.4s ease-in-out infinite;
  transform-origin: left;
}

@keyframes progress-indeterminate {
  0% {
    transform: translateX(-100%) scaleX(0.4);
  }
  50% {
    transform: translateX(60%) scaleX(0.6);
  }
  100% {
    transform: translateX(200%) scaleX(0.4);
  }
}

.upload-progress-label {
  font-size: 12.5px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.upload-error {
  margin-top: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
}

.upload-error-text {
  flex: 1;
  font-size: 13px;
  color: #dc2626;
}

/* --- Contract Cards ---------------------------------------- */
.contract-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.contract-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.contract-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-primary);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.contract-card:hover::before {
  opacity: 1;
}

.contract-card-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.contract-card-icon {
  width: 36px;
  height: 36px;
  background: var(--color-border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.contract-card-icon svg {
  width: 18px;
  height: 18px;
}

.contract-card-info {
  flex: 1;
  min-width: 0;
}

.contract-card-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.contract-card-meta {
  font-size: 11.5px;
  color: var(--color-text-muted);
}

/* --- Status Badges ----------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-processing {
  background: #fef3c7;
  color: #b45309;
}

.badge-processing .badge-dot {
  background: #d97706;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.badge-success {
  background: #dcfce7;
  color: #15803d;
}

.badge-success .badge-dot {
  background: #16a34a;
}

.badge-error {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-error .badge-dot {
  background: #dc2626;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

/* --- Auth Test Module -------------------------------------- */
.auth-test-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 480px;
}

.auth-test-description {
  color: var(--color-text-secondary);
  font-size: 13.5px;
  line-height: 1.6;
  margin-bottom: var(--space-5);
}

.auth-test-description code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--color-border-subtle);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
}

.auth-test-actions {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.auth-test-result {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  white-space: pre-wrap;
}

.auth-test-loading {
  background: var(--color-border-subtle);
  color: var(--color-text-muted);
}

.auth-test-allowed {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.auth-test-denied {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.auth-test-error {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

/* --- Mobile Overlay ---------------------------------------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

/* ============================================================
   Responsive — Tablet & Mobile
   ============================================================ */

/* Tablet: collapse sidebar by default */
@media (max-width: 1024px) {
  .sidebar {
    width: var(--sidebar-collapsed-width);
  }

  .sidebar .logo-text,
  .sidebar .nav-label,
  .sidebar .nav-badge {
    opacity: 0;
    pointer-events: none;
  }

  .main-content {
    margin-left: var(--sidebar-collapsed-width);
  }

  .sidebar.expanded {
    width: var(--sidebar-width);
  }

  .sidebar.expanded .logo-text,
  .sidebar.expanded .nav-label,
  .sidebar.expanded .nav-badge {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Mobile: sidebar as drawer */
@media (max-width: 640px) {
  .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Restore text visibility when drawer is open — tablet breakpoint hides it */
  .sidebar.open .logo-text,
  .sidebar.open .nav-label,
  .sidebar.open .nav-badge {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }

  .main-content {
    margin-left: 0;
  }

  .topbar-menu-btn {
    display: flex;
  }

  .sidebar-toggle {
    display: none;
  }

  .page-content {
    padding: var(--space-5) var(--space-5);
  }
}
