:root {
  --bg-dark: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.7);
  --border-color: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.1) 0px, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px;
}

.app-container {
  width: 100%;
  max-width: 1100px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  color: var(--primary);
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
}

/* Login Page Styling */
.login-wrapper {
  width: 100%;
  min-height: 80vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 32px 28px;
}

.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 24px;
}

.login-header .logo-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

.login-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  text-align: center;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

.main-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-header {
  margin-bottom: 20px;
}

.card-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 4px;
}

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

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.field-hint code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

input[type="text"],
input[type="password"] {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

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

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

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

.btn-warning {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.btn-warning:hover {
  background: var(--warning);
  color: #000;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  padding: 8px;
  border-radius: 8px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.icon {
  width: 18px;
  height: 18px;
}

.button-group {
  display: flex;
  gap: 12px;
}

.badge-optional {
  font-size: 0.7rem;
  background: var(--warning);
  color: #000;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.info-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.banner-icon {
  width: 20px;
  height: 20px;
  color: var(--primary);
  flex-shrink: 0;
}

/* Table */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.badge-not-found {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.peer-cache-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.action-cell {
  display: flex;
  gap: 8px;
}

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Modal Popup Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.modal-container {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  padding: 24px;
  animation: scaleUp 0.2s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 16px;
}

.btn-close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.3s ease;
}

.toast-success {
  background: #059669;
}

.toast-error {
  background: #dc2626;
}

@keyframes slideIn {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==================================================
   MOBILE & TABLET RESPONSIVE STYLES
   ================================================== */

@media (max-width: 768px) {
  body {
    padding: 12px 8px;
  }

  .app-container {
    width: 100%;
    max-width: 100%;
    padding: 0;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
  }

  .header-status {
    align-self: flex-start;
  }

  .logo-icon {
    width: 32px;
    height: 32px;
  }

  .app-header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .main-content {
    gap: 16px;
    width: 100%;
  }

  .card {
    padding: 16px 14px;
    border-radius: 12px;
    width: 100%;
  }

  .card-header h2 {
    font-size: 1.1rem;
  }

  .card-header p {
    font-size: 0.8rem;
  }

  .auth-form {
    width: 100%;
    gap: 14px;
  }

  .form-group {
    width: 100%;
  }

  /* Font-size 16px prevents iOS Safari auto-zoom on focus */
  input[type="text"],
  input[type="password"] {
    width: 100%;
    font-size: 1rem;
    padding: 12px 14px;
  }

  .btn:not(.btn-icon) {
    width: 100%;
    min-height: 46px;
    padding: 10px 16px;
    font-size: 0.95rem;
    justify-content: center;
  }

  .btn-icon {
    width: auto;
    padding: 10px 14px;
  }

  .button-group {
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }

  .button-group .btn {
    width: 100%;
  }

  .action-cell {
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }

  .action-cell .btn {
    width: 100%;
    justify-content: center;
  }

  /* Mobile Toast positioning */
  .toast-container {
    bottom: 16px;
    left: 16px;
    right: 16px;
  }

  .toast {
    width: 100%;
    text-align: center;
  }
}

@media (max-width: 640px) {
  body {
    padding: 8px 4px;
  }

  .card {
    padding: 14px 10px;
  }

  /* Transform table to clean mobile card view */
  .table-responsive {
    overflow-x: visible;
  }

  .data-table, 
  .data-table thead, 
  .data-table tbody, 
  .data-table th, 
  .data-table td, 
  .data-table tr {
    display: block;
    width: 100%;
  }

  .data-table thead tr {
    display: none;
  }

  .data-table tbody tr {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .data-table td {
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    font-size: 0.875rem;
  }

  .data-table td:last-child {
    border-bottom: none;
    flex-direction: column;
    align-items: stretch;
    padding-top: 12px;
  }

  .data-table td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    margin-right: 12px;
  }

  .data-table td[data-label="Actions"]::before {
    display: none;
  }
}
