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

:root {
  --sidebar-w: 220px;
  --primary:   #2563eb;
  --success:   #16a34a;
  --danger:    #dc2626;
  --gray-100:  #f3f4f6;
  --gray-200:  #e5e7eb;
  --gray-500:  #6b7280;
  --gray-700:  #374151;
  --gray-900:  #111827;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.12);
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}
.sidebar-logo {
  padding: 20px 16px 12px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .5px;
}
.sidebar-nav {
  list-style: none;
  flex: 1;
  overflow-y: auto;
}
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #94a3b8;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.sidebar-nav li a:hover { background: #334155; color: #fff; }
.sidebar-nav li.active a { background: #1d4ed8; color: #fff; border-left-color: #60a5fa; }
.nav-section {
  padding: 14px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #475569;
  text-transform: uppercase;
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #334155;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #94a3b8;
}
.sidebar-footer a { color: #60a5fa; text-decoration: none; }

/* ---- Main ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px;
  max-width: 1300px;
}

/* ---- Login ---- */
.login-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--gray-100); margin: 0; }
.login-box { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px; width: 360px; }
.login-box h1 { font-size: 24px; color: var(--primary); margin-bottom: 4px; }
.login-box h2 { font-size: 16px; color: var(--gray-500); margin-bottom: 24px; }
.login-box form { display: flex; flex-direction: column; gap: 16px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.login-box input { padding: 9px 12px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 14px; }
.login-box button { padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: 6px; font-size: 15px; cursor: pointer; }

/* ---- Cards ---- */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--gray-700); }

/* ---- Forms ---- */
.form-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin-bottom: 4px; }
.form-col  { display: flex; flex-direction: column; gap: 16px; }
.field     { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.field--wide { flex: 1 1 100%; }
.field--sm   { min-width: 80px; max-width: 120px; }
.field--action { min-width: 0; }
.field label { font-weight: 600; font-size: 13px; color: var(--gray-700); }
.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=number],
.field textarea,
.field select {
  padding: 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { resize: vertical; }
.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; }
.inline-check { font-weight: 400; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; }

.lines-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 900px) { .lines-grid { grid-template-columns: 1fr 1fr; } }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 14px;
  background: var(--gray-200);
  border: none; border-radius: 6px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; color: var(--gray-900);
  transition: background .15s;
  white-space: nowrap;
}
.btn:hover { background: #d1d5db; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: #1d4ed8; }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: #15803d; }
.btn--danger  { background: var(--danger);  color: #fff; }
.btn--danger:hover  { background: #b91c1c; }
.btn--sm { padding: 4px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.actions   { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---- Alerts ---- */
.alert {
  padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-error   { background: #fee2e2; color: #991b1b; }
.alert-info    { background: #dbeafe; color: #1e40af; }

/* ---- Tables ---- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { background: var(--gray-100); padding: 8px 12px; text-align: left; font-weight: 700; border-bottom: 2px solid var(--gray-200); }
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--gray-200); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--gray-100); }
.row--inactive { opacity: .5; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.badge--admin { background: #fef9c3; color: #713f12; }
.badge--user  { background: #e0f2fe; color: #075985; }

/* ---- History filter ---- */
.filter-bar { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.empty { color: var(--gray-500); padding: 20px 0; }

/* ---- Style grid (builder) ---- */
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 16px; }
.style-grid h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.pos-table { border-collapse: collapse; font-size: 13px; }
.pos-table th { text-align: left; padding: 4px 8px; font-weight: 600; color: var(--gray-500); }
.pos-table td { padding: 3px 8px; }
.pos-table input[type=number] { width: 70px; padding: 4px 6px; }
.pos-table input[type=color]  { width: 40px; height: 28px; padding: 2px; cursor: pointer; }

.collapsible { border: 1px solid var(--gray-200); border-radius: 6px; padding: 0; }
.collapsible summary { padding: 10px 16px; cursor: pointer; font-weight: 600; list-style: none; }
.collapsible > :not(summary) { padding: 16px; }

/* ---- Preview ---- */
#cpw-preview { display: inline-block; overflow: auto; max-width: 100%; }
#cpw-preview .label {
  width: 744px; height: 1052px;
  padding: 48px; box-sizing: border-box;
  border: 1px dashed #ccc; position: relative;
  font-family: Arial, Helvetica, sans-serif;
  background: #fff; overflow: hidden;
}
#cpw-preview .cpw-img { max-width: 50%; margin: 12px 0; }
#cpw-preview .cpw-desc,
#cpw-preview [class^="cpw-line"] { white-space: pre-line; }

/* ---- Status ---- */
.status-msg { padding: 8px 14px; border-radius: 6px; font-size: 13px; margin-top: 8px; }
.status-ok    { background: #dcfce7; color: #166534; }
.status-error { background: #fee2e2; color: #991b1b; }
.status-info  { background: #dbeafe; color: #1e40af; }

/* ---- Backgrounds grid ---- */
.bg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.bg-card { background: var(--gray-100); border-radius: 6px; padding: 8px; text-align: center; }
.bg-card img { width: 100%; height: 100px; object-fit: cover; border-radius: 4px; margin-bottom: 6px; }
.bg-card__name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.bg-card__meta { color: var(--gray-500); font-size: 11px; margin-bottom: 8px; }

/* ---- Results panel ---- */
.results-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0 12px; border-bottom: 1px solid var(--gray-200); margin-bottom: 12px;
}
.results-header strong { font-size: 15px; }
.results-header small  { color: var(--gray-500); flex: 1; }

.results-list { display: flex; flex-direction: column; gap: 12px; }

.result-card {
  border: 1px solid var(--gray-200); border-radius: 8px;
  padding: 14px 16px; background: var(--gray-100);
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color .15s;
}
.result-card:hover { border-color: var(--primary); }

.result-card__header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.result-title  { font-weight: 700; font-size: 14px; flex: 1; }
.result-brand  { color: var(--gray-500); font-size: 13px; }

.result-card__body { display: flex; gap: 14px; align-items: flex-start; }
.result-img   { width: 80px; height: 80px; object-fit: contain; border-radius: 4px; background: #fff; flex-shrink: 0; }
.result-desc  { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.result-meta  { font-size: 12px; color: var(--gray-500); }
.result-short { font-size: 13px; color: var(--gray-700); margin: 0; }

.source-badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap;
}

/* ---- Misc ---- */
.hint { color: var(--gray-500); font-size: 13px; margin-bottom: 12px; }
.hint a { color: var(--primary); }
.test-result { background: #f8fafc; border: 1px solid var(--gray-200); padding: 12px; border-radius: 6px; max-height: 400px; overflow: auto; font-size: 12px; margin-top: 12px; }
.inline-form { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; }
h1 { font-size: 22px; font-weight: 800; margin-bottom: 20px; }
code { background: var(--gray-100); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ---- Wrap helpers ---- */
.builder-wrap, .history-wrap, .admin-wrap { max-width: 1100px; }
