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

:root {
  --primary: #667eea;
  --primary-dark: #5568d3;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* Header */
.header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 20px 24px;
  margin: -24px -24px 24px -24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--gray-900);
}

.header-stats {
  display: flex;
  gap: 32px;
  font-size: 13px;
  color: var(--gray-600);
}

.header-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-stat-value {
  font-weight: 600;
  color: var(--gray-900);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--gray-200);
}

.tab-btn {
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--gray-600);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  position: relative;
  bottom: -1px;
}

.tab-btn:hover {
  color: var(--gray-900);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Cards */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-label {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

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

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

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

/* Device/Plan Cards */
.item-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.item-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.item-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.item-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
}

.item-card-subtitle {
  font-size: 13px;
  color: var(--gray-600);
  margin-top: 4px;
}

.item-card-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--gray-600);
  padding-top: 12px;
  border-top: 1px solid var(--gray-100);
}

/* Status Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-idle {
  background: var(--gray-100);
  color: var(--gray-700);
}

.badge-charging {
  background: #fef3c7;
  color: #92400e;
}

.badge-offline {
  background: #fee2e2;
  color: #991b1b;
}

.badge-active {
  background: #d1fae5;
  color: #065f46;
}

.badge-completed {
  background: var(--gray-100);
  color: var(--gray-700);
}

.badge-hashkey {
  background: #dbeafe;
  color: #1e40af;
}

.badge-blockchain {
  background: #e9d5ff;
  color: #6b21a8;
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.table td {
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover {
  background: var(--gray-50);
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-help {
  display: block;
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Modal */
/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

#addPlanModal {
  z-index: 1100;
}

#qrModal {
  z-index: 1100;
}

#planDetailModal {
  z-index: 1100;
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  margin: 20px;
}

.modal-content.modal-lg {
  max-width: 900px;
}

.modal-header {
  padding: 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-900);
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--gray-400);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: all 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-600);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: var(--gray-50);
}

.modal-section {
  margin-bottom: 24px;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 16px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 14px;
}

/* QR Code Display */
.qr-display {
  text-align: center;
  padding: 20px;
}

.qr-display img {
  max-width: 280px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  background: white;
  margin: 20px auto;
}

.qr-url {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 12px;
  font-family: 'Monaco', 'Menlo', monospace;
  word-break: break-all;
  color: var(--gray-700);
  margin-top: 16px;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

/* Button Group */
.btn-group {
  display: flex;
  gap: 8px;
}

/* Form Row */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Danger button */
.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

/* Success button */
.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #059669;
}

/* Badge variants */
.badge-failed {
  background: #fee2e2;
  color: #991b1b;
}

.badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-skipped {
  background: #fef3c7;
  color: #92400e;
}

.badge-paused {
  background: var(--gray-100);
  color: var(--gray-700);
}

.badge-running {
  background: #d1fae5;
  color: #065f46;
}

.badge-stopped {
  background: var(--gray-100);
  color: var(--gray-700);
}

.badge-replaced {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-expired {
  background: #fee2e2;
  color: #991b1b;
}

/* Config display */
.config-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  font-size: 13px;
}

.config-label {
  color: var(--gray-500);
  font-weight: 500;
}

.config-value {
  color: var(--gray-900);
  word-break: break-all;
}

/* Code block */
.code {
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Text utilities */
.text-muted {
  color: var(--gray-500);
}

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

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

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

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 16px;
  }

  .header {
    padding: 16px;
    margin: -16px -16px 16px -16px;
  }

  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .header-stats {
    flex-wrap: wrap;
    gap: 16px;
  }

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

  .item-card-meta {
    flex-direction: column;
    gap: 8px;
  }

  .modal-content {
    max-width: 100%;
  }
}
