/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  color: #222;
}

#app {
  min-height: 100vh;
}

/* ==================== RESPONSIVE CONTAINER ==================== */
.container {
  padding: 16px 24px 32px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 768px) {
  .container {
    padding: 12px 16px 20px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 8px 12px 16px;
  }
}

/* ==================== SECTION ==================== */
.section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 18px;
}

@media (max-width: 480px) {
  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .section-actions {
    width: 100%;
  }

  .section-actions button {
    width: 100%;
  }
}

.section-actions {
  display: flex;
  gap: 8px;
}

/* ==================== LAYOUT GRID ==================== */
.layout-grid {
  display: grid;
  grid-template-columns: 2fr 1.2fr;
  gap: 16px;
}

@media (max-width: 960px) {
  .layout-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

/* ==================== CARDS ==================== */
.card,
.unified-card {
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 12px 12px 14px;
  overflow-x: auto;
}

@media (max-width: 480px) {
  .card,
  .unified-card {
    padding: 10px;
  }
}

.card-header,
.card-subheader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

.card-header > div,
.card-subheader > div {
  font-size: 14px;
  font-weight: 500;
}

@media (max-width: 640px) {
  .card-header {
    flex-direction: column;
    align-items: stretch;
  }

  .card-header .input {
    width: 100%;
  }
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .card-footer {
    flex-direction: column;
  }

  .card-footer button {
    width: 100%;
  }
}

/* ==================== FORMS ==================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 12px;
}

@media (max-width: 480px) {
  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: #4b5563;
}

.input {
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  font-size: 13px;
  outline: none;
  width: 100%;
}

.input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
}

.checkbox-item {
  margin-top: 4px;
}

.checkbox-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

/* ==================== BUTTONS ==================== */
button {
  font-family: inherit;
}

.btn-primary,
.btn-secondary,
.btn-outline,
.btn-icon,
.btn-icon-small {
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
  background: transparent;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #f3f4f6;
  color: #111827;
  border-color: #d1d5db;
}

.btn-secondary:hover {
  background: #e5e7eb;
}

.btn-outline {
  background: #fff;
  color: #111827;
  border-color: #d1d5db;
}

.btn-outline:hover {
  background: #f3f4f6;
}

.btn-icon {
  padding: 4px 8px;
  font-size: 12px;
  background: #f3f4f6;
  border-color: #d1d5db;
}

.btn-icon:hover {
  background: #e5e7eb;
}

.btn-icon.danger {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.btn-icon.danger:hover {
  background: #fee2e2;
}

.btn-icon-small {
  padding: 0 4px;
  margin-left: 4px;
  font-size: 11px;
  background: transparent;
  border-color: transparent;
  color: #6b7280;
}

.btn-icon-small:hover {
  color: #111827;
}

/* ==================== TABLES ==================== */
.table-wrapper {
  max-height: 420px;
  overflow-x: auto;
  overflow-y: auto;
  border-radius: 4px;
  border: 1px solid #e5e7eb;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px;
}

@media (max-width: 640px) {
  table {
    min-width: 500px;
  }
}

th,
td {
  padding: 6px 8px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}

th {
  background: #f9fafb;
  font-weight: 500;
  font-size: 12px;
  color: #4b5563;
  position: sticky;
  top: 0;
  z-index: 10;
}

tr:last-child td {
  border-bottom: none;
}

.actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.empty-row {
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
  padding: 20px !important;
}

.muted {
  color: #9ca3af;
  font-size: 12px;
}

/* ==================== BADGES ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-info {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-proxy {
  background: #f3f4f6;
  color: #374151;
}

/* ==================== PROXY ASSIGNMENT ==================== */
.proxy-assign {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.proxy-assign-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.proxy-assign-row select {
  flex: 1;
  min-width: 120px;
}

.assigned-list {
  font-size: 12px;
}

.proxy-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* ==================== PAGINATION ==================== */
.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .pagination {
    justify-content: center;
  }
}

.pagination button {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  cursor: pointer;
  transition: all 0.2s;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: default;
}

.pagination-info {
  color: #6b7280;
}

.pagination-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.current-page {
  font-weight: 500;
  color: #2563eb;
}

/* ==================== TABLE FOOTER ==================== */
.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
  flex-wrap: wrap;
  gap: 12px;
}

@media (max-width: 768px) {
  .table-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .footer-left,
  .footer-right {
    justify-content: center;
  }
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-right {
  display: flex;
  align-items: center;
}

.btn-download-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #10b981;
  color: white;
  border-color: #10b981;
}

.btn-download-all:hover {
  background: #059669;
  transform: translateY(-1px);
}

.records-info {
  font-size: 13px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 4px 10px;
  border-radius: 6px;
}

/* ==================== FIXED NOTIFICATIONS (بالا نریزه) ==================== */
.notif-container {
  position: fixed;
  top: 70px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  max-width: 380px;
  width: auto;
  pointer-events: none;
}

@media (max-width: 768px) {
  .notif-container {
    top: 60px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}

.notif {
  pointer-events: auto;
  min-width: 280px;
  max-width: 360px;
  background: #1f2937;
  color: #f9fafb;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  position: relative;
  display: flex;
  gap: 12px;
  backdrop-filter: blur(8px);
  animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .notif {
    min-width: auto;
    width: 100%;
    max-width: none;
    padding: 12px;
  }
}

.notif-icon {
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.notif-content {
  flex: 1;
  word-break: break-word;
  line-height: 1.4;
}

.notif-success {
  background: linear-gradient(135deg, #065f46, #047857);
  border-left: 4px solid #34d399;
}

.notif-error {
  background: linear-gradient(135deg, #991b1b, #b91c1c);
  border-left: 4px solid #f87171;
}

.notif-info {
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8);
  border-left: 4px solid #60a5fa;
}
.notif-auth {
  background: linear-gradient(135deg, #bcb3ab, #bdadad);
  border-left: 4px solid #0b010b;
}

.notif-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 0 0 0 12px;
  transition: width 0.05s linear;
}

/* حذف pagination قبلی و استفاده از جدید */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.pagination button,
.btn-page {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}

.pagination button:hover:not(:disabled),
.btn-page:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.pagination button:disabled,
.btn-page:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.current-page {
  font-weight: 600;
  color: #4f46e5;
  background: #eef2ff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
}

/* Responsive fixes for tables */
@media (max-width: 640px) {
  .table-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .footer-left {
    justify-content: space-between;
  }

  .pagination {
    justify-content: center;
  }

  .btn-download-all {
    width: 100%;
    justify-content: center;
  }
}
/* ==================== LOADING OVERLAY ==================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(20, 20, 20, 0.35);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-box {
  background: white;
  padding: 30px 40px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  text-align: center;
}

@media (max-width: 480px) {
  .loading-box {
    padding: 20px 30px;
    margin: 0 20px;
  }
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #eee;
  border-top: 4px solid #4f46e5;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: auto;
}

.loading-text {
  margin-top: 12px;
  font-size: 14px;
  color: #444;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== TABS CONTAINER ==================== */
.tabs-container {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 24px;
  max-width: 1600px;
  margin: 0 auto;
  flex-wrap: wrap;
  background: white;
}

@media (max-width: 768px) {
  .tabs {
    padding: 0 16px;
    gap: 2px;
  }
}

@media (max-width: 640px) {
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
}

/* Tab Buttons */
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  border-radius: 8px 8px 0 0;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .tab {
    padding: 10px 14px;
    font-size: 13px;
  }
}

@media (max-width: 640px) {
  .tab {
    padding: 10px 12px;
    font-size: 12px;
  }
}

.tab:hover {
  color: #4f46e5;
  background: #f3f4f6;
}

.tab.active {
  color: #4f46e5;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: #4f46e5;
  border-radius: 2px 2px 0 0;
}

/* Tab Badge */
.tab-badge {
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  line-height: 1;
  min-width: 18px;
  text-align: center;
}

/* User Info Section */
.user-avatar {
  margin-left: auto;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: default;
  transition: transform 0.2s;
}

@media (max-width: 768px) {
  .user-avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
}

.user-avatar:hover {
  transform: scale(1.05);
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  margin-left: 8px;
}

@media (max-width: 768px) {
  .user-name {
    display: none;
  }
}

/* Logout Button */
.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  margin-left: 12px;
  font-size: 13px;
  font-weight: 500;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

@media (max-width: 768px) {
  .logout-btn {
    padding: 4px 10px;
    font-size: 12px;
    margin-left: 8px;
  }
}

@media (max-width: 480px) {
  .logout-btn span:first-child {
    margin-right: 0;
  }

  .logout-btn span:last-child {
    display: none;
  }
}

.logout-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  transform: translateY(-1px);
}

.logout-btn:active {
  transform: translateY(0);
}

/* ==================== COOKIE TABLE SPECIFIC ==================== */
.cookie-table {
  width: 100%;
  table-layout: fixed;
  min-width: 800px;
}

@media (max-width: 1024px) {
  .cookie-table {
    display: block;
    overflow-x: auto;
  }
}

.cookie-name-cell,
.cookie-value-cell {
  padding: 8px 6px !important;
  vertical-align: middle;
  position: relative;
}

.cell-content {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.truncate-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.4;
}

.cookie-value {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: #2c3e50;
}

.copy-mini {
  flex-shrink: 0;
  padding: 2px 6px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.copy-mini:hover {
  background: #e0e0e0;
  transform: scale(1.05);
}

/* Hover effect for full text */
.cookie-name-cell:hover .truncate-text,
.cookie-value-cell:hover .truncate-text {
  position: absolute;
  background: #fff;
  z-index: 100;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  white-space: normal;
  word-break: break-all;
  max-width: 300px;
  left: 0;
  top: 100%;
  margin-top: 4px;
}

/* ==================== LOGIN PAGE ==================== */
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

@media (max-width: 480px) {
  .login-card {
    padding: 20px;
    margin: 0 16px;
  }
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
}

.login-footer {
  margin-top: 16px;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
}

.error-text {
  color: #b91c1c;
  font-size: 12px;
  margin-top: 6px;
}

/* ==================== UTILITIES ==================== */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  button,
  .tab,
  .btn-primary,
  .btn-secondary,
  .logout-btn {
    min-height: 44px;
  }

  .input,
  select,
  textarea {
    font-size: 16px;
  }
}