/* ============================================
   GPS-Server 4.0 Modern Theme - Phase 2
   Mobile-Optimized Version
   ============================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --secondary: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #06b6d4;
  --dark: #0f172a;
  --light: #f8fafc;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark-mode {
  --text-primary: #f3f4f6;
  --text-secondary: #d1d5db;
  --border: #374151;
  --light: #1f2937;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--light);
  color: var(--text-primary);
  transition: var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.dark-mode {
  background: #111827;
}

/* ============================================
   HEADER & NAVIGATION
   ============================================ */

.navbar-modern {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: white;
  box-shadow: var(--shadow-sm);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 20px;
  transition: var(--transition);
}

body.dark-mode .navbar-modern {
  background: #1f2937;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 20px;
  margin-right: auto;
}

.navbar-brand img {
  height: 40px;
  width: auto;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: auto;
}

.navbar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-primary);
  padding: 8px;
  line-height: 1;
  width: 44px;
  height: 44px;
  min-height: 44px;
  min-width: 44px;
  border-radius: 6px;
  transition: var(--transition);
}

.navbar-toggle:active {
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .navbar-toggle:active {
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   SIDEBAR NAVIGATION
   ============================================ */

.sidebar-modern {
  position: fixed;
  left: 0;
  top: 64px;
  width: 250px;
  height: calc(100vh - 64px);
  background: white;
  overflow-y: auto;
  transition: var(--transition);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

body.dark-mode .sidebar-modern {
  background: #1f2937;
}

.sidebar-modern.active {
  transform: translateX(0);
}

/* Close sidebar on outside click (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.sidebar-overlay.active {
  display: block;
}

/* ============================================
   MAIN CONTAINER
   ============================================ */

.main-container {
  margin-top: 64px;
  padding: 20px;
  min-height: 100vh;
  transition: var(--transition);
}

.content-header {
  margin-bottom: 30px;
  padding: 0;
}

.content-header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================
   CARDS & COMPONENTS
   ============================================ */

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: var(--transition);
  overflow: hidden;
  position: relative;
}

body.dark-mode .stat-card {
  background: #1f2937;
  border-color: #374151;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.stat-card-title {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.stat-card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

/* ============================================
   DEVICE CARDS
   ============================================ */

.device-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: var(--transition);
  cursor: pointer;
}

body.dark-mode .device-card {
  background: #1f2937;
  border-color: #374151;
}

.device-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 15px;
}

.device-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.device-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.device-status.online {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.device-status.offline {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.device-status.idle {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.status-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

.device-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 15px;
}

.device-info-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.device-info-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.device-actions {
  display: flex;
  gap: 10px;
}

.device-action-btn {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: white;
  color: var(--primary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: var(--transition);
  min-height: 40px;
}

body.dark-mode .device-action-btn {
  background: #374151;
  border-color: #4b5563;
  color: var(--info);
}

.device-action-btn:active {
  background: var(--primary);
  color: white;
}

.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

/* ============================================
   ACTIVITY FEED
   ============================================ */

.activity-feed {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  max-height: 500px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.dark-mode .activity-feed {
  background: #1f2937;
  border-color: #374151;
}

.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  border-radius: 50%;
  font-size: 16px;
  flex-shrink: 0;
}

.activity-icon.success {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.activity-icon.warning {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.activity-icon.danger {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.activity-icon.info {
  background: rgba(6, 182, 212, 0.1);
  color: #0891b2;
}

.activity-content {
  flex: 1;
  min-width: 0;
}

.activity-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  word-break: break-word;
}

.activity-time {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ============================================
   BUTTONS & INPUTS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
  min-height: 40px;
  min-width: 40px;
  padding: 8px 16px;
  font-size: 14px;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn-secondary {
  background: var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #d1d5db;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  min-height: 32px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
  min-height: 48px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet and below */
@media (max-width: 1024px) {
  .main-container {
    margin-left: 0;
  }

  .sidebar-modern {
    transform: translateX(-100%);
    position: fixed;
    max-width: 100%;
    width: 70%;
  }

  .sidebar-modern.active {
    transform: translateX(0);
  }

  .navbar-toggle {
    display: flex;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

  .devices-grid {
    grid-template-columns: 1fr;
  }
}

/* Medium tablets and small screens */
@media (max-width: 768px) {
  .navbar-modern {
    padding: 0 16px;
  }

  .navbar-brand img {
    height: 32px;
  }

  .main-container {
    padding: 16px;
    padding-top: 80px;
  }

  .content-header h1 {
    font-size: 24px;
    margin-bottom: 20px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-card-value {
    font-size: 28px;
  }

  .stat-card-title {
    font-size: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
  }

  .device-card {
    padding: 16px;
  }

  .devices-grid {
    gap: 16px;
  }

  .device-info {
    gap: 8px;
  }

  .device-info-row {
    font-size: 13px;
  }

  .activity-feed {
    padding: 16px;
  }

  .navbar-menu {
    gap: 12px;
  }
}

/* Small mobile devices */
@media (max-width: 640px) {
  .navbar-modern {
    height: 56px;
    padding: 0 12px;
  }

  .navbar-brand img {
    height: 32px;
  }

  .navbar-brand span {
    display: none;
  }

  .main-container {
    margin-top: 56px;
    padding: 12px;
  }

  .content-header h1 {
    font-size: 20px;
  }

  .stat-card {
    padding: 12px;
    border-radius: 10px;
  }

  .stat-card-value {
    font-size: 24px;
  }

  .stat-card-title {
    font-size: 11px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }

  .device-card {
    padding: 12px;
  }

  .device-name {
    font-size: 16px;
  }

  .device-status {
    font-size: 11px;
    padding: 2px 8px;
  }

  .device-info {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .device-actions {
    flex-direction: column;
  }

  .device-action-btn {
    width: 100%;
  }

  .activity-feed {
    padding: 12px;
    max-height: 400px;
  }

  .activity-item {
    padding: 10px;
    gap: 10px;
  }

  .activity-icon {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    font-size: 14px;
  }

  .activity-title {
    font-size: 13px;
  }

  .activity-time {
    font-size: 11px;
  }

  .navbar-menu {
    gap: 8px;
  }

  .btn {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 13px;
  }

  .btn-sm {
    min-height: 32px;
    padding: 4px 8px;
    font-size: 11px;
  }
}

/* Very small phones */
@media (max-width: 480px) {
  .navbar-modern {
    height: 52px;
    padding: 0 8px;
  }

  .navbar-brand img {
    height: 28px;
  }

  .main-container {
    margin-top: 52px;
    padding: 8px;
  }

  .content-header h1 {
    font-size: 18px;
    margin-bottom: 12px;
  }

  .stat-card {
    padding: 10px;
    border-radius: 8px;
  }

  .stat-card-value {
    font-size: 20px;
  }

  .stat-card-title {
    font-size: 10px;
    letter-spacing: 0px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .device-card {
    padding: 10px;
  }

  .device-header {
    margin-bottom: 10px;
  }

  .device-name {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .device-info {
    gap: 4px;
    margin-bottom: 10px;
  }

  .device-info-row {
    font-size: 12px;
  }

  .device-actions {
    gap: 6px;
  }

  .device-action-btn {
    padding: 8px 10px;
    font-size: 12px;
    min-height: 36px;
  }

  .activity-feed {
    padding: 10px;
    max-height: 350px;
  }

  .activity-item {
    padding: 8px;
    gap: 8px;
  }

  .activity-icon {
    width: 32px;
    min-width: 32px;
    height: 32px;
    min-height: 32px;
    font-size: 13px;
  }

  .activity-title {
    font-size: 12px;
  }

  .activity-time {
    font-size: 10px;
  }

  .btn {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .navbar-menu {
    gap: 4px;
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

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

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.card-enter {
  animation: slideIn 0.3s ease-out;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

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

.mt-20 {
  margin-top: 20px;
}

.mb-20 {
  margin-bottom: 20px;
}

.flex {
  display: flex;
}

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

.gap-10 {
  gap: 10px;
}

.rounded {
  border-radius: 8px;
}

.shadow {
  box-shadow: var(--shadow);
}

/* ============================================
   ACCESSIBILITY & TOUCH
   ============================================ */

button, a, [role="button"] {
  -webkit-user-select: none;
  user-select: none;
}

input, textarea, select {
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

/* Prevent zoom on input focus */
@supports (-webkit-touch-callout: none) {
  input, textarea, select {
    font-size: 16px;
  }
}

/* Focus styles for accessibility */
button:focus, a:focus, [role="button"]:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .navbar-modern,
  .sidebar-modern,
  .navbar-toggle {
    display: none;
  }

  .main-container {
    margin-top: 0;
  }
}
