/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #6366f1;
  --brand-dark:   #4f46e5;
  --brand-light:  #e0e7ff;
  --success:      #22c55e;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;
  --bg:           #f8fafc;
  --bg-card:      #ffffff;
  --border:       #e2e8f0;
  --border-focus: #6366f1;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow:       0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:    0 12px 40px rgba(0,0,0,.14);
  --radius:       14px;
  --radius-sm:    8px;
  --radius-lg:    20px;
  --sidebar-w:    240px;
  --topbar-h:     60px;
  --transition:   0.2s ease;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  direction: rtl;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Utilities ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; }
.accent { color: var(--brand); }
.optional { font-size: .75rem; color: var(--text-muted); font-weight: 400; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 20px; border-radius: var(--radius-sm); border: none;
  font-family: inherit; font-size: .875rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

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

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }

.btn-ghost    { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

.btn-sm  { padding: 6px 14px; font-size: .8rem; }
.btn-lg  { padding: 13px 28px; font-size: 1rem; }
.btn-full { width: 100%; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--text); }

.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { min-width: 180px; }

input[type="text"], input[type="url"], input[type="password"],
input[type="number"], input[type="search"], input[type="datetime-local"],
select, textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-family: inherit; font-size: .9rem;
  color: var(--text); background: var(--bg-card); transition: border var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
input::placeholder { color: var(--text-light); }

.input-prefix-wrap { display: flex; align-items: stretch; }
.input-prefix {
  display: flex; align-items: center; padding: 0 12px;
  background: var(--bg); border: 1.5px solid var(--border); border-left: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-size: .8rem; color: var(--text-muted); white-space: nowrap;
  /* RTL: left side */
}
[dir="rtl"] .input-prefix {
  border-left: 1.5px solid var(--border); border-right: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.input-prefix-wrap input {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
[dir="rtl"] .input-prefix-wrap input {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.form-group-check { justify-content: flex-end; padding-bottom: 2px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500;
}
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ─── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 16px;
}
.card-title-row {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;
}

/* ─── Site Header ────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}

.logo { display: flex; align-items: baseline; gap: 0; text-decoration: none; }
.logo-main { font-size: 1.6rem; font-weight: 800; color: var(--brand); letter-spacing: -1px; }
.logo-dot  { font-size: 1.2rem; font-weight: 600; color: var(--text-muted); }
.logo-center { justify-content: center; margin-bottom: 24px; }

/* ─── Hero Section ───────────────────────────────────────────────────────────── */
.hero {
  padding: 72px 0 48px;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 60%);
}
.hero-content { max-width: 680px; margin: 0 auto; text-align: center; }
.hero-title { font-size: clamp(1.8rem, 4vw, 2.8rem); font-weight: 800; line-height: 1.25; margin-bottom: 12px; }
.hero-subtitle { color: var(--text-muted); font-size: 1.05rem; margin-bottom: 36px; }

.shorten-card { text-align: right; }
.shorten-card form { display: flex; flex-direction: column; gap: 16px; }

.advanced-toggle {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  color: var(--brand); font-size: .875rem; font-weight: 600;
  user-select: none; width: fit-content;
}
.advanced-toggle .chevron {
  width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
  transition: transform var(--transition);
}
.advanced-toggle.open .chevron { transform: rotate(180deg); }
.advanced-section { display: none; flex-direction: column; gap: 16px; }
.advanced-section.open { display: flex; }

/* ─── Result Card ────────────────────────────────────────────────────────────── */
.result-card { margin-top: 20px; text-align: right; }
.result-header {
  display: flex; align-items: center; gap: 8px;
  color: var(--success); font-weight: 700; font-size: 1rem; margin-bottom: 16px;
}
.result-header .icon-check {
  width: 22px; height: 22px; stroke: currentColor; fill: none;
  stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
}
.result-url-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 12px;
}
.result-url { font-size: 1.1rem; font-weight: 700; color: var(--brand); flex: 1; word-break: break-all; }
.result-meta { font-size: .8rem; color: var(--text-muted); margin-bottom: 14px; word-break: break-all; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.qr-container {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border);
}
.qr-container img { width: 160px; height: 160px; border-radius: var(--radius-sm); }

/* ─── Features Section ───────────────────────────────────────────────────────── */
.features { padding: 64px 0; }
.features-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 20px;
}
.feature-item {
  text-align: center; padding: 24px 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); transition: box-shadow var(--transition);
}
.feature-item:hover { box-shadow: var(--shadow); }
.feature-icon { font-size: 2rem; margin-bottom: 10px; }
.feature-item h3 { font-size: .95rem; font-weight: 700; margin-bottom: 6px; }
.feature-item p { font-size: .8rem; color: var(--text-muted); }

/* ─── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  background: var(--bg-card); border-top: 1px solid var(--border);
  padding: 24px 0; text-align: center; font-size: .85rem; color: var(--text-muted);
}

/* ─── Page Center ────────────────────────────────────────────────────────────── */
.page-center {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 60%);
}
.center-wrap { width: 100%; max-width: 420px; padding: 24px; text-align: center; }

.password-card { text-align: right; }
.password-icon { font-size: 3rem; margin-bottom: 12px; }
.password-card h2 { font-size: 1.2rem; margin-bottom: 6px; }
.password-hint { font-size: .875rem; color: var(--text-muted); margin-bottom: 20px; }

.error-card { text-align: center; padding: 40px 24px; }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--brand); margin-bottom: 8px; }
.error-card h2 { font-size: 1.3rem; margin-bottom: 8px; }
.error-card p { color: var(--text-muted); margin-bottom: 20px; }

.back-link { margin-top: 16px; font-size: .85rem; }

/* ─── Admin Layout ───────────────────────────────────────────────────────────── */
.page-admin body, .admin-layout {
  min-height: 100vh;
}
.admin-layout {
  display: flex; min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; right: 0; bottom: 0;
  z-index: 40; transition: transform var(--transition);
}
.sidebar-logo {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px; font-size: .9rem; font-weight: 500;
  color: var(--text-muted); cursor: pointer; transition: all var(--transition);
  border-right: 3px solid transparent; text-decoration: none;
}
.nav-item svg {
  width: 18px; height: 18px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
.nav-item:hover { color: var(--brand); background: var(--brand-light); text-decoration: none; }
.nav-item.active {
  color: var(--brand); background: var(--brand-light);
  border-right-color: var(--brand); font-weight: 700;
}
.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}

/* Admin Main */
.admin-main {
  flex: 1; margin-right: var(--sidebar-w);
  display: flex; flex-direction: column; min-height: 100vh;
}
.admin-topbar {
  height: var(--topbar-h); background: var(--bg-card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-size: 1rem; font-weight: 700; flex: 1; }
.sidebar-toggle {
  display: none; background: none; border: none; cursor: pointer; padding: 4px;
}
.sidebar-toggle svg {
  width: 22px; height: 22px; stroke: var(--text); fill: none;
  stroke-width: 2; stroke-linecap: round;
}
.admin-content { padding: 24px; flex: 1; }

/* ─── Stats Grid ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-sm); transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-icon { font-size: 1.8rem; flex-shrink: 0; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }

/* ─── Charts ─────────────────────────────────────────────────────────────────── */
.charts-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.chart-card { flex: 1; min-width: 240px; }
.chart-wide { flex: 2; min-width: 360px; }

/* ─── Data Table ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border);
}
.data-table th {
  font-weight: 700; color: var(--text-muted); background: var(--bg);
  font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
}
.data-table tr:hover td { background: var(--bg); }
.data-table td:last-child { white-space: nowrap; }

.slug-cell { font-family: monospace; font-weight: 700; color: var(--brand); }
.original-cell {
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text-muted); font-size: .8rem;
}
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 99px; font-size: .72rem; font-weight: 700;
}
.badge-active  { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #fee2e2; color: #b91c1c; }
.badge-expired { background: #fef9c3; color: #854d0e; }
.action-btns { display: flex; gap: 6px; }

/* ─── View Toolbar ───────────────────────────────────────────────────────────── */
.view-toolbar {
  display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap;
}
.search-input { max-width: 340px; }
.select-input { width: auto; min-width: 140px; }
.select-sm { min-width: 100px; font-size: .8rem; padding: 6px 10px; }

/* ─── Pagination ─────────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; padding-top: 16px; flex-wrap: wrap;
}
.page-btn {
  min-width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--bg-card);
  color: var(--text); font-family: inherit; font-size: .85rem; cursor: pointer;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--brand); color: var(--brand); }
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ─── Login Overlay ──────────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0; background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 60%);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.login-box { width: 100%; max-width: 380px; margin: 24px; }
.login-logo {
  display: flex; align-items: baseline; justify-content: center;
  margin-bottom: 16px;
}
.login-box h2 { text-align: center; font-size: 1.2rem; margin-bottom: 20px; color: var(--text-muted); }
.login-box form { display: flex; flex-direction: column; gap: 14px; }

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer; font-size: 1.2rem;
  color: var(--text-muted); line-height: 1;
}
.modal-close:hover { color: var(--danger); }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; gap: 10px; padding-top: 8px; }

/* ─── Analytics ──────────────────────────────────────────────────────────────── */
.analytics-header {
  display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}
.analytics-title { font-size: 1.3rem; font-weight: 800; }
.analytics-original { font-size: .8rem; color: var(--text-muted); word-break: break-all; }

/* ─── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(100%); /* hidden off-screen to the right */
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .admin-main { margin-right: 0; }
  .sidebar-toggle { display: block; }

  .charts-row { flex-direction: column; }
  .chart-wide, .chart-card { min-width: unset; }

  .form-row { flex-direction: column; }
  .hero { padding: 40px 0 32px; }
  .features-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .modal { margin: 0; border-radius: var(--radius) var(--radius) 0 0; }
  .modal-overlay { align-items: flex-end; }
}

@media (max-width: 480px) {
  .features-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.3rem; }
  .admin-content { padding: 16px; }
}
