* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0f1117; color: #e4e4e7; min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

/* ── Nav ── */
.nav { background: #18181b; border-bottom: 1px solid #27272a; padding: 12px 32px; display: flex; align-items: center; gap: 24px; position: sticky; top: 0; z-index: 40; }
.nav .brand { font-size: 18px; font-weight: 600; color: #f4f4f5; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.nav .brand-logo { width: 28px; height: 28px; display: block; flex-shrink: 0; }
.nav .brand span { color: #a855f7; }
.nav .spacer { flex: 1; }
.nav a { color: #a1a1aa; text-decoration: none; font-size: 14px; }
.nav a:hover { color: #e4e4e7; }
.nav .user-info { color: #71717a; font-size: 13px; }

/* ── Header / Stats ── */
.header { background: linear-gradient(135deg, #1a1025 0%, #0f1117 100%); border-bottom: 1px solid #27272a; padding: 20px 32px; }
.header h1 { font-size: 22px; font-weight: 600; color: #f4f4f5; display: flex; align-items: center; gap: 12px; }
.header h1 span { color: #a855f7; }
.header .stats { display: flex; gap: 24px; margin-top: 10px; font-size: 13px; color: #a1a1aa; }
.header .stats .stat-val { font-size: 20px; font-weight: 700; color: #f4f4f5; }
.header .stats .stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Controls ── */
.controls { padding: 16px 32px; background: #18181b; border-bottom: 1px solid #27272a; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.controls input, .controls select { background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7; padding: 8px 12px; border-radius: 6px; font-size: 14px; outline: none; }
.controls input:focus, .controls select:focus { border-color: #a855f7; }
.controls input[type="text"], .controls input[type="search"] { width: 320px; }
.search-wrap { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search-wrap input { width: 100%; }
.suggest-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 50; background: #18181b; border: 1px solid #3f3f46; border-radius: 8px; margin-top: 4px; list-style: none; max-height: 280px; overflow: auto; box-shadow: 0 12px 32px rgba(0,0,0,.45); }
.suggest-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: #f4f4f5; padding: 12px 14px; font-size: 15px; min-height: 44px; }
.suggest-item:hover, .suggest-item:focus { background: #27272a; color: #a855f7; }
.org-link { color: #c084fc; text-decoration: none; }
.org-link:hover { text-decoration: underline; }
.controls select { min-width: 140px; }
.btn { background: #a855f7; color: white; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; text-decoration: none; display: inline-block; }
.btn:hover { background: #9333ea; }
.btn.secondary { background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7; }
.btn.secondary:hover { background: #3f3f46; }
.btn-danger { background: #dc2626 !important; color: white !important; }
.btn-danger:hover { background: #b91c1c !important; }
.btn-success { background: #16a34a !important; color: white !important; }
.btn-success:hover { background: #15803d !important; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.result-count { font-size: 13px; color: #71717a; margin-left: auto; }

/* ── Review queues ── */
.queue-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 32px 0; background: #18181b; }
.queue-chip { background: #27272a; border: 1px solid #3f3f46; color: #a1a1aa; padding: 5px 12px; border-radius: 999px; font-size: 12px; text-decoration: none; }
.queue-chip:hover { color: #e4e4e7; border-color: #71717a; }
.queue-chip.active { background: #3b0764; border-color: #a855f7; color: #f4f4f5; }

/* ── Upload ── */
.upload-wrap { max-width: 720px; margin: 32px auto; padding: 0 24px 48px; }
.upload-wrap h1 { font-size: 22px; margin-bottom: 8px; }
.upload-wrap p.lead { color: #a1a1aa; margin-bottom: 24px; font-size: 14px; }
.upload-wrap label { display: block; color: #a1a1aa; font-size: 13px; margin-bottom: 4px; }
.upload-wrap input[type="text"], .upload-wrap select, .upload-wrap input[type="file"] {
  width: 100%; background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7;
  padding: 10px 12px; border-radius: 6px; font-size: 14px; outline: none; margin-bottom: 16px;
}
.upload-wrap .check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; color: #d4d4d8; font-size: 14px; }
.upload-wrap .check input { width: auto; margin: 0; }
.preview-list { background: #18181b; border: 1px solid #27272a; border-radius: 8px; padding: 16px; margin: 16px 0; max-height: 360px; overflow: auto; }
.preview-list li { font-size: 13px; padding: 4px 0; border-bottom: 1px solid #27272a; }
.upload-meta { color: #71717a; font-size: 13px; margin-bottom: 12px; }
.mail-card { background: #18181b; border: 1px solid #27272a; border-radius: 8px; padding: 16px; margin: 16px 0 20px; }
.mail-row { color: #e4e4e7; font-size: 14px; margin-bottom: 8px; }
.mail-row span { display: inline-block; width: 72px; color: #71717a; font-size: 12px; text-transform: uppercase; }
.upload-wrap textarea { width: 100%; background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7; padding: 10px 12px; border-radius: 6px; font-size: 14px; outline: none; margin: 8px 0 0; resize: vertical; }

@media (max-width: 720px) {
  .nav { padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
  .nav .user-info { display: none; }
  .header { padding: 14px 12px; }
  .header h1 { font-size: 17px; flex-wrap: wrap; }
  .header .stats { gap: 16px; }
  .controls, .table-wrap, .queue-bar { padding-left: 12px; padding-right: 12px; }
  .controls { flex-direction: column; align-items: stretch; }
  .controls input[type="text"], .controls input[type="search"], .controls select, .search-wrap { width: 100%; max-width: none; }
  .result-count { margin-left: 0; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  table { margin-top: 8px; }
  tbody tr { background: #18181b; border: 1px solid #27272a; border-radius: 10px; margin-bottom: 10px; padding: 8px 12px; }
  tbody tr:hover { background: #1c1c24; }
  td { max-width: none; white-space: normal; padding: 6px 0; display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid #27272a; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: #71717a; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; flex: 0 0 42%; }
  td.producer-name { font-size: 16px; }
  td.editing-cell, td.edit-cell { flex-direction: column; align-items: stretch; }
  td.rating-cell {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    white-space: normal;
    padding: 10px 0;
    min-height: 52px;
  }
  td.rating-cell::before { flex: none; width: auto; }
  .stars.interactive { width: 100%; max-width: 280px; justify-content: space-between; }
  .stars.interactive .star { width: 44px; height: 44px; }
  .stars.interactive .star svg { width: 26px; height: 26px; }
  .stars.avg { flex-wrap: wrap; }
  .stars.avg .star { width: 28px; height: 28px; }
  .stars.avg .star svg { width: 20px; height: 20px; }
  .avg-num { font-size: 14px; }
  .controls input, .controls select, .controls .btn {
    min-height: 44px;
    font-size: 16px;
  }
  .cell-input { min-height: 40px; }
}

/* ── Table ── */
.table-wrap { overflow-x: auto; padding: 0 32px 32px; }
table { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 13px; }
thead th { background: #18181b; color: #a1a1aa; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; font-weight: 600; padding: 10px 12px; text-align: left; border-bottom: 1px solid #27272a; position: sticky; top: 0; cursor: pointer; user-select: none; }
thead th:hover { color: #e4e4e7; }
thead th.sorted { color: #a855f7; }
tbody tr { border-bottom: 1px solid #1e1e22; }
tbody tr:hover { background: #1c1c24; }
td { padding: 10px 12px; vertical-align: top; max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.producer-name { font-weight: 500; color: #f4f4f5; white-space: normal; }
td.geo-id-cell { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; color: #e9d5ff; letter-spacing: 0.3px; min-width: 96px; overflow: visible; }
td.edit-cell { white-space: normal; overflow: visible; max-width: 140px; }
td.editing-cell { overflow: visible; white-space: normal; max-width: none; }
tr.editing td { white-space: normal; overflow: visible; }
.cell-input { width: 100%; min-width: 72px; background: #27272a; border: 1px solid #a855f7; color: #e4e4e7; padding: 6px 8px; border-radius: 6px; font-size: 13px; outline: none; }
.edit-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.edit-error { color: #f87171; font-size: 12px; margin-top: 6px; }
.org-edit-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 16px; }
.org-edit-bar .edit-error { margin-top: 0; }
.org-name-input { font-size: 24px; width: 100%; background: #27272a; border: 1px solid #a855f7; color: #f4f4f5; padding: 6px 10px; border-radius: 8px; margin-bottom: 8px; outline: none; }
.org-field-input { width: 100%; background: #27272a; border: 1px solid #3f3f46; color: #f4f4f5; padding: 6px 8px; border-radius: 6px; font-size: 15px; outline: none; }
.org-field-input:focus, .org-name-input:focus, .cell-input:focus { border-color: #c084fc; }
td .badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }
td .badge-high { background: #14532d; color: #4ade80; }
td .badge-medium { background: #422006; color: #fb923c; }
td .badge-low { background: #450a0a; color: #f87171; }
td.rating-cell { overflow: visible; max-width: none; white-space: nowrap; vertical-align: middle; }
.stars { display: inline-flex; align-items: center; gap: 0; }
.star {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: 0;
  padding: 4px;
  margin: 0;
  cursor: pointer;
  color: #a855f7;
  line-height: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.star svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linejoin: round;
  pointer-events: none;
}
.star.filled svg { fill: currentColor; }
@media (hover: hover) {
  .stars.interactive:hover .star svg { fill: none; }
  .stars.interactive:hover .star:hover svg,
  .stars.interactive:hover .star:has(~ .star:hover) svg { fill: currentColor; }
}
.stars.avg .star {
  cursor: default;
  pointer-events: none;
  width: 22px;
  height: 22px;
  padding: 2px;
}
.stars.avg .star svg { width: 16px; height: 16px; }
.avg-num { color: #a1a1aa; font-size: 12px; margin-left: 6px; }
.avg-empty { color: #71717a; }

@media (max-width: 720px) {
  td { max-width: none; overflow: visible; white-space: normal; }
  td.rating-cell {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    white-space: normal;
    padding: 10px 0;
    min-height: 52px;
  }
  td.rating-cell::before { flex: none; width: auto; }
  .stars.interactive { width: 100%; max-width: 280px; justify-content: space-between; }
  .stars.interactive .star { width: 44px; height: 44px; }
  .stars.interactive .star svg { width: 26px; height: 26px; }
  .stars.avg { flex-wrap: wrap; }
  .stars.avg .star { width: 28px; height: 28px; }
  .stars.avg .star svg { width: 20px; height: 20px; }
  .avg-num { font-size: 14px; }
}

/* ── Pagination ── */
.pagination { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: #18181b; border-top: 1px solid #27272a; }
.pagination[hidden] { display: none !important; }
.pagination a, .pagination span { background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7; padding: 12px 20px; border-radius: 8px; font-size: 15px; text-decoration: none; min-width: 72px; text-align: center; min-height: 44px; }
.pagination a:hover { background: #3f3f46; }
.pagination .disabled { opacity: 0.3; pointer-events: none; }
.pagination .current { background: #a855f7; border-color: #a855f7; min-width: 96px; }

/* ── Flash messages ── */
.flash { padding: 10px 32px; font-size: 14px; }
.flash-error { background: #450a0a; color: #f87171; }
.flash-warning { background: #422006; color: #fb923c; }
.flash-success { background: #14532d; color: #4ade80; }
.flash-info { background: #172554; color: #60a5fa; }

/* ── Login ── */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.login-box { background: #18181b; border: 1px solid #27272a; border-radius: 12px; padding: 40px; width: 380px; }
.login-box h1 { font-size: 24px; color: #f4f4f5; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.login-box h1 span { color: #a855f7; }
.login-logo { width: 40px; height: 40px; display: block; flex-shrink: 0; }
.login-box p { color: #71717a; font-size: 14px; margin-bottom: 24px; }
.login-box label { display: block; color: #a1a1aa; font-size: 13px; margin-bottom: 4px; }
.login-box input { width: 100%; background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7; padding: 10px 12px; border-radius: 6px; font-size: 14px; outline: none; margin-bottom: 16px; }
.login-box input:focus { border-color: #a855f7; }
.login-box button { width: 100%; }

/* ── Admin panel ── */
.admin-header { padding: 20px 32px; border-bottom: 1px solid #27272a; }
.admin-header h2 { color: #f4f4f5; font-size: 20px; }
.admin-create { background: #18181b; padding: 20px 32px; border-bottom: 1px solid #27272a; display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.admin-create .field { display: flex; flex-direction: column; gap: 4px; }
.admin-create label { color: #a1a1aa; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.admin-create input, .admin-create select { background: #27272a; border: 1px solid #3f3f46; color: #e4e4e7; padding: 8px 12px; border-radius: 6px; font-size: 14px; outline: none; }
.admin-create input:focus, .admin-create select:focus { border-color: #a855f7; }
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.status-active { background: #14532d; color: #4ade80; }
.status-disabled { background: #450a0a; color: #f87171; }
.status-online { background: #172554; color: #60a5fa; }

/* ── Org / contact page ── */
.org-page { max-width: 720px; margin: 0 auto; padding: 20px 16px 32px; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; color: #c084fc; text-decoration: none; font-size: 16px; font-weight: 500; margin-bottom: 12px; }
.back-link:hover { text-decoration: underline; color: #e9d5ff; }
.back-link-bottom { margin-top: 20px; margin-bottom: 8px; }
.org-kicker { color: #a855f7; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.org-page h1 { font-size: 24px; margin-bottom: 8px; }
.org-page .lead { color: #a1a1aa; font-size: 14px; margin-bottom: 20px; }
.org-page h2 { font-size: 16px; margin: 24px 0 10px; color: #e4e4e7; }
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.contact-card { background: #18181b; border: 1px solid #27272a; border-radius: 10px; padding: 12px 14px; }
.contact-card span { display: block; color: #71717a; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.contact-card strong { color: #f4f4f5; font-size: 15px; word-break: break-word; }
.contact-card a { color: #c084fc; }
.org-producers { list-style: none; }
.org-producers li { padding: 12px 0; border-bottom: 1px solid #27272a; display: flex; flex-direction: column; gap: 2px; }
.org-producers a { color: #f4f4f5; text-decoration: none; font-weight: 500; }
.org-producers span { color: #71717a; font-size: 13px; }
.org-producers .empty { color: #71717a; }
@media (max-width: 720px) {
  .contact-grid { grid-template-columns: 1fr; }
  .nav { padding-top: calc(10px + env(safe-area-inset-top)); }
  .nav a { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 4px; }
  .queue-chip { min-height: 44px; display: inline-flex; align-items: center; padding: 10px 14px; }
  td.geo-id-cell { overflow: visible; white-space: nowrap; color: #e9d5ff; font-size: 15px; }
  .edit-actions .btn { min-height: 44px; padding: 10px 14px; font-size: 15px; }
  .flash { padding: 10px 12px; }
  .login-wrap { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .login-box { width: 100%; max-width: 380px; padding: 24px 16px; }
  .login-box input, .login-box button, .admin-create input, .admin-create select, .upload-wrap input, .upload-wrap select, .upload-wrap textarea {
    min-height: 44px;
    font-size: 16px;
  }
  .admin-header, .admin-create { padding-left: 12px; padding-right: 12px; }
  .admin-create { flex-direction: column; align-items: stretch; }
}
.status-offline { color: #52525b; }
