/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f9fafb;
  color: #111827;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

/* ── Layout ────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform .22s ease;
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid #f3f4f6;
  min-height: 64px;
  display: flex;
  align-items: center;
}
.sidebar-brand-text {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -.4px;
  color: #111827;
}
.sidebar-logo {
  max-height: 36px;
  max-width: 160px;
  object-fit: contain;
}
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  color: #374151;
  transition: background .15s, color .15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
}
.nav-item:hover   { background: #f3f4f6; color: #111827; }
.nav-item.active  { background: #f3f4f6; color: #111827; font-weight: 600; }
.nav-item svg     { opacity: .75; flex-shrink: 0; }
.nav-item-sm { font-size: .82rem; padding: 7px 12px; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid #f3f4f6;
}
.sidebar-user {
  display: block;
  font-size: .77rem;
  color: #9ca3af;
  padding: 0 12px;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Topbar (mobile) ─────────────────────────────────────────────── */
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 99;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 16px;
  height: 56px;
  align-items: center;
  gap: 14px;
}
.topbar-brand { font-weight: 700; font-size: 1rem; }
.topbar-toggle { background: none; border: none; cursor: pointer; color: #374151; padding: 4px; display: flex; }

/* ── Main Content ────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: 220px;
  padding: 28px 32px;
  min-height: 100vh;
}

/* ── Page Header ─────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -.3px; color: #111827; }
.page-sub   { font-size: .875rem; color: #6b7280; margin-top: 2px; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title { font-size: 1rem; font-weight: 600; color: #111827; }
.card-body  { padding: 20px; }

/* ── Table Grid ──────────────────────────────────────────────────── */
.table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.table-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow .15s;
}
.table-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.07); }
.table-card-header {
  display: flex; align-items: center; justify-content: space-between;
}
.table-number { font-size: 1.1rem; font-weight: 700; color: #111827; }
.table-name   { font-size: .85rem; color: #6b7280; }
.table-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.table-card-qr { display: flex; justify-content: center; padding: 8px 0; }
.table-card-url {
  font-size: .72rem; color: #9ca3af; word-break: break-all;
  text-align: center; font-family: monospace;
}
.table-card-actions {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px;
}

/* ── Edit Grid ───────────────────────────────────────────────────── */
.edit-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
.edit-col-main {}
.edit-col-side {}

/* ── Form Elements ───────────────────────────────────────────────── */
.form-group  { margin-bottom: 16px; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-label  { display: block; font-size: .84rem; font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-input  {
  display: block; width: 100%;
  padding: 9px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 7px;
  font-size: .9rem;
  color: #111827;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-input:focus  { border-color: #3B82F6; box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.form-input::placeholder { color: #9ca3af; }
textarea.form-input { resize: vertical; }
.code-input { font-family: 'SF Mono','Fira Code','Consolas',monospace; font-size: .82rem; }
.form-hint  { font-size: .8rem; color: #9ca3af; }
.required   { color: #EF4444; }
.muted      { color: #9ca3af; font-size: .85rem; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 7px;
  font-size: .88rem; font-weight: 500;
  cursor: pointer; border: none; transition: all .15s;
  white-space: nowrap;
}
.btn-primary {
  background: #111827; color: #fff;
}
.btn-primary:hover { background: #1f2937; }
.btn-outline {
  background: #fff; color: #374151;
  border: 1px solid #e5e7eb;
}
.btn-outline:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-ghost {
  background: transparent; color: #374151;
}
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger-outline {
  background: #fff; color: #EF4444;
  border: 1px solid #fecaca;
}
.btn-danger-outline:hover { background: #fef2f2; }
.btn-sm  { padding: 6px 12px; font-size: .82rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  background: none; border: none; cursor: pointer; padding: 5px;
  border-radius: 5px; color: #6b7280; display: inline-flex;
  transition: background .12s, color .12s;
}
.btn-icon:hover { background: #f3f4f6; color: #111827; }
.btn-icon-danger:hover { background: #fef2f2; color: #EF4444; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: .75rem; font-weight: 500;
}
.badge-gray  { background: #f3f4f6; color: #374151; }
.badge-blue  { background: #EFF6FF; color: #2563EB; }
.badge-green { background: #ECFDF5; color: #059669; }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.35); z-index: 200;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px;
  width: 100%; max-width: 460px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 48px rgba(0,0,0,.15);
}
.modal-lg  { max-width: 580px; }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid #f3f4f6;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: #9ca3af; line-height: 1; padding: 2px 6px;
  border-radius: 5px; transition: background .12s;
}
.modal-close:hover { background: #f3f4f6; color: #111827; }
form > .form-group, .modal .form-group { padding: 0 24px; }
form > .form-group:first-of-type { margin-top: 20px; }
.modal-footer {
  padding: 16px 24px 20px;
  display: flex; justify-content: flex-end; gap: 8px;
  border-top: 1px solid #f3f4f6;
  margin-top: 8px;
}

/* ── Links list ─────────────────────────────────────────────────── */
.links-list { list-style: none; }
.link-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid #f3f4f6;
}
.link-item:last-child { border-bottom: none; }
.link-drag { cursor: grab; color: #d1d5db; flex-shrink: 0; }
.link-drag:active { cursor: grabbing; }
.link-icon { flex-shrink: 0; }
.link-info  { flex: 1; min-width: 0; }
.link-title { display: block; font-size: .88rem; font-weight: 500; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-url   { display: block; font-size: .77rem; color: #9ca3af; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ── Upload Zone ─────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed #e5e7eb; border-radius: 8px;
  padding: 32px 20px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: #9ca3af; font-size: .88rem;
}
.upload-zone:hover { border-color: #3B82F6; background: #EFF6FF; }
.upload-zone small { font-size: .77rem; }

/* ── Toggle ──────────────────────────────────────────────────────── */
.toggle-label {
  display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer; font-size: .88rem; color: #374151;
  user-select: none;
}
.toggle-label input[type=checkbox] { display: none; }
.toggle {
  width: 40px; height: 22px; background: #e5e7eb;
  border-radius: 11px; position: relative;
  transition: background .2s; flex-shrink: 0;
}
.toggle::after {
  content: ''; position: absolute;
  left: 3px; top: 3px;
  width: 16px; height: 16px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s;
}
.toggle-label input:checked ~ .toggle { background: #111827; }
.toggle-label input:checked ~ .toggle::after { transform: translateX(18px); }

.toggle-grid { display: flex; flex-direction: column; gap: 2px; }
.toggle-row  {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid #f3f4f6;
}
.toggle-row:last-child { border-bottom: none; }

/* ── Stats ────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.stat-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 20px;
}
.stat-label { font-size: .8rem; color: #6b7280; font-weight: 500; margin-bottom: 6px; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: #111827; }

/* ── Data Table ──────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: .875rem;
}
.data-table th {
  background: #f9fafb; text-align: left;
  padding: 10px 16px; font-size: .78rem; font-weight: 600;
  color: #6b7280; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid #e5e7eb; white-space: nowrap;
}
.data-table td {
  padding: 11px 16px; border-bottom: 1px solid #f3f4f6;
  color: #374151; vertical-align: middle;
}
.data-table tbody tr:hover { background: #fafafa; }
.data-table tbody tr:last-child td { border-bottom: none; }

.stars { display: flex; gap: 1px; }

/* ── Pagination ──────────────────────────────────────────────────── */
.pagination {
  display: flex; gap: 4px; padding: 16px;
  justify-content: center; flex-wrap: wrap;
}
.page-btn {
  min-width: 32px; height: 32px; display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 6px; border: 1px solid #e5e7eb;
  font-size: .82rem; color: #374151; background: #fff;
  transition: all .12s;
}
.page-btn:hover { background: #f3f4f6; }
.page-btn.active { background: #111827; color: #fff; border-color: #111827; }

/* ── Alerts ────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 7px; font-size: .875rem; }
.alert-danger { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.mb-24 { margin-bottom: 24px; }

/* ── Empty State ─────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 60px 20px; text-align: center; color: #9ca3af; font-size: .9rem;
}
.empty-state-sm {
  padding: 20px; text-align: center; color: #9ca3af; font-size: .85rem;
}

/* ── Toast ───────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: #111827; color: #fff; padding: 12px 20px;
  border-radius: 8px; font-size: .88rem;
  transform: translateY(80px); opacity: 0;
  transition: all .25s ease; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
#toast.show { transform: translateY(0); opacity: 1; }

/* ── mt/gap utilities ────────────────────────────────────────────── */
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .edit-grid { grid-template-columns: 1fr; }
  .edit-col-side { order: -1; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .main-content { margin-left: 0; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
}

@media (max-width: 480px) {
  .table-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}
