:root {
  --bg-color: #0a0a0a;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #48d1a5;
  --primary-hover: #3ab892;
  --accent: #ff8b8b;
  --accent-amber: #ffb319;
  --glass-bg: rgba(30, 41, 59, 0.75);
  --glass-border: rgba(255, 255, 255, 0.1);
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #22c55e;
  --sidebar-w: 260px;
}

body.light-mode {
  --bg-color: #f5f7f6;
  --text-main: #0f172a;
  --text-muted: #475569;
  --primary: #2d6a64;
  --primary-hover: #245a55;
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', 'Cairo', sans-serif;
  background: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* HTML hidden must win over .app-shell / .modal-backdrop display rules */
[hidden] {
  display: none !important;
}

.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  filter: blur(100px);
  opacity: 0.35;
  border-radius: 50%;
}

.blob-1 {
  width: 500px;
  height: 500px;
  background: var(--primary);
  top: -10%;
  left: -5%;
}

.blob-2 {
  width: 450px;
  height: 450px;
  background: var(--accent);
  bottom: -10%;
  right: -5%;
}

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  position: relative;
  z-index: 1;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  position: relative;
  z-index: 2;
}

.login-card .logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.login-sub {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.login-form .field {
  display: block;
  margin-bottom: 1rem;
}

.login-form .field span,
.login-form .field > label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap .input {
  padding-right: 2.75rem;
  position: relative;
  z-index: 1;
}

.password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.password-toggle:hover {
  color: var(--text-main);
  background: rgba(99, 102, 241, 0.15);
}

.password-toggle svg[hidden] {
  display: none !important;
}

.file-protocol-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2001;
  padding: 0.75rem 1rem;
  text-align: center;
  font-size: 0.9rem;
  background: rgba(245, 158, 11, 0.95);
  color: #0f172a;
  font-weight: 600;
}

.file-protocol-banner code {
  background: rgba(0, 0, 0, 0.12);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

/* App layout */
.app-shell {
  display: flex;
  min-height: 100vh;
  gap: 1.25rem;
  padding: 1.25rem;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  position: sticky;
  top: 1.25rem;
  height: calc(100vh - 2.5rem);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--primary);
  margin-bottom: 1.25rem;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.9rem;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.2s, color 0.2s;
}

.nav-item:hover {
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.nav-icon {
  font-size: 1.1rem;
  width: 1.5rem;
  text-align: center;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--glass-border);
}

.main-content {
  flex: 1;
  min-width: 0;
  overflow: auto;
  position: relative;
}

.main-content.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 16px;
}

.page-header {
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.page-header p {
  color: var(--text-muted);
  font-size: 1rem;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card {
  padding: 1.25rem;
}

.stat-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  margin: 0.35rem 0;
}

.stat-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Table */
.table-wrap {
  padding: 0.5rem;
  overflow-x: auto;
  margin-top: 1rem;
}

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

.data-table th {
  text-align: left;
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--glass-border);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

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

/* Cards grid */
.cards-grid,
.posts-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.entity-card,
.post-card {
  padding: 1.15rem;
}

.entity-card h3,
.post-card strong {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

.meta {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
}

.post-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.post-media {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 12px;
  margin: 0.5rem 0;
}

.rich-content {
  line-height: 1.55;
  word-break: break-word;
  margin: 0.35rem 0 0.5rem;
}

.rich-content .mention {
  color: var(--primary);
  font-weight: 600;
}

.rich-content .hashtag {
  color: #a78bfa;
  font-weight: 600;
}

.rich-content .rich-link {
  color: #60a5fa;
  text-decoration: underline;
}

.post-body {
  max-height: 320px;
  overflow-y: auto;
}

.avatar-sm {
  width: 28px;
  height: 28px;
}

.comment-row {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--glass-border);
}

.comment-row:last-child {
  border-bottom: none;
}

.comment-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.comments-modal-list {
  max-height: min(60vh, 480px);
  overflow-y: auto;
}

.login-remember {
  margin: 0.25rem 0 0.75rem;
  justify-content: flex-start;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

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

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

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

.btn-warn {
  background: var(--warn);
  color: #0f172a;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--glass-border);
}

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

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
  padding: 0.75rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
}

body.light-mode .input {
  background: rgba(255, 255, 255, 0.9);
}

.input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.toolbar .input {
  max-width: 320px;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-ok {
  background: rgba(34, 197, 94, 0.2);
  color: var(--ok);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warn);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.empty-state.error {
  color: var(--danger);
}

/* Form card */
.form-card {
  padding: 1.5rem;
  max-width: 560px;
  margin-top: 1rem;
}

.form-card .field {
  display: block;
  margin-bottom: 1rem;
}

.form-card .field span {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

.field-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.field-hint code {
  background: rgba(99, 102, 241, 0.2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.target-fieldset {
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
}

.target-fieldset legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.35rem;
}

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

.modal-form .field {
  display: block;
  margin-bottom: 0.85rem;
}

.modal-form .field span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.comment-row {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--glass-border);
}

/* Modal */
.modal-backdrop:not([hidden]) {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-title {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.modal-message {
  font-size: 1rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.85rem 1.25rem;
  border-radius: 12px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 360px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  border-color: var(--ok);
}

.toast-error {
  border-color: var(--danger);
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
}
