:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --panel: #ffffff;
  --bg: #f8fafc;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent2: #f5f3ff;
  --danger: #ef4444;
  --success: #10b981;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font: 14px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font: inherit;
  touch-action: manipulation;
}

/* ====================================================================
   SHELL & DESKTOP SIDEBAR
   ==================================================================== */
.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 24px 18px 20px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.03em;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  text-decoration: none;
}

.brand-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 2px;
}

.nav {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-heading {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  padding: 14px 10px 4px;
}

.nav a {
  padding: 8px 12px;
  border-radius: 8px;
  color: #475569;
  font-weight: 500;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
  text-decoration: none;
}

.nav a:hover {
  background: #f1f5f9;
  color: var(--ink);
}

.nav a.active {
  background: #f1f5f9;
  color: var(--ink);
  font-weight: 600;
}

.nav a .badge {
  margin-left: auto;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #64748b;
  transition: color 0.15s ease;
}

.nav a:hover .nav-icon,
.nav a.active .nav-icon {
  color: var(--ink);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.user-email {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile-only elements hidden on desktop */
.mobile-topbar {
  display: none;
}

.mobile-bottom-nav {
  display: none;
}

.mobile-drawer-backdrop {
  display: none;
}

.mobile-drawer {
  display: none;
}

/* ====================================================================
   MAIN LAYOUT & TYPOGRAPHY
   ==================================================================== */
.main {
  padding: 32px 40px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

.topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.title {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
  color: var(--ink);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 3px 0;
}

.muted {
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.grid > * {
  min-width: 0;
  max-width: 100%;
}

.product-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  border-color: #cbd5e1;
}

.product-card-title {
  margin: 14px 0 4px;
  font-size: 18px;
  font-weight: 750;
  line-height: 1.3;
  color: var(--ink);
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
  max-width: 100%;
}

.product-card-url {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 100%;
  display: block;
  margin: 0;
}

/* Product filter form styling */
.product-filter-form {
  margin-bottom: 20px;
  padding: 14px 16px;
  min-width: 0;
  max-width: 100%;
}

.product-filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  min-width: 0;
}

.product-filter-search {
  flex: 2;
  min-width: 180px;
}

.product-filter-actions {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 220px;
  align-items: center;
}

.product-filter-select {
  flex: 1;
  min-width: 120px;
}

.product-filter-btn {
  min-width: 84px;
  flex-shrink: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.spread {
  justify-content: space-between;
}

.stack {
  display: grid;
  gap: 14px;
}

/* ====================================================================
   BUTTONS & BADGES
   ==================================================================== */
.btn {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 7px 14px;
  background: #ffffff;
  color: #1e293b;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  text-decoration: none;
}

.btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.btn.primary:hover {
  background: #1e293b;
  border-color: #1e293b;
}

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

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

.btn.small {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #475569;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.badge.ACTIVE, .badge.DONE, .badge.COMPLETED {
  background: #dcfce7;
  color: #15803d;
}

.badge.CHANGES_REQUESTED, .badge.HIGH, .badge.CRITICAL {
  background: #fee2e2;
  color: #b91c1c;
}

.badge.IN_PROGRESS, .badge.IN_REVIEW {
  background: #e0e7ff;
  color: #4338ca;
}

.badge.MEDIUM {
  background: #fef3c7;
  color: #b45309;
}

.badge.LOW, .badge.TODO, .badge.DRAFT {
  background: #f1f5f9;
  color: #475569;
}

.badge.ARCHIVED, .badge.CLOSED, .badge.REJECTED {
  background: #f1f5f9;
  color: #64748b;
}

.metrics {
  display: flex;
  gap: 20px;
  margin-top: 14px;
}

.metric strong {
  display: block;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
}

/* ====================================================================
   FORMS & INPUTS
   ==================================================================== */
.form {
  max-width: 640px;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  font-weight: 600;
  font-size: 12.5px;
  color: #334155;
}

.input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  padding: 8px 12px;
  outline: none;
  font-size: 13.5px;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

textarea.input {
  min-height: 100px;
  resize: vertical;
}

.flash, .errors {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 13.5px;
}

.flash {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.errors {
  background: #fff1f2;
  color: #9f1239;
  border: 1px solid #fecdd3;
}

/* ====================================================================
   TABLES
   ==================================================================== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: #f8fafc;
  font-weight: 650;
}

tr:last-child td {
  border: 0;
}

tr:hover td {
  background: #fcfcfd;
}

.section {
  margin-top: 28px;
}

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}

/* ====================================================================
   GUEST PAGES (LOGIN / 2FA)
   ==================================================================== */
.guest {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px 16px;
  background: radial-gradient(circle at 50% 0, #ede9fe, transparent 50%), var(--bg);
}

.guest-card {
  width: 100%;
  max-width: 420px;
  padding: 30px 24px;
}

.code {
  font-size: 26px;
  letter-spacing: 0.25em;
  text-align: center;
  font-weight: 700;
}

/* ====================================================================
   REVIEW & CAPTURE
   ==================================================================== */
.review-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 54px 1fr;
  background: #0f172a;
  overflow: hidden;
}

.review-bar {
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  z-index: 10;
  gap: 12px;
}

.review-stage {
  position: relative;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.review-frame {
  border: 0;
  width: 100%;
  height: 100%;
  background: #ffffff;
}

.review-panel {
  width: 380px;
  max-width: 90vw;
  background: #ffffff;
  border-left: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
  display: none;
  z-index: 30;
}

.review-panel.open {
  display: block;
}

.capture-status {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: rgba(15, 23, 42, 0.9);
  color: #ffffff;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 15;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 8px 12px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
  color: #334155;
  border: 1px solid #e2e8f0;
}

.sheet-drag-handle {
  width: 36px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 999px;
  margin: 0 auto 10px;
  display: block;
}

/* ====================================================================
   RESPONSIVE DESIGN (MOBILE ADAPTATION <= 800px)
   ==================================================================== */
@media (max-width: 800px) {
  .shell {
    display: block;
    padding-top: calc(54px + var(--safe-top));
    padding-bottom: calc(56px + var(--safe-bottom));
  }

  .sidebar {
    display: none;
  }

  /* Mobile Topbar */
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(54px + var(--safe-top));
    padding-top: var(--safe-top);
    padding-left: 16px;
    padding-right: 16px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    z-index: 40;
  }

  /* Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(54px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    z-index: 40;
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 10px;
    font-weight: 550;
    gap: 2px;
    padding: 6px 12px;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    text-decoration: none;
  }

  .mobile-bottom-nav a.active,
  .mobile-bottom-nav a:active {
    color: var(--accent);
  }

  .mobile-bottom-nav .nav-icon {
    width: 18px;
    height: 18px;
  }

  .mobile-bottom-nav .badge-dot {
    position: absolute;
    top: 4px;
    right: 14px;
    background: #ef4444;
    color: #ffffff;
    font-size: 9px;
    font-weight: 700;
    border-radius: 9999px;
    padding: 1px 4px;
    min-width: 14px;
    text-align: center;
  }

  /* Mobile Drawer */
  .mobile-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 50;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .mobile-drawer-backdrop.open {
    display: block;
    opacity: 1;
  }

  .mobile-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    width: 280px;
    max-width: 85vw;
    background: #ffffff;
    z-index: 60;
    padding: calc(18px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .mobile-drawer.open {
    transform: translateX(0);
  }

  .mobile-drawer .nav {
    margin-top: 16px;
    overflow-y: auto;
  }

  .main {
    padding: 20px 16px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    min-width: 0;
  }

  .topline {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .topline > .row {
    width: 100%;
    justify-content: flex-start;
  }

  .topline > .btn {
    width: 100%;
  }

  .title {
    font-size: 22px;
  }

  .grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    min-width: 0;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  .input, select.input, textarea.input, input, select {
    font-size: 16px !important;
  }

  /* Mobile responsive filter form */
  .product-filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .product-filter-search {
    width: 100%;
    min-width: 0;
    flex: none;
  }

  .product-filter-actions {
    width: 100%;
    min-width: 0;
    display: flex;
    gap: 8px;
  }

  .product-filter-select {
    flex: 1;
    min-width: 0;
  }

  .product-filter-btn {
    flex-shrink: 0;
    min-width: 80px;
  }

  .review-shell {
    grid-template-rows: auto 1fr;
  }

  .review-bar {
    padding: 8px 12px;
    flex-wrap: wrap;
    height: auto;
    min-height: 50px;
    gap: 8px;
  }

  .review-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-width: 100vw;
    max-height: 80vh;
    border-radius: 16px 16px 0 0;
    border-top: 2px solid var(--accent);
    border-left: 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
    z-index: 100;
    padding: 16px 16px calc(20px + var(--safe-bottom));
  }
}
