:root {
  --brand: #b8763e;
  --brand-dark: #1a1a1a;
  --bg: #faf9f7;
  --card: #ffffff;
  --border: #e7e2db;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --danger: #c0392b;
  --success: #2e7d32;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.navbar .brand { font-weight: 700; font-size: 18px; }
.navbar .brand span { color: var(--brand); }

.btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-align: center;
}
.btn-primary { background: var(--brand-dark); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-block { width: 100%; }

.hero {
  text-align: center;
  padding: 70px 20px 50px;
}
.hero .tag {
  display: inline-block;
  background: #f3e9dd;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(28px, 5vw, 46px);
  margin: 0 0 18px;
  font-weight: 800;
}
.hero h1 .accent { color: var(--brand); }
.hero p {
  max-width: 640px;
  margin: 0 auto 30px;
  color: var(--muted);
  font-size: 17px;
}
.hero .cta-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-page {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 16px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px;
  width: 100%;
  max-width: 420px;
}
.auth-card h2 { margin-top: 0; }
.field { margin-bottom: 16px; }
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.auth-card .footer-link {
  text-align: center;
  margin-top: 18px;
  font-size: 14px;
  color: var(--muted);
}
.error-box {
  background: #fdecea;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}
.success-box {
  background: #eaf6ec;
  color: var(--success);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-wrap: wrap;
  gap: 10px;
}

.trial-banner {
  background: #fff6ea;
  border: 1px solid #f0dcb8;
  border-radius: 10px;
  padding: 14px 18px;
  margin: 20px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.card .big { font-size: 26px; font-weight: 700; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
  font-size: 14px;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-active { background: #eaf6ec; color: var(--success); }
.badge-suspended { background: #fdecea; color: var(--danger); }
.badge-trial { background: #f3e9dd; color: var(--brand); }

textarea {
  width: 100%;
  min-height: 90px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}

.section-title { margin: 30px 0 14px; font-size: 18px; }

.inline-form { display: inline; }

/* Dashboard shell: left sidebar + main content */
.dash-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  width: 100%;
}

.dash-sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.dash-sidebar .sidebar-brand {
  font-weight: 700;
  font-size: 16px;
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.dash-sidebar .sidebar-brand span { color: var(--brand); }

.sidebar-nav { display: flex; flex-direction: column; }

.sidebar-group { display: flex; flex-direction: column; }
.sidebar-group:first-child .sidebar-group-label { padding-top: 4px; }

.sidebar-group-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 20px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.sidebar-group-chevron {
  font-size: 10px;
  transition: transform 0.15s ease;
}
.sidebar-group.open .sidebar-group-chevron { transform: rotate(180deg); }

.sidebar-group-items {
  display: flex;
  flex-direction: column;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}
.sidebar-group.open .sidebar-group-items { max-height: 500px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.sidebar-link:hover { background: var(--bg); }
.sidebar-link.active {
  background: var(--bg);
  border-left-color: var(--brand);
  color: var(--brand-dark);
}
.sidebar-link .soon {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 999px;
}
.sidebar-link.disabled {
  cursor: default;
  color: var(--muted);
}
.sidebar-link.disabled:hover { background: none; }

.dash-main {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 16px;
  cursor: pointer;
}

.sidebar-backdrop { display: none; }

@media (max-width: 640px) {
  .dash-header { flex-direction: column; align-items: flex-start; }
  .dash-header > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .container { padding: 0 14px; }
  .hero { padding: 44px 14px 34px; }
  .hero .cta-row { flex-direction: column; align-items: stretch; }
  .card { padding: 16px; }
  .navbar { padding: 14px; flex-wrap: wrap; gap: 8px; }
  th, td { padding: 8px 10px; font-size: 13px; }
  .auth-card { padding: 24px 20px; }
}

@media (max-width: 900px) {
  .sidebar-toggle { display: inline-block; }

  .dash-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
  }
  .dash-sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 30;
  }
  .sidebar-backdrop.open { display: block; }
}

/* Scan modal — the camera/manual scan popup on /app/scan */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--card);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 4px;
}

.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1 1 auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }

.scan-counts-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.scan-counts-row .mini-stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  text-align: center;
}
.scan-counts-row .mini-stat .n { font-size: 18px; font-weight: 700; }
.scan-counts-row .mini-stat .l { font-size: 11px; color: var(--muted); }

.camera-preview-area {
  display: none;
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  margin-bottom: 12px;
}
.camera-preview-area video {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
}
.camera-status-text {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  background: rgba(0,0,0,0.45);
  border-radius: 6px;
  padding: 4px 8px;
}

.scan-status-line {
  min-height: 20px;
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0;
}
.scan-status-line.ok { color: var(--success); }
.scan-status-line.err { color: var(--danger); }
.scan-status-line.warn { color: #b8860b; }

.scan-log-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.scan-log-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.scan-log-row:last-child { border-bottom: none; }
