:root {
  --bg: #f4f7fb;
  --card-bg: #ffffff;
  --text: #172a3d;
  --muted: #66788a;
  --accent: #f47b20;
  --border: #dce5ee;
  --shadow: 0 1px 3px rgba(16, 42, 67, 0.08);
  --shadow-hover: 0 6px 16px rgba(16, 42, 67, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header.site-header {
  position: relative;
  background: var(--bg);
  color: #fff;
  text-align: center;
  padding: 30px;
}

header.site-header::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 100%;
  max-width: 1100px;
  transform: translateX(-50%);
  background-image: var(--header-image, url("thu%20vien/header.png"));
  background-position: bottom right;
  background-size: cover;
  background-repeat: no-repeat;
}

.header-auth-btn {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(16, 42, 67, 0.4);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  cursor: pointer;
  flex-shrink: 0;
}

.header-auth-btn.hidden {
  display: none;
}

header.site-header .header-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  position: absolute;
  right: 8px;
  bottom: 8px;
}

header.site-header img.logo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #fff;
  padding: 6px;
  object-fit: contain;
  flex-shrink: 0;
  margin-left: 60px;
}

header.site-header h1 {
  margin: 0;
  font-size: 2rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.6);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

section.group {
  margin-bottom: 36px;
}

section.group .group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 16px;
}

section.group h2 {
  font-size: 1.05rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin: 0;
}

.group-header-title {
  display: flex;
  align-items: center;
}

.row-controls {
  gap: 2px;
}

.row-edit-btn,
.row-delete-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.row-edit-btn {
  font-size: 0.9rem;
}

.row-edit-btn:hover {
  background: #fff3e8;
  color: var(--accent);
}

.row-delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 14px;
}

.link-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 8px;
  height: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.link-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.link-card img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.link-card span {
  font-size: 0.78rem;
  text-align: center;
  line-height: 1.25;
  word-break: break-word;
}

.link-card.note {
  border-style: dashed;
  opacity: 0.75;
}

footer {
  background: var(--bg);
  font-size: 0.8rem;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 20px 40px;
  background: #1d4667;
  color: #d9e5ee;
  text-align: left;
}

footer p {
  margin: 0;
}

/* --- dynamic cards / admin controls --- */

.link-card-wrap {
  position: relative;
}

.link-card-wrap--size-2 {
  grid-column: span 2;
}

.link-card-wrap--size-2 .link-card img {
  width: auto;
  height: auto;
  max-height: 48px;
  max-width: 100%;
}

.link-card-wrap--size-2 .link-card span {
  font-size: 0.88rem;
}

.link-card-wrap--no-caption .link-card img {
  width: 72px;
  height: 72px;
}

.link-card-wrap--size-2.link-card-wrap--no-caption .link-card img {
  width: auto;
  height: 72px;
  max-width: 100%;
}

.hidden-unless-admin {
  display: none !important;
}

body.is-admin .hidden-unless-admin {
  display: flex !important;
}

.cell-admin-controls {
  position: absolute;
  top: 4px;
  right: 4px;
  gap: 4px;
  z-index: 1;
}

.drag-handle {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 1;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  cursor: grab;
  font-size: 0.85rem;
  color: var(--muted);
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.row-drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 0.95rem;
  margin-right: 4px;
  touch-action: none;
}

.row-drag-handle:active {
  cursor: grabbing;
}

.sortable-ghost {
  opacity: 0.35;
}

.sortable-drag {
  box-shadow: var(--shadow-hover);
}

.grid.sortable-drag,
section.group.sortable-drag {
  border: 1.5px dashed var(--accent);
}

.cell-admin-controls button {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
}

.cell-admin-controls button.delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.cell-admin-controls button.edit-btn:hover {
  background: #fff3e8;
  color: var(--accent);
}

.add-cell-btn {
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  border-radius: 12px;
  min-height: 92px;
}

.add-cell-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.add-row-btn {
  display: block;
  width: fit-content;
  margin: 8px auto 0;
  padding: 12px 28px;
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
}

.add-row-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- modals --- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 42, 67, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-hover);
}

.modal-box h3 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

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

.btn-google::before {
  content: "G";
  font-weight: 700;
  color: #4285f4;
}

.modal-divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 14px 0;
  position: relative;
}

.modal-divider::before,
.modal-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  border-top: 1px solid var(--border);
}

.modal-divider::before {
  left: 0;
}

.modal-divider::after {
  right: 0;
}

.modal-box form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.modal-box label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.modal-box .checkbox-label input[type="checkbox"] {
  width: auto;
  padding: 0;
  border: none;
  background: transparent;
}

.modal-box input,
.modal-box select {
  font-size: 0.95rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  background: #fff;
}

.modal-error {
  margin: 0;
  min-height: 1em;
  font-size: 0.82rem;
  color: #dc2626;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.btn-primary,
.btn-secondary {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 0.88rem;
  cursor: pointer;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

.logo-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -4px;
}

.logo-actions .btn-secondary {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.logo-preview {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 3px;
}

.logo-picker-box {
  max-width: min(1040px, 92vw);
}

.logo-upload-bar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.logo-upload-bar .btn-secondary {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.logo-bulk-status {
  margin: 8px 0 0;
  min-height: 1em;
  font-size: 0.82rem;
  color: var(--muted);
}

.logo-picker-grid {
  max-height: 70vh;
  overflow-y: auto;
  padding: 4px;
  margin-top: 8px;
}

.logo-folder-group {
  margin-bottom: 18px;
}

.logo-folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.logo-folder-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.logo-folder-controls {
  display: flex;
  gap: 2px;
}

.logo-folder-controls button {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.logo-folder-controls .logo-folder-edit:hover {
  background: #fff3e8;
  color: var(--accent);
}

.logo-folder-controls .logo-folder-delete:hover {
  background: #fee2e2;
  color: #dc2626;
}

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

.logo-picker-item-wrap {
  position: relative;
}

.logo-picker-item {
  width: 100%;
  aspect-ratio: 1;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.logo-picker-item:hover {
  border-color: var(--accent);
}

.logo-picker-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-picker-item-controls {
  position: absolute;
  top: -6px;
  right: -6px;
  display: flex;
  gap: 3px;
}

.logo-picker-item-controls button {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
}

.logo-picker-edit:hover {
  background: #fff3e8;
  color: var(--accent);
}

.logo-picker-delete:hover {
  background: #fee2e2;
  color: #dc2626;
}

.logo-picker-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 12px 0;
}
