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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1117;
  color: #e1e4e8;
  min-height: 100vh;
}

header {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  color: #f0f6fc;
}

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

.stat {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #21262d;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  user-select: none;
}

.stat:hover {
  background: #30363d;
}

.stat.stat-active {
  box-shadow: 0 0 0 2px #58a6ff;
  background: #30363d;
}

.stat-online { color: #3fb950; }
.stat-offline { color: #f85149; }
.stat-unknown { color: #8b949e; }

.toolbar {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid #21262d;
  background: #0f1117;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.sort-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sort-label {
  font-size: 12px;
  color: #8b949e;
  margin-right: 2px;
}

.sort-btn.active {
  box-shadow: 0 0 0 2px #58a6ff;
  background: #30363d;
}

.btn {
  padding: 6px 14px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #21262d;
  color: #c9d1d9;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.5;
}

.btn:hover {
  background: #30363d;
}

.btn-primary {
  background: #238636;
  border-color: #2ea043;
  color: #fff;
}

.btn-primary:hover {
  background: #2ea043;
}

.btn-danger {
  background: #da3633;
  border-color: #f85149;
  color: #fff;
}

.btn-danger:hover {
  background: #f85149;
}

.btn-sm {
  padding: 3px 8px;
  font-size: 12px;
}

.search-input, .filter-select {
  padding: 6px 10px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
  color: #c9d1d9;
  font-size: 13px;
}

.search-input { width: 200px; }

.device-grid {
  padding: 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.device-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s;
}

.device-card:hover {
  border-color: #484f58;
}

.device-card.online {
  border-left: 3px solid #3fb950;
}

.device-card.offline {
  border-left: 3px solid #f85149;
}

.device-card.unknown {
  border-left: 3px solid #484f58;
}

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

.device-name {
  font-weight: 600;
  font-size: 14px;
  color: #f0f6fc;
}

.device-status {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

.device-status.online {
  background: rgba(63, 185, 80, 0.15);
  color: #3fb950;
}

.device-status.offline {
  background: rgba(248, 81, 73, 0.15);
  color: #f85149;
  cursor: pointer;
}

.device-status.offline.blink {
  animation: blink-offline 1s ease-in-out infinite;
}

@keyframes blink-offline {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.device-status.unknown {
  background: rgba(139, 148, 158, 0.15);
  color: #8b949e;
}

.device-info {
  font-size: 12px;
  color: #8b949e;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-duration {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 0;
}

.device-duration.online {
  color: #3fb950;
}

.device-duration.offline {
  color: #f85149;
}

.device-ip {
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: #c9d1d9;
}

.device-group {
  font-style: italic;
}

.device-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 24px;
  width: 90%;
  max-width: 440px;
}

.modal-content h2 {
  margin-bottom: 16px;
  font-size: 18px;
  color: #f0f6fc;
}

.modal-content label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: #8b949e;
}

.modal-content input[type="text"],
.modal-content input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
  color: #c9d1d9;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
}

.export-options {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.hint {
  font-size: 12px;
  color: #8b949e;
  margin-bottom: 12px;
}

#import-result {
  margin-top: 12px;
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
}

#import-result.success {
  background: rgba(63, 185, 80, 0.15);
  color: #3fb950;
}

#import-result.error {
  background: rgba(248, 81, 73, 0.15);
  color: #f85149;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: #484f58;
}

.empty-state h2 {
  font-size: 18px;
  margin-bottom: 8px;
  color: #8b949e;
}

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

#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 80vh;
  overflow-y: auto;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #30363d;
  background: #161b22;
  color: #e1e4e8;
  font-size: 13px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.3s ease;
}

.toast-online {
  border-left: 4px solid #3fb950;
}

.toast-offline {
  border-left: 4px solid #f85149;
}

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.toast-online .toast-icon {
  color: #3fb950;
}

.toast-offline .toast-icon {
  color: #f85149;
}

.toast-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.toast-body strong {
  color: #f0f6fc;
}

.toast-detail {
  color: #8b949e;
  font-size: 12px;
}

.toast-close {
  background: none;
  border: none;
  color: #484f58;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.toast-close:hover {
  color: #c9d1d9;
}

.toast-fade {
  opacity: 0;
  transition: opacity 0.4s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
}

.nav-tab {
  padding: 6px 14px;
  border-radius: 6px;
  color: #8b949e;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-tab:hover {
  background: #21262d;
  color: #c9d1d9;
}

.nav-tab.active {
  background: #21262d;
  color: #f0f6fc;
}

.device-card {
  cursor: pointer;
}

.device-uptime {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.uptime-badge {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

.uptime-badge-label {
  font-size: 11px;
  color: #8b949e;
}

.uptime-good {
  background: rgba(63, 185, 80, 0.15);
  color: #3fb950;
}

.uptime-warn {
  background: rgba(210, 153, 34, 0.15);
  color: #d29922;
}

.uptime-bad {
  background: rgba(248, 81, 73, 0.15);
  color: #f85149;
}

.uptime-insufficient {
  background: rgba(139, 148, 158, 0.1);
  color: #484f58;
}

.uptime-row-insufficient .uptime-label {
  color: #484f58;
}

.uptime-bar-grey {
  height: 100%;
  background: #30363d;
}

.modal-content-wide {
  max-width: 640px;
}

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

.detail-header h2 {
  margin-bottom: 4px;
}

.detail-ip {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  color: #8b949e;
}

.detail-uptime-section {
  margin-bottom: 24px;
}

.detail-uptime-section h3,
.detail-outage-section h3 {
  font-size: 14px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.uptime-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.uptime-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.uptime-label {
  font-size: 13px;
  color: #8b949e;
  min-width: 70px;
  text-align: right;
}

.uptime-bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  flex: 1;
  background: #21262d;
}

.uptime-bar-up {
  height: 100%;
  background: #3fb950;
  transition: width 0.3s;
}

.uptime-bar-down {
  height: 100%;
  background: #f85149;
  transition: width 0.3s;
}

.uptime-pct {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  min-width: 70px;
  text-align: right;
}

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

.detail-outage-header h3 {
  margin-bottom: 0;
}

.outage-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.outage-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #0d1117;
  border: 1px solid #21262d;
  border-radius: 6px;
  font-size: 13px;
}

.outage-times {
  display: flex;
  align-items: center;
  gap: 8px;
}

.outage-start, .outage-end {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  color: #c9d1d9;
}

.outage-arrow {
  color: #484f58;
}

.outage-ongoing {
  color: #f85149;
  font-weight: 600;
}

.outage-duration {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  color: #f85149;
  white-space: nowrap;
}

.pagination {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  justify-content: center;
}

.pagination .btn-sm {
  min-width: 32px;
  text-align: center;
}
