* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: #111;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", sans-serif;
  color: #fff;
}

@supports not (background-attachment: fixed) {
  body { background-attachment: scroll; }
}

body.no-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
}

.placeholder {
  text-align: center;
  padding: 2rem;
}

.placeholder p { font-size: 1.05rem; opacity: 0.85; margin-bottom: 1rem; }
.placeholder a {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border: 1px solid #fff;
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.2s;
}
.placeholder a:hover { background: rgba(255,255,255,0.1); }

/* Admin styling */
.admin-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  color: #1a1a2e;
}
.admin-shell h1 { font-size: 1.4rem; margin: 0 0 1rem; }
.admin-shell h2 { font-size: 1.05rem; margin: 1.75rem 0 0.5rem; color: #444; font-weight: 600; }
.admin-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.admin-bar a { color: #2563eb; text-decoration: none; }
.admin-bar a:hover { text-decoration: underline; }
.admin-nav { display: flex; gap: 1rem; align-items: center; }
.admin-nav a {
  color: #4b5563;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-weight: 500;
}
.admin-nav a.is-active {
  background: #1f2937;
  color: #fff;
}
.admin-nav a.is-active:hover { text-decoration: none; }
.admin-user { font-size: 0.85rem; }

.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: #1f2937;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.btn:hover { background: #374151; }
.btn.secondary { background: #e5e7eb; color: #1f2937; }
.btn.secondary:hover { background: #d1d5db; }
.btn.danger { background: #dc2626; }
.btn.danger:hover { background: #b91c1c; }

input[type=text], input[type=password], input[type=file] {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
input[type=text]:focus, input[type=password]:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
label { display: block; margin: 0.6rem 0 0.3rem; font-size: 0.9rem; color: #374151; }

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  padding: 1.5rem;
}
.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 2rem 2.25rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  color: #1f2937;
}
.login-card h1 { font-size: 1.2rem; margin: 0 0 1rem; }

.alert {
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert.ok    { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}
th { background: #f9fafb; font-weight: 600; color: #374151; }
td.muted { color: #6b7280; word-break: break-all; }
tr:hover td { background: #fafafa; }

.bg-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.bg-thumb {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  background: #f3f4f6;
  position: relative;
}
.bg-thumb.is-active { border-color: #16a34a; box-shadow: 0 0 0 2px rgba(22,163,74,0.2); }
.bg-thumb img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}
.bg-thumb .actions {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem;
  font-size: 0.75rem;
}
.bg-thumb .actions form { flex: 1; }
.bg-thumb .actions button { width: 100%; padding: 0.3rem; font-size: 0.75rem; }
.bg-thumb .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: #16a34a;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
}

.muted-text { color: #6b7280; font-size: 0.85rem; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem 1.1rem;
}
.stat-card .label { font-size: 0.8rem; color: #6b7280; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; color: #111827; }
.stat-card .sub { font-size: 0.75rem; color: #9ca3af; margin-top: 0.2rem; }

.chart-wrap {
  position: relative;
  height: 280px;
  margin-top: 0.5rem;
}
.chart-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

/* Inline form layout */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.6rem;
  align-items: end;
}
.form-row label { margin-top: 0; }
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

/* User table */
.users-table td.actions {
  white-space: nowrap;
  width: 1%;
}
.users-table td.actions form {
  display: inline-block;
  margin: 0 0.15rem 0 0;
}
.users-table .row-form input { padding: 0.35rem 0.55rem; font-size: 0.85rem; }
.users-table .row-form { display: flex; gap: 0.3rem; align-items: center; }
.users-table .row-form button { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
