/* ─── CSS Variables (Dark & Light Themes) ─────────────────────── */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.05);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(233, 69, 96, 0.5);
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b8;
  --text-muted: #666680;
  --accent: #e94560;
  --accent-hover: #ff6b6b;
  --accent-gradient: linear-gradient(90deg, #e94560, #ff6b6b);
  --danger: #dc3545;
  --success: #28a745;
  --warning: #ffc107;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
}

/* Light theme */
body.light-mode {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e8eaed;
  --bg-card: rgba(0, 0, 0, 0.02);
  --bg-card-hover: rgba(0, 0, 0, 0.04);
  --bg-input: #ffffff;
  --border-color: rgba(0, 0, 0, 0.12);
  --border-focus: rgba(233, 69, 96, 0.5);
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* ─── Reset & Base ───────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(
    135deg,
    var(--bg-primary) 0%,
    var(--bg-secondary) 50%,
    var(--bg-tertiary) 100%
  );
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  transition:
    background 0.4s ease,
    color 0.4s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
  height: auto;
}

/* ─── Navbar ─────────────────────────────────────────────────── */
.navbar {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  transition:
    background 0.4s ease,
    border-color 0.4s ease;
}

.navbar-brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-brand .brand-accent {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
}

.navbar-nav a {
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all var(--transition);
}

.navbar-nav a:hover,
.navbar-nav a.active {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

/* Dropdown menus */
.nav-dropdown {
  position: relative;
}

.nav-dropdown .dropdown-arrow {
  font-size: 0.7rem;
  margin-left: 4px;
  display: inline-block;
  transition: transform 0.2s ease;
}

.nav-dropdown:hover .dropdown-arrow {
  transform: rotate(180deg);
}

.nav-dropdown .dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 200px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 150;
  list-style: none;
  padding: 0.5rem 0;
  margin-top: 4px;
}

.nav-dropdown:hover .dropdown-menu {
  display: block;
}

.nav-dropdown .dropdown-menu li a {
  display: block;
  padding: 0.5rem 1.25rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  border-radius: 0;
  white-space: nowrap;
}

.nav-dropdown .dropdown-menu li a:hover,
.nav-dropdown .dropdown-menu li a.active {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

/* ─── Container ──────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}

.card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.card-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.card-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.75rem;
}

.card-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  background: var(--bg-input);
}

/* Card links (for post cards) */
a.card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}
a.card-link:hover .card {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

/* Multi-select */
select[multiple].form-control {
  min-height: 120px;
  padding: 4px;
}
select[multiple].form-control option {
  padding: 6px 10px;
  border-radius: 4px;
  margin: 2px 0;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.3rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(233, 69, 96, 0.3);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.1);
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

/* ─── Search Bar ─────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.search-bar .form-control {
  flex: 1;
  min-width: 200px;
}

/* ─── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: none;
}

.alert-error {
  background: rgba(220, 53, 69, 0.15);
  color: #f8717f;
  border: 1px solid rgba(220, 53, 69, 0.3);
}

.alert-success {
  background: rgba(40, 167, 69, 0.15);
  color: #5cdb6e;
  border: 1px solid rgba(40, 167, 69, 0.3);
}

/* ─── Page Header ────────────────────────────────────────────── */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.page-header h1 .highlight {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header p {
  color: var(--text-secondary);
}

/* ─── Divider ────────────────────────────────────────────────── */
.divider {
  width: 60px;
  height: 3px;
  background: var(--accent-gradient);
  border-radius: 2px;
  margin-bottom: 1.5rem;
}

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-header h2 {
  color: var(--text-primary);
  font-size: 1.3rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--accent);
}

/* ─── Table ──────────────────────────────────────────────────── */
.table-container {
  overflow-x: auto;
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

td {
  color: var(--text-primary);
  font-size: 0.9rem;
}

tr:hover td {
  background: var(--bg-card-hover);
}

/* ─── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ─── Footer ─────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
  margin-top: 3rem;
}

/* ─── Loading Spinner ────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
}

.spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Utility ────────────────────────────────────────────────── */
.text-center {
  text-align: center;
}
.mt-1 {
  margin-top: 1rem;
}
.mt-2 {
  margin-top: 2rem;
}
.mb-1 {
  margin-bottom: 1rem;
}
.mb-2 {
  margin-bottom: 2rem;
}
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* ─── Toast ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.9rem;
  animation: slideInRight 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  max-width: 400px;
}

.toast.success {
  background: var(--success);
}
.toast.error {
  background: var(--danger);
}
.toast.warning {
  background: var(--warning);
  color: #000;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar {
    padding: 0 1rem;
  }

  .navbar-nav {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    width: 100%;
    background: var(--bg-secondary);
    flex-direction: column;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
  }

  .navbar-nav.open {
    display: flex;
  }

  .nav-dropdown .dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: transparent;
    padding-left: 1rem;
    min-width: auto;
  }

  .nav-dropdown:hover .dropdown-menu {
    display: none;
  }

  .nav-dropdown.open .dropdown-menu {
    display: block;
  }

  .mobile-menu-btn {
    display: block;
  }

  .container {
    padding: 1rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .page-header h1 {
    font-size: 1.5rem;
  }

  .tabs {
    flex-direction: column;
  }

  .tab-btn {
    text-align: left;
    border-bottom: none;
    border-left: 2px solid transparent;
  }

  .tab-btn.active {
    border-bottom: none;
    border-left-color: var(--accent);
  }
}

/* ─── Admin Layout ───────────────────────────────────────────── */
.admin-layout {
  display: flex;
  min-height: calc(100vh - 64px);
}

.admin-sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem 0;
  flex-shrink: 0;
}

.admin-sidebar a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
  font-size: 0.9rem;
}

.admin-sidebar a:hover,
.admin-sidebar a.active {
  color: var(--accent);
  background: var(--bg-card-hover);
}

.admin-content {
  flex: 1;
  padding: 2rem;
  overflow-x: hidden;
}

.admin-section {
  display: none;
}

.admin-section.active {
  display: block;
}

@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
  }

  .admin-sidebar {
    width: 100%;
    display: flex;
    overflow-x: auto;
    padding: 0.5rem;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .admin-sidebar a {
    padding: 0.5rem 1rem;
    white-space: nowrap;
  }

  .admin-content {
    padding: 1rem;
  }
}

/* ─── Login Page ─────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  text-align: center;
  margin-bottom: 0.5rem;
  font-size: 1.6rem;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

/* ─── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 2rem;
}

.pagination button {
  padding: 0.4rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
}

.pagination button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Tag / Badge ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.badge-accent {
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent);
  border-color: rgba(233, 69, 96, 0.3);
}
/* ─── Image Upload ─────────────────────────────────────────── */
.img-upload-group {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.img-upload-group img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  object-fit: cover;
}
.img-upload-group input[type="file"] {
  flex: 1;
  min-width: 150px;
}

/* ─── Language Switcher ─────────────────────────────────────── */
.lang-switcher {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}
.lang-switcher:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ─── RTL (Persian/Farsi) Overrides ─────────────────────────── */
body.rtl {
  direction: rtl;
  text-align: right;
}

body.rtl .navbar-nav {
  padding-right: 0;
}

body.rtl .nav-dropdown .dropdown-menu {
  left: auto;
  right: 0;
}

body.rtl .nav-dropdown .dropdown-arrow {
  margin-left: 0;
  margin-right: 4px;
}

body.rtl .navbar-actions {
  flex-direction: row-reverse;
}

body.rtl .admin-sidebar a {
  flex-direction: row;
}

body.rtl .admin-layout {
  flex-direction: row;
}

body.rtl .modal-header {
  flex-direction: row;
}

body.rtl th,
body.rtl td {
  text-align: right;
}

body.rtl .search-bar {
  flex-direction: row-reverse;
}

body.rtl .flex-between {
  flex-direction: row;
}

body.rtl .toast-container {
  right: auto;
  left: 1rem;
}

body.rtl .post-body {
  text-align: right;
  direction: rtl;
}

body.rtl .post-body h1,
body.rtl .post-body h2,
body.rtl .post-body h3 {
  text-align: right;
}

body.rtl .post-body ul,
body.rtl .post-body ol {
  padding-left: 0;
  padding-right: 24px;
}

body.rtl .post-body blockquote {
  border-left: none;
  border-right: 3px solid var(--accent);
  padding-left: 0;
  padding-right: 16px;
}

body.rtl .badge {
  margin-left: 0;
  margin-right: 0;
}

body.rtl select.form-control {
  background-position: left 0.75rem center;
}

@media (max-width: 768px) {
  body.rtl .admin-layout {
    flex-direction: column;
  }
  body.rtl .admin-sidebar {
    flex-direction: row;
  }
  body.rtl .nav-dropdown .dropdown-menu {
    right: auto;
    left: auto;
  }
}
