:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --navy: #0f172a;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --good: #059669;
  --good-bg: #ecfdf5;
  --medium: #d97706;
  --medium-bg: #fffbeb;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.2);
}

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

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

code {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.85em;
}

/* Topbar */
.topbar {
  background: var(--navy);
  color: #ffffff;
  padding: 14px 20px;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.topbar-brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.topbar-sub {
  font-size: 0.8rem;
  color: #94a3b8;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.db-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.3);
  padding: 5px 10px;
  border-radius: 999px;
}

/* Tabs */
.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.tabs-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 14px 16px;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-count {
  font-size: 0.75rem;
  background: #f1f5f9;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 999px;
}

.tab-btn.active .tab-count {
  background: #dbeafe;
  color: var(--primary);
}

/* Main */
.admin-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text);
}

.kpi-good .kpi-value { color: var(--good); }
.kpi-muted .kpi-value { color: #64748b; }
.kpi-amber .kpi-value { color: var(--medium); }
.kpi-blue .kpi-value { color: var(--primary); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Inputs & Buttons */
.input {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.search-input {
  min-width: 240px;
}

.select-input {
  min-width: 170px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

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

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

.btn-success {
  background: var(--good);
  color: #ffffff;
}

.btn-success:hover { background: #047857; }

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover { background: var(--surface-alt); border-color: var(--border-strong); }

.btn-outline-light {
  background: transparent;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.35);
}

.btn-outline-light:hover { background: rgba(255, 255, 255, 0.12); }

.btn-danger-outline {
  background: var(--surface);
  color: var(--bad);
  border-color: #fecaca;
}

.btn-danger-outline:hover { background: var(--bad-bg); }

.icon-btn {
  border: none;
  background: #f1f5f9;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.15rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: #e2e8f0; }

/* Panel Card & Table */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.data-table th {
  text-align: left;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr.is-hidden-row {
  background: #fafafa;
  opacity: 0.68;
}

.order-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

.order-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 22px;
}

.order-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.move-btn {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  width: 24px;
  height: 20px;
  border-radius: 5px;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
}

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

.admin-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f1f5f9;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.admin-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.mat-title {
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--text);
}

.mat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.72rem;
}

.pill-brand { background: #eff6ff; color: var(--primary); }
.pill-code { background: #f1f5f9; color: #475569; font-family: ui-monospace, monospace; }
.pill-cat { background: #f3e8ff; color: #6b21a8; }

.mat-desc {
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Toggle Switch */
.switch-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.switch-input {
  appearance: none;
  width: 42px;
  height: 24px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.16s ease;
  flex-shrink: 0;
}

.switch-input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.16s ease;
}

.switch-input:checked {
  background: var(--good);
}

.switch-input.light-switch:checked {
  background: var(--medium);
}

.switch-input:checked::after {
  transform: translateX(18px);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.empty-box {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* Submissions */
.submissions-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sub-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.sub-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sub-user {
  font-size: 1rem;
  font-weight: 800;
}

.sub-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.sub-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.sub-item-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.sub-item-title {
  font-weight: 700;
  font-size: 0.86rem;
  margin-bottom: 6px;
}

.sub-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-tag {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.status-tag.good { background: var(--good-bg); color: #065f46; }
.status-tag.medium { background: var(--medium-bg); color: #92400e; }
.status-tag.bad { background: var(--bad-bg); color: #991b1b; }
.status-tag.qty { background: #e2e8f0; color: #334155; }

.sub-comment {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #475569;
  font-style: italic;
}

.sub-general-comment {
  margin-top: 12px;
  padding: 10px 12px;
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  font-size: 0.84rem;
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
  align-items: start;
}

.settings-card {
  padding: 20px;
}

.settings-card h3 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.card-desc {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
}

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

.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 18px;
}

.toggle-list.compact {
  margin: 6px 0 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.86rem;
  cursor: pointer;
}

.stack-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.db-info-box {
  margin-top: 18px;
  padding: 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  font-size: 0.84rem;
  color: #166534;
}

.db-info-box p {
  margin: 6px 0 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2,
.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-grid .form-group {
  margin-bottom: 0;
}

.span-2 {
  grid-column: span 2;
}

.image-editor-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.image-preview-box {
  width: 112px;
  height: 112px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f1f5f9;
  padding: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-controls {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Zoom Modal */
.zoom-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.zoom-img-wrap {
  padding: 16px;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-img-wrap img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

/* PIN Overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.pin-overlay[hidden] {
  display: none;
}

.pin-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-lg);
}

.pin-icon {
  font-size: 2rem;
}

.pin-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.pin-card p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.pin-error {
  color: var(--bad) !important;
  font-weight: 700;
}

.pin-back-link {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-top: 4px;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--navy);
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 150;
}

.toast.error {
  background: var(--bad);
}

/* Team & Links Generator */
.generator-card {
  padding: 16px 18px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
  border-color: #bfdbfe;
}

.gen-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.gen-field label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--navy);
}

.generator-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-code {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  background: #f1f5f9;
  color: #1e293b;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  text-decoration: none;
}

.link-code:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.pill-role {
  background: #dbeafe;
  color: #1e40af;
}

.pill-role-ft {
  background: #ede9fe;
  color: #5b21b6;
}

.pill-sent {
  background: var(--good-bg);
  color: #065f46;
}

.pill-pending {
  background: var(--medium-bg);
  color: #92400e;
}

.member-sub-date {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .admin-main {
    padding: 14px;
  }
  .search-input,
  .select-input {
    width: 100%;
    min-width: 0;
  }
  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }
  .modal-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
  .image-editor-row {
    flex-direction: column;
  }
}
