:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* Stack & spacing */
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.mt-xs { margin-top: 6px; }
.mt-sm { margin-top: 10px; }
.mt-md { margin-top: 14px; }
.mt-lg { margin-top: 20px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); border-color: #cbd5e1; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger:hover { background: #fee2e2; }

.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-full { width: 100%; }

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-weight: 600;
  font-size: 13px;
  color: #334155;
}
input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}

.error-text {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  padding: 8px 11px;
  border-radius: 8px;
  margin: 0;
  font-size: 13px;
}

.notice-box {
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.45;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, #dbeafe, #f1f5f9 55%);
}
.login-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 12px 35px rgba(15, 23, 42, 0.08);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.brand-row h1 { margin: 0; font-size: 20px; }
.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.login-hint {
  margin: 16px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 248px;
  background: #0f172a;
  color: #f8fafc;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 6px;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: #94a3b8; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.nav-btn {
  border: none;
  background: transparent;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 9px;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; }

.sidebar-footer {
  border-top: 1px solid #1e293b;
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-footer .btn-ghost { color: #cbd5e1; }
.sidebar-footer .btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #334155;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-transform: uppercase;
}
.user-name { font-size: 13.5px; font-weight: 600; }
.user-role { font-size: 11.5px; color: #94a3b8; text-transform: uppercase; }

.main-content {
  flex: 1;
  padding: 24px 28px;
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0 0 2px; font-size: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.base-url-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Cards & Toolbar */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card h3, .card h4 { margin: 0; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}
.toolbar-filters input[type="search"] { max-width: 300px; }
.toolbar-filters select { width: auto; min-width: 170px; }

/* QR Grid */
.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}
.qr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.qr-card-top {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.qr-thumb {
  width: 88px;
  height: 88px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  background: #fff;
  flex-shrink: 0;
  object-fit: contain;
}
.qr-info { flex: 1; min-width: 0; }
.qr-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.qr-title {
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qr-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.qr-links {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
}
.qr-link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.qr-link-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #334155;
}
.qr-link-text a { color: var(--primary); text-decoration: none; font-weight: 600; }
.qr-link-text a:hover { text-decoration: underline; }

.qr-metrics {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.qr-metrics strong { color: var(--text); font-size: 14px; }

.qr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 46px 20px;
}

/* KPI & Analytics */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 0; }
.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 800; color: var(--text); }
.kpi-value-sm { font-size: 18px; line-height: 1.4; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.chart-card { margin-bottom: 18px; }
.svg-chart-wrap {
  width: 100%;
  min-height: 210px;
  margin-top: 12px;
  position: relative;
}
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: #0f172a;
  color: #fff;
  padding: 6px 9px;
  border-radius: 7px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 10;
}

.legend { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend-dot.primary { background: var(--primary); }

.analytics-split {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 16px;
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 10px;
}
.breakdown-item { display: flex; flex-direction: column; gap: 4px; }
.breakdown-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
}
.breakdown-bar-bg {
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.breakdown-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}

.top-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}

/* Tables & Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 920px; }
.modal-xl { max-width: 1040px; }

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.qr-editor-layout {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 24px;
  align-items: start;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-input-wrap input[type="color"] {
  width: 42px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.color-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.preset-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.preset-btn:hover { border-color: var(--primary); color: var(--primary); }

.logo-box {
  background: var(--surface-2);
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.existing-logo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.qr-preview-pane {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.preview-frame {
  width: 240px;
  height: 240px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-frame img { width: 100%; height: 100%; object-fit: contain; }
.preview-meta { text-align: center; width: 100%; }
.short-url-code {
  display: inline-block;
  margin-top: 4px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.preview-downloads { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* Toasts */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 920px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .sidebar-nav { flex-direction: row; flex: initial; }
  .sidebar-footer { border-top: none; padding-top: 0; flex-direction: row; align-items: center; }
  .qr-editor-layout, .analytics-split, .three-col { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .main-content { padding: 16px; }
  .qr-grid, .two-col { grid-template-columns: 1fr; }
}
