/* FreeLinkShortner - Main Stylesheet */
:root {
  --primary: #6c63ff;
  --primary-dark: #574fd6;
  --primary-light: #ede9ff;
  --secondary: #ff6584;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --dark: #1e1b4b;
  --gray-900: #111827;
  --gray-800: #1f2937;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50: #f9fafb;
  --white: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.05);
  --shadow-lg: 0 25px 50px -12px rgba(108,99,255,.2);
  --transition: .2s ease;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; display: block; }
input, select, textarea, button { font-family: inherit; }

/* ===== LAYOUT ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.container-sm { max-width: 800px; margin: 0 auto; padding: 0 20px; }
.container-xs { max-width: 480px; margin: 0 auto; padding: 0 20px; }

/* ===== NAVBAR ===== */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 20px;
  position: sticky; top: 0; z-index: 1000;
  box-shadow: var(--shadow);
}
.navbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1200px; margin: 0 auto; height: 64px;
}
.navbar-brand {
  font-size: 1.4rem; font-weight: 800; color: var(--primary);
  display: flex; align-items: center; gap: 10px;
}
.navbar-brand img { width: 36px; height: 36px; border-radius: 8px; }
.navbar-brand .logo-icon {
  width: 36px; height: 36px; background: var(--primary);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1.1rem;
}
.navbar-nav { display: flex; align-items: center; gap: 8px; }
.navbar-nav a {
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-weight: 500; font-size: .9rem; color: var(--gray-600);
  transition: all var(--transition);
}
.navbar-nav a:hover, .navbar-nav a.active {
  background: var(--primary-light); color: var(--primary);
}
.navbar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: .875rem;
  border: none; cursor: pointer; transition: all var(--transition);
  white-space: nowrap; text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); color: var(--gray-700); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #16a34a; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-lg { padding: 13px 28px; font-size: 1rem; border-radius: var(--radius); }
.btn-xl { padding: 16px 36px; font-size: 1.1rem; border-radius: var(--radius); }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }

/* ===== CARDS ===== */
.card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
  padding: 18px 24px; border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3, .card-header h4 { font-size: 1rem; font-weight: 700; color: var(--gray-800); margin: 0; }
.card-body { padding: 24px; }
.card-footer { padding: 16px 24px; border-top: 1px solid var(--gray-100); background: var(--gray-50); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-weight: 600; font-size: .875rem; color: var(--gray-700); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm); font-size: .9rem; background: var(--white);
  color: var(--gray-800); transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,99,255,.1); }
.form-control::placeholder { color: var(--gray-400); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .8rem; color: var(--gray-500); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-prefix {
  padding: 10px 12px; background: var(--gray-100); border: 1.5px solid var(--gray-300);
  border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-size: .85rem; color: var(--gray-500); white-space: nowrap; display: flex; align-items: center;
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 18px; border-radius: var(--radius-sm); margin-bottom: 18px;
  font-size: .9rem; display: flex; align-items: flex-start; gap: 10px;
  border-left: 4px solid transparent;
}
.alert-success { background: #dcfce7; color: #166534; border-color: var(--success); }
.alert-error, .alert-danger { background: #fee2e2; color: #991b1b; border-color: var(--danger); }
.alert-warning { background: #fef3c7; color: #92400e; border-color: var(--warning); }
.alert-info { background: #dbeafe; color: #1e40af; border-color: var(--info); }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
table th {
  background: var(--gray-50); padding: 12px 16px; text-align: left;
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--gray-500); border-bottom: 2px solid var(--gray-200);
}
table td { padding: 14px 16px; border-bottom: 1px solid var(--gray-100); font-size: .9rem; vertical-align: middle; }
table tr:hover td { background: var(--gray-50); }
table tr:last-child td { border-bottom: none; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 50px; font-size: .75rem; font-weight: 600;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-gray { background: var(--gray-200); color: var(--gray-600); }

/* ===== STATS CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 28px; }
.stat-card {
  background: var(--white); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.purple { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.blue   { background: #dbeafe; color: var(--info); }
.stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-info h3 { font-size: 1.6rem; font-weight: 800; color: var(--gray-900); line-height: 1.2; }
.stat-info p { font-size: .8rem; color: var(--gray-500); font-weight: 500; margin-top: 2px; }

/* ===== DASHBOARD SIDEBAR ===== */
.dash-layout { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  width: 240px; background: var(--dark); padding: 20px 14px;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: var(--radius-sm); color: rgba(255,255,255,.65);
  font-weight: 500; font-size: .9rem; margin-bottom: 2px;
  transition: all var(--transition);
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: rgba(255,255,255,.1); color: white;
}
.sidebar-nav a i { width: 18px; text-align: center; }
.sidebar-sep { border: none; border-top: 1px solid rgba(255,255,255,.1); margin: 12px 0; }
.sidebar-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: rgba(255,255,255,.3); padding: 0 14px; margin: 10px 0 4px; }
.dash-main { flex: 1; padding: 28px; overflow-x: hidden; }
.dash-header { margin-bottom: 24px; }
.dash-header h2 { font-size: 1.4rem; font-weight: 800; color: var(--gray-900); }
.dash-header p { color: var(--gray-500); font-size: .9rem; margin-top: 4px; }

/* ===== HERO SECTION ===== */
.hero {
  background: linear-gradient(135deg, var(--dark) 0%, #312e81 100%);
  color: white; padding: 70px 20px; text-align: center;
}
.hero h1 { font-size: 2.8rem; font-weight: 900; line-height: 1.2; margin-bottom: 16px; }
.hero h1 span { color: #a5f3fc; }
.hero p { font-size: 1.1rem; opacity: .8; max-width: 500px; margin: 0 auto 36px; }
.hero-form {
  background: white; border-radius: var(--radius-lg); padding: 28px;
  max-width: 680px; margin: 0 auto; box-shadow: var(--shadow-lg);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 2000; display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; border-radius: var(--radius-lg); padding: 28px;
  max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); animation: fadeIn .2s ease;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.4rem; color: var(--gray-400); }
.modal-close:hover { color: var(--gray-700); }

/* ===== PAGINATION ===== */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 13px; border-radius: var(--radius-sm); font-size: .875rem;
  border: 1.5px solid var(--gray-200); color: var(--gray-700); font-weight: 500;
}
.pagination a:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.pagination .current { background: var(--primary); border-color: var(--primary); color: white; }
.pagination .disabled { opacity: .4; pointer-events: none; }

/* ===== GROUP CARD ===== */
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.group-card {
  background: white; border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; transition: transform var(--transition), box-shadow var(--transition);
}
.group-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.group-card-img { height: 160px; background: linear-gradient(135deg,var(--primary),var(--secondary)); position: relative; overflow: hidden; }
.group-card-img img { width: 100%; height: 100%; object-fit: cover; }
.group-card-body { padding: 16px; }
.group-card-body h4 { font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.group-card-body p { font-size: .8rem; color: var(--gray-500); }
.group-card-footer {
  padding: 12px 16px; border-top: 1px solid var(--gray-100);
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ===== LINK CARD ===== */
.link-item {
  background: white; border-radius: var(--radius-sm); padding: 14px 18px;
  box-shadow: var(--shadow); margin-bottom: 10px;
  display: flex; align-items: center; gap: 14px;
  transition: box-shadow var(--transition);
}
.link-item:hover { box-shadow: var(--shadow-md); }
.link-item-img { width: 44px; height: 44px; border-radius: var(--radius-sm); object-fit: cover; background: var(--gray-100); flex-shrink: 0; }
.link-item-info { flex: 1; min-width: 0; }
.link-item-info h5 { font-weight: 700; font-size: .9rem; color: var(--gray-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-item-info .url { font-size: .8rem; color: var(--gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-item-info .short { font-size: .85rem; color: var(--primary); font-weight: 600; }
.link-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===== ANALYTICS ===== */
.chart-container { position: relative; height: 260px; margin: 20px 0; }
.country-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.country-bar-label { width: 120px; font-size: .85rem; color: var(--gray-700); flex-shrink: 0; }
.country-bar-track { flex: 1; height: 8px; background: var(--gray-200); border-radius: 4px; overflow: hidden; }
.country-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.country-bar-num { width: 40px; text-align: right; font-size: .8rem; color: var(--gray-500); }

/* ===== AUTH PAGES ===== */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, var(--dark) 0%, #312e81 100%); }
.auth-card { background: white; border-radius: var(--radius-lg); padding: 40px; max-width: 440px; width: 100%; box-shadow: var(--shadow-lg); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .brand { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.auth-logo p { color: var(--gray-500); font-size: .9rem; margin-top: 4px; }

/* ===== ADVANCED SETTINGS ===== */
.advanced-toggle { cursor: pointer; color: var(--primary); font-size: .85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; margin-top: 12px; user-select: none; }
.advanced-panel { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--gray-200); }
.advanced-panel.open { display: block; }

/* ===== TOGGLE SWITCH ===== */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.toggle-row:last-child { border-bottom: none; }
.toggle-label h5 { font-size: .875rem; font-weight: 600; color: var(--gray-800); }
.toggle-label p { font-size: .78rem; color: var(--gray-500); }
.toggle-switch { position: relative; display: inline-flex; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0; background: var(--gray-300);
  border-radius: 24px; transition: var(--transition);
}
.toggle-slider::before {
  position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ===== COPY BUTTON ===== */
.copy-btn { cursor: pointer; }
.copy-btn.copied { color: var(--success) !important; }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease; }

/* ===== UTILITIES ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-500); font-size: .85rem; }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; } .mb-4 { margin-bottom: 24px; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-100 { width: 100%; }
.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-title { font-size: 1.2rem; font-weight: 800; color: var(--gray-900); margin-bottom: 6px; }
.section-sub { font-size: .875rem; color: var(--gray-500); margin-bottom: 20px; }

/* ===== FOOTER ===== */
.footer { background: var(--dark); color: rgba(255,255,255,.5); text-align: center; padding: 20px; font-size: .85rem; }
.footer a { color: rgba(255,255,255,.7); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .hero h1 { font-size: 1.8rem; }
  .dash-layout { flex-direction: column; }
  .sidebar { width: 100%; padding: 10px; }
  .sidebar-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar-nav a { padding: 7px 12px; font-size: .8rem; }
  .dash-main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .navbar-toggle { display: block; }
  .navbar-nav { display: none; flex-direction: column; position: absolute; top: 64px; left: 0; right: 0; background: white; padding: 16px; border-bottom: 1px solid var(--gray-200); box-shadow: var(--shadow-md); }
  .navbar-nav.open { display: flex; }
  .auth-card { padding: 24px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .group-grid { grid-template-columns: 1fr; }
}

/* ===== EXTENDED MOBILE RESPONSIVE ===== */
@media (max-width: 900px) {
  /* Create link page grid */
  .create-link-grid { grid-template-columns: 1fr !important; }
  .create-link-grid > div:last-child .card { position: static !important; }
  /* Track page tabs */
  .tab-group > div { gap: 6px; }
  .tab-btn { font-size: .8rem; padding: 6px 12px; }
}

@media (max-width: 768px) {
  /* Dashboard header flex to column */
  .dash-header { flex-direction: column; align-items: flex-start; }
  /* Stats grid always 2 cols on tablet */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  /* Tables scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  /* Cards padding */
  .card-body { padding: 16px; }
  .card-header { padding: 14px 16px; }
  .card-footer { padding: 12px 16px; }
  /* Form rows stack */
  .form-row { grid-template-columns: 1fr !important; gap: 10px; }
  /* Buttons wrap */
  .btn-xl { padding: 12px 22px; font-size: .95rem; }
  /* Hero form */
  .hero-form { padding: 20px; }
  .hero { padding: 44px 16px; }
  /* Admin sidebar */
  .admin-sidebar-nav { display: flex; flex-wrap: wrap; gap: 4px; }
}

@media (max-width: 600px) {
  /* Full single column */
  .stats-grid { grid-template-columns: 1fr !important; }
  .group-grid  { grid-template-columns: 1fr !important; }
  /* Dash layout completely vertical */
  .dash-layout { flex-direction: column; }
  .sidebar { width: 100%; padding: 10px 14px; }
  .sidebar-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar-nav a { padding: 7px 11px; font-size: .8rem; }
  .sidebar-label { display: none; }
  .sidebar-sep { display: none; }
  .dash-main { padding: 14px; }
  /* Auth card */
  .auth-card { padding: 20px 16px; }
  /* Input group on mobile */
  .input-group { flex-direction: column; }
  .input-group .form-control { border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important; }
  .input-group .btn { border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important; width: 100%; justify-content: center; }
  .input-prefix { border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important; border-right: 1.5px solid var(--gray-300) !important; border-bottom: none !important; }
  /* Hero input group keep inline on small */
  .hero .input-group { flex-direction: row; }
  .hero .input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm) !important; }
  .hero .input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important; width: auto; }
  /* Tables min-width smaller */
  table { min-width: 480px; }
  /* Stat cards */
  .stat-card { padding: 14px; gap: 10px; }
  .stat-info h3 { font-size: 1.3rem; }
  /* Modal */
  .modal { padding: 20px 16px; }
  /* Pagination */
  .pagination { gap: 4px; }
  .pagination a, .pagination span { padding: 5px 10px; font-size: .8rem; }
  /* Navbar brand */
  .navbar-brand { font-size: 1.1rem; }
  /* Track page charts */
  .country-bar-label { width: 90px; font-size: .78rem; }
}

/* ===== STATIC PAGES MOBILE ===== */
@media (max-width: 768px) {
  .static-hero h1 { font-size: 1.5rem; }
  .static-body { padding: 28px 16px 44px; }
  .static-body h2 { font-size: 1.1rem; }
}

/* ===== FOOTER MOBILE ===== */
@media (max-width: 768px) {
  footer > div:first-child > div:first-child:not(style) {
    grid-template-columns: 1fr 1fr !important;
  }
}
@media (max-width: 480px) {
  footer > div:first-child > div:first-child:not(style) {
    grid-template-columns: 1fr !important;
  }
}
