/* CSS Reset & Variables */
:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(23, 31, 51, 0.7);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-hover: rgba(30, 41, 67, 0.9);
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.25);
  
  --emerald: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.15);
  
  --purple: #8b5cf6;
  --purple-bg: rgba(139, 92, 246, 0.15);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: rgba(239, 68, 68, 0.15);

  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  
  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --backdrop-blur: blur(12px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.82);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  animation: fadeIn 0.25s ease-out;
}

/* Auth Card */
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.auth-icon {
  width: 64px;
  height: 64px;
  background: rgba(59, 130, 246, 0.12);
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px auto;
}

.auth-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.pin-input-group input {
  width: 100%;
  padding: 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 1.6rem;
  letter-spacing: 8px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

.pin-input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* App Shell Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
}

/* Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-bottom: 1px solid var(--bg-card-border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.header-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.header-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
}

.status-pulse-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Refresh rate selector */
.refresh-rate-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 0 10px 0 8px;
  height: 40px;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.refresh-rate-wrapper:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.refresh-rate-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.refresh-rate-select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0px center;
}

.refresh-rate-select option {
  background: #1e293b;
  color: var(--text-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px; /* Mobile touch size */
}

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

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

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

.btn-full { width: 100%; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.danger-icon:hover { color: var(--danger); }

/* Main Content & Sections */
.main-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--text-main);
}

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

.badge-count {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  margin-left: 6px;
}

/* Metrics Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

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

.metric-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.fill-blue { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.fill-purple { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.fill-emerald { background: linear-gradient(90deg, #10b981, #34d399); }
.fill-orange { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.fill-red { background: linear-gradient(90deg, #ef4444, #f87171); }

/* Per-core CPU rows */
.cpu-cores-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.cpu-core-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cpu-core-row .progress-bar-bg {
  margin-bottom: 0;
  height: 7px;
}

.cpu-core-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 18px;
  text-align: right;
  letter-spacing: 0.02em;
}

.cpu-core-pct {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}

.metric-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Services List */
.services-list, .containers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  transition: transform 0.15s ease, background 0.2s ease;
}

@media (min-width: 600px) {
  .item-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.item-card:hover {
  background: var(--bg-card-hover);
}

.item-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.status-badge-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-running { background: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.dot-stopped { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

.item-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-details-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.port-tag {
  font-size: 0.72rem;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 6px;
  padding: 2px 6px;
  display: inline-block;
  margin-top: 4px;
  width: fit-content;
}

.live-log-badge {
  font-size: 0.72rem;
  color: var(--emerald);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.small-dot {
  width: 8px;
  height: 8px;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

@media (min-width: 600px) {
  .item-actions {
    width: auto;
  }
}

.btn-action-sm {
  padding: 8px 12px;
  font-size: 0.82rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  flex: 1;
  justify-content: center;
}

@media (min-width: 600px) {
  .btn-action-sm {
    flex: initial;
  }
}

/* Danger Zone */
.danger-zone-card {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.danger-info h3 {
  font-size: 1rem;
  color: #fca5a5;
  margin-bottom: 4px;
}
.danger-info p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Confirm & Log Modals */
.confirm-card, .log-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 440px;
}

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

.modal-icon-badge {
  font-size: 2.2rem;
  margin-bottom: 12px;
}

.confirm-card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.confirm-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.log-card {
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

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

.log-body {
  background: #070a12;
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  max-height: 50vh;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.log-body pre {
  font-family: monospace;
  font-size: 0.8rem;
  color: #38bdf8;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  left: 20px;
  max-width: 400px;
  margin: 0 auto;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-card);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.3s ease-out;
}

.toast-success { border-left: 4px solid var(--emerald); }
.toast-error { border-left: 4px solid var(--danger); }

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

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

/* Skeleton Loading */
.skeleton-item {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 16px;
  text-align: center;
}
