:root {
  --bg: #0f1225;
  --surface: #181c36;
  --surface-2: #21264a;
  --border: #2e3561;
  --text: #f3f4f8;
  --muted: #9ca3c9;
  --primary: #4f6df5;
  --primary-hover: #3e5ce8;
  --accent: #fbbf24;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #1f2552 0%, #0f1225 65%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.14);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.login-card .subtitle {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(15, 18, 37, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.08rem;
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.85rem;
}

.role-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(79, 109, 245, 0.22);
  color: #a5b4fc;
}

.role-badge.admin {
  background: rgba(251, 191, 36, 0.2);
  color: var(--accent);
}

/* Container & Toolbar */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 16px 48px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 240px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Inputs & Buttons */
input[type='text'],
input[type='password'],
input[type='search'],
select,
textarea {
  width: 100%;
  background: #12152b;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.86rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
  min-width: 160px;
}

.flex-2 {
  flex: 2;
  min-width: 220px;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.84rem;
}

.btn-full {
  width: 100%;
}

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

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

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

.btn-ghost:hover {
  border-color: var(--primary);
}

.btn-danger-outline {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.55);
  color: #fca5a5;
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* Posts Grid */
.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.post-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.post-thumb-wrap {
  position: relative;
  height: 185px;
  background: #12152b;
  overflow: hidden;
}

.post-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.img-count-badge {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(15, 18, 37, 0.85);
  color: var(--accent);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.78rem;
  font-weight: 700;
}

.post-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.post-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.tag {
  display: inline-block;
  background: rgba(79, 109, 245, 0.18);
  color: #a5b4fc;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.post-card-title {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.35;
}

.post-card-excerpt {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}

/* Pagination */
.pagination {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

/* Detail View */
.detail-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.detail-owner-actions {
  display: flex;
  gap: 8px;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.86rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.detail-title {
  margin: 0 0 16px;
  font-size: 1.65rem;
  line-height: 1.3;
}

.detail-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1rem;
  color: #e6e8f2;
}

.detail-gallery-wrap {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.gallery-heading {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--accent);
}

.detail-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.gallery-item {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #12152b;
  cursor: zoom-in;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-expired {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Admin View */
.section-heading {
  margin: 0;
  font-size: 1.25rem;
}

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

.admin-card h3 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.admin-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.admin-card-head h3 {
  margin-bottom: 4px;
}

.storage-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-box strong {
  font-size: 1.15rem;
  color: var(--accent);
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #12152b;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.25s;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.field-submit {
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
}

.status-ok {
  color: var(--success);
  font-weight: 600;
}

.status-locked {
  color: #fca5a5;
  font-weight: 600;
}

.action-group {
  display: inline-flex;
  gap: 6px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 16, 0.75);
}

.modal-dialog {
  position: relative;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-lg {
  max-width: 720px;
}

.modal-sm {
  max-width: 420px;
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.icon-btn:hover {
  color: var(--text);
}

/* Upload Dropzone & Preview */
.upload-dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  background: #12152b;
  cursor: pointer;
  transition: border-color 0.15s;
}

.upload-dropzone:hover {
  border-color: var(--primary);
}

.upload-dropzone input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-dropzone p {
  margin: 0 0 4px;
  font-weight: 600;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.preview-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
  background: #12152b;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 18, 37, 0.85);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(5, 7, 16, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox-stage {
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.lightbox-stage img {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-caption {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 2.2rem;
  cursor: pointer;
}

.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  font-size: 2.2rem;
  width: 46px;
  height: 64px;
  border-radius: 10px;
  cursor: pointer;
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

/* Alerts & Toast */
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 10px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 90;
  background: var(--surface-2);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  max-width: 360px;
}

@media (max-width: 640px) {
  .detail-card {
    padding: 16px;
  }
  .detail-title {
    font-size: 1.35rem;
  }
  .lightbox-nav {
    width: 36px;
    height: 48px;
    font-size: 1.7rem;
  }
}
