/* ============================================================
   Sub Zero Job Board — Design System & Component Styles
   ============================================================
   Font: Inter (Google Fonts)
   Palette: Dark mode, ice-blue accent, Sub Zero brand feel
   ============================================================ */

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

/* ── CSS Custom Properties (Design Tokens) ──────────────────── */
:root {
  /* Background layers */
  --bg-base:        #080c10;
  --bg-surface:     #0d1117;
  --bg-card:        #161b22;
  --bg-card-hover:  #1c2230;
  --bg-elevated:    #1f2937;

  /* Borders */
  --border:         rgba(255,255,255,0.07);
  --border-subtle:  rgba(255,255,255,0.04);
  --border-accent:  rgba(56,189,248,0.3);

  /* Text */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;
  --text-accent:    #38bdf8;

  /* Accent / brand */
  --accent:         #38bdf8;
  --accent-dim:     rgba(56,189,248,0.12);
  --accent-glow:    rgba(56,189,248,0.25);

  /* Semantic colours */
  --aging-red:      #f87171;
  --aging-red-bg:   rgba(248,113,113,0.10);
  --aging-red-border: rgba(248,113,113,0.25);
  --ok-green:       #34d399;
  --ok-green-bg:    rgba(52,211,153,0.10);

  /* Typography */
  --font-family:    'Inter', system-ui, -apple-system, sans-serif;
  --font-size-xs:   0.70rem;
  --font-size-sm:   0.80rem;
  --font-size-base: 0.875rem;
  --font-size-md:   1rem;
  --font-size-lg:   1.125rem;
  --font-size-xl:   1.5rem;
  --font-size-2xl:  2rem;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radii */
  --radius-sm:  4px;
  --radius:     8px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.4);
  --shadow:     0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.6);
  --shadow-accent: 0 0 20px rgba(56,189,248,0.15);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition:        220ms ease;
  --transition-slow:   350ms ease;

  /* Layout */
  --header-height: 64px;
  --content-max:   1280px;
  --sidebar-width: 260px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Subtle grid texture on body */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(56,189,248,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 30% at 100% 100%, rgba(56,189,248,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── App shell ────────────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: rgba(13,17,23,0.85);
  backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-8);
  gap: var(--space-6);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand-name {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.header-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.header-title {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#last-updated {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* Mock data badge */
#mock-data-badge {
  display: none;
  align-items: center;
  gap: var(--space-1);
  background: rgba(245,158,11,0.15);
  border: 1px solid rgba(245,158,11,0.3);
  color: #f59e0b;
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* Refresh button */
#refresh-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  color: var(--text-accent);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

#refresh-btn:hover {
  background: rgba(56,189,248,0.2);
  box-shadow: var(--shadow-accent);
}

#refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#refresh-btn .refresh-icon {
  display: inline-block;
  font-size: 14px;
  transition: transform var(--transition);
}

#refresh-btn.refreshing .refresh-icon {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Main content ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: var(--space-8) var(--space-8) var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

/* ── Section headings ─────────────────────────────────────────── */
.section-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: var(--space-4);
}

/* ── Summary tiles row ────────────────────────────────────────── */
#summary-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
}

.summary-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-5) var(--space-4);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  outline: none;
}

/* Coloured top accent bar */
.summary-tile::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--tile-color, var(--accent));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Subtle glow on hover matching tile color */
.summary-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top left, color-mix(in srgb, var(--tile-color, var(--accent)) 8%, transparent) 0%, transparent 70%);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition);
}

.summary-tile:hover,
.summary-tile:focus-visible {
  background: var(--bg-card-hover);
  border-color: color-mix(in srgb, var(--tile-color, var(--accent)) 30%, transparent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.summary-tile:hover::after { opacity: 1; }

.tile-count {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-bottom: var(--space-2);
}

.tile-label {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: var(--space-3);
}

.tile-aging {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--aging-red);
  background: var(--aging-red-bg);
  border: 1px solid var(--aging-red-border);
  border-radius: var(--radius-full);
  padding: 2px var(--space-2);
  display: inline-block;
  animation: pulse-subtle 2s ease-in-out infinite;
}

.tile-ok {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--ok-green);
  opacity: 0.8;
}

@keyframes pulse-subtle {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.7; }
}

/* ── Job groups ───────────────────────────────────────────────── */
#job-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.job-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.job-group:hover {
  box-shadow: var(--shadow);
}

/* Group header */
.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.group-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.group-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.group-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.group-aging-badge {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--aging-red);
  background: var(--aging-red-bg);
  border: 1px solid var(--aging-red-border);
  border-radius: var(--radius-full);
  padding: 2px var(--space-2);
  white-space: nowrap;
}

.group-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.group-action {
  font-size: var(--font-size-sm);
  color: var(--text-accent);
  font-weight: 500;
}

.group-owner {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.group-owner strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Job list */
.job-list {
  display: flex;
  flex-direction: column;
}

.job-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

.job-row:last-child {
  border-bottom: none;
}

.job-row:hover {
  background: rgba(255,255,255,0.02);
}

.job-row--aging {
  background: var(--aging-red-bg);
  border-left: 3px solid var(--aging-red);
}

.job-row--aging:hover {
  background: rgba(248,113,113,0.14);
}

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

.job-name {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: 2px;
}

.job-customer {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-desc {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-desc::before {
  content: '·';
  margin-right: var(--space-1);
}

.job-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* Aging days pill */
.days-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  padding: 3px 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.days-pill--aging {
  color: var(--aging-red);
  background: var(--aging-red-bg);
  border: 1px solid var(--aging-red-border);
  animation: pulse-subtle 2s ease-in-out infinite;
}

.days-pill--ok {
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
}

.days-pill--unknown {
  color: var(--text-muted);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-subtle);
}

/* Owner avatar */
.owner-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e40af 0%, #0ea5e9 100%);
  color: #fff;
  font-size: var(--font-size-xs);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: default;
  transition: transform var(--transition-fast);
}

.job-row:hover .owner-avatar {
  transform: scale(1.1);
}

/* Open in Simpro link */
.job-link {
  font-size: var(--font-size-md);
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast), transform var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.job-link:hover {
  color: var(--text-accent);
  transform: translate(1px, -1px);
}

/* Group footer */
.group-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  background: rgba(255,255,255,0.01);
  border-top: 1px solid var(--border-subtle);
}

.group-count {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.group-simpro-link {
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-accent);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.group-simpro-link:hover { opacity: 1; }

/* Empty job list */
.job-list-empty {
  padding: var(--space-8) var(--space-6);
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* ── Ask-anything bar ─────────────────────────────────────────── */
.ask-bar-wrapper {
  position: relative;
}

.ask-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-3) var(--space-5);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.ask-bar:focus-within {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.ask-icon {
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

#ask-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  caret-color: var(--accent);
}

#ask-input::placeholder {
  color: var(--text-muted);
}

#ask-input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.ask-badge {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Loading state ────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-12);
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Error state ──────────────────────────────────────────────── */
.error-state {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-8);
  background: var(--aging-red-bg);
  border: 1px solid var(--aging-red-border);
  border-radius: var(--radius-lg);
  color: var(--aging-red);
  font-size: var(--font-size-sm);
}

.error-icon {
  font-size: var(--font-size-lg);
  flex-shrink: 0;
}

/* ── Empty board ──────────────────────────────────────────────── */
.empty-board {
  padding: var(--space-12);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-base);
}

/* ── Footer ───────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-5) var(--space-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.footer-text {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.footer-text a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-text a:hover {
  color: var(--text-accent);
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.14);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .site-header {
    padding: 0 var(--space-4);
    gap: var(--space-3);
  }

  .header-center {
    display: none;
  }

  .main-content {
    padding: var(--space-5) var(--space-4) var(--space-8);
    gap: var(--space-5);
  }

  #summary-tiles {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }

  .group-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-4);
  }

  .group-header-right {
    flex-wrap: wrap;
  }

  .job-row {
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
  }

  .job-right {
    width: 100%;
    justify-content: flex-end;
  }

  .site-footer {
    flex-direction: column;
    text-align: center;
    padding: var(--space-4);
  }
}

@media (max-width: 480px) {
  #summary-tiles {
    grid-template-columns: 1fr 1fr;
  }

  .brand-name {
    display: none;
  }
}
