/* ════════════════════════════════════════════════════════════════
   Wallee V2 – Stylesheet (Apple Design, 1:1 wie V1)
   ════════════════════════════════════════════════════════════════ */

:root {
  --primary-blue: #007AFF;
  --success-green: #34C759;
  --warning-orange: #FF9500;
  --error-red: #FF3B30;
  --label-primary: #000000;
  --label-secondary: #3C3C43;
  --label-tertiary: #3C3C4399;
  --separator: #C6C6C8;
  --background-primary: #FFFFFF;
  --background-secondary: #F2F2F7;
  --background-tertiary: #FFFFFF;
  --fill-quaternary: #F2F2F7;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.1);
  --border-radius: 12px;
  --border-radius-small: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  background-color: var(--background-secondary);
  color: var(--label-primary);
  line-height: 1.5;
  padding: 20px;
  min-height: 100vh;
}

.container { max-width: 1640px; margin: 0 auto; }

.header {
  text-align: center;
  margin-bottom: 32px;
}
.header h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--label-primary);
  margin-bottom: 8px;
}

/* ════════════════════════════════════════════════════════════════
   LOGIN OVERLAY (matching auth server design)
   ════════════════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  transition: opacity .3s ease;
}
.login-overlay.hidden { display: none !important; }
.login-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.login-card {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.08);
  padding: 48px 40px 40px;
  width: 400px;
  max-width: 92vw;
  text-align: center;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.login-logo {
  margin-bottom: 12px;
}
.login-logo-img {
  height: 32px;
  opacity: .85;
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
}
.login-subtitle {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 24px;
}
.login-input-wrap {
  margin-bottom: 16px;
}
.login-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  background: #f7f8fa;
  color: #1e293b;
  transition: border-color .2s;
  text-align: center;
}
.login-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .08);
}
.login-input.shake {
  animation: loginShake .4s ease;
}
@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.login-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  background: #2563eb;
  color: white;
  border: none;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  transition: background .2s;
}
.login-btn:hover:not(:disabled) { background: #1d4ed8; }
.login-btn:disabled {
  opacity: .6;
  cursor: wait;
}

.login-error-wrap {
  margin-top: 12px;
}
.login-error-wrap .message {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
}

.login-forgot {
  margin-top: 20px;
  font-size: 12px;
}
.login-forgot a {
  color: #64748b;
  text-decoration: none;
  transition: color .2s;
}
.login-forgot a:hover {
  color: #2563eb;
  text-decoration: underline;
}

/* ════════════════════════════════════════════════════════════════
   AUTH TOPBAR
   ════════════════════════════════════════════════════════════════ */
.auth-topbar {
  position: fixed;
  top: 12px; right: 12px;
  display: flex; gap: 8px; align-items: center;
  z-index: 9998;
}
.auth-topbar.hidden { display: none !important; }

.token-timer {
  background: var(--fill-quaternary);
  border-radius: var(--border-radius-small);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--label-primary);
  text-align: center;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.token-timer.warning {
  background: #FFF3CD;
  color: #856404;
  border: 1px solid #FFEAA7;
}
.token-timer.danger {
  background: #F8D7DA;
  color: #721C24;
  border: 1px solid #F5C6CB;
}

.user-badge,
.auth-user-badge {
  background: var(--fill-quaternary);
  border-radius: var(--border-radius-small);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--label-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}
.auth-user-badge:hover {
  background: rgba(0,122,255,0.1);
  color: var(--primary-blue);
}

.btn-logout {
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--border-radius-small);
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--primary-blue);
  color: white;
  font-family: inherit;
}
.btn-logout:hover { background: #0056CC; }

/* ════════════════════════════════════════════════════════════════
   MAIN GRID – 4 columns
   ════════════════════════════════════════════════════════════════ */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

@media (max-width: 1200px) {
  .main-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .main-grid { grid-template-columns: 1fr; }
}

.column {
  background: var(--background-tertiary);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  overflow: visible;
}

.column-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--separator);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
}
.column-header-connect {
  background: linear-gradient(135deg, #E8F5E8, #F0F9F0);
  border-bottom: 1px solid #D4E6D4;
}
.column-header-check {
  background: linear-gradient(135deg, #FFF8E1, #FFFDF0);
  border-bottom: 1px solid #F7E0A3;
}
.column-header-disconnect {
  background: linear-gradient(135deg, #FDF2F2, #FEF7F7);
  border-bottom: 1px solid #F5D5D5;
}
.column-header-general {
  background: linear-gradient(135deg, #F0F4FF, #F8FAFF);
  border-bottom: 1px solid #D6E3FF;
}

.column-title {
  font-size: 18px;
  font-weight: 600;
  color: #000000;
}

.column-content {
  padding: 20px;
  position: relative;
}

/* ════════════════════════════════════════════════════════════════
   FORM ELEMENTS
   ════════════════════════════════════════════════════════════════ */
.form-group {
  margin-bottom: 20px;
  position: relative;
}
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--label-primary);
  margin-bottom: 6px;
}
.form-input, .form-select,
input[type="text"],
select {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid var(--separator);
  border-radius: var(--border-radius-small);
  background: var(--background-primary);
  color: var(--label-primary);
  transition: all 0.2s ease;
  position: relative;
  z-index: 10;
  font-family: inherit;
}
.form-input:focus, .form-select:focus,
input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--fill-quaternary);
  color: var(--label-tertiary);
  opacity: 0.6;
}

.form-textarea,
textarea {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid var(--separator);
  border-radius: var(--border-radius-small);
  background: var(--background-primary);
  color: var(--label-primary);
  min-height: 100px;
  resize: vertical;
  font-family: inherit;
  transition: all 0.2s ease;
}
textarea:focus {
  outline: none;
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}
textarea.invalid-serials {
  border-color: #ff3b30;
  background-color: #fff5f5;
  box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.1);
}

select {
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%233C3C43' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.info-text {
  font-size: 14px;
  color: var(--label-secondary);
}

/* ════════════════════════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-block;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  border: none;
  border-radius: var(--border-radius-small);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-decoration: none;
  font-family: inherit;
}
.btn-primary {
  background: var(--primary-blue);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: #0056CC; }
.btn-success {
  background: var(--success-green);
  color: white;
}
.btn-success:hover:not(:disabled) { background: #2EB84C; }
.btn-danger {
  background: var(--error-red);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: #E0332B; }
.btn-secondary {
  background: var(--fill-quaternary);
  color: var(--label-primary);
  border: 1px solid var(--separator);
}
.btn-secondary:hover:not(:disabled) { background: var(--separator); }

.btn-manual-active {
  background: #FF8C00;
  color: white;
}
.btn-manual-active:hover:not(:disabled) {
  background: #E67E00;
}

.btn:disabled, .btn[disabled] {
  background: var(--separator) !important;
  color: var(--label-tertiary) !important;
  cursor: not-allowed !important;
}

.btn-full { width: 100%; }
.btn-small { padding: 8px 16px; font-size: 14px; }
.btn-outline {
  background: var(--background-primary);
  color: var(--label-primary);
  border: 1px solid var(--separator);
}
.btn-outline:hover:not(:disabled) { background: var(--fill-quaternary); }

/* ════════════════════════════════════════════════════════════════
   SEARCH DROPDOWN (Spaces)
   ════════════════════════════════════════════════════════════════ */
.search-container {
  position: relative;
}
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--background-primary);
  border: 1px solid var(--separator);
  border-top: none;
  border-radius: 0 0 var(--border-radius-small) var(--border-radius-small);
  box-shadow: var(--card-shadow);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
}
.search-dropdown.hidden { display: none !important; }

.search-option {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--fill-quaternary);
  transition: background-color 0.2s ease;
}
.search-option:hover {
  background: var(--fill-quaternary);
}
.search-option:last-child {
  border-bottom: none;
}
.search-option-name {
  font-weight: 500;
  font-size: 13px;
  color: var(--label-primary);
}
.search-option-id {
  font-size: 11px;
  color: var(--label-secondary);
  margin-top: 1px;
}

/* ════════════════════════════════════════════════════════════════
   MESSAGES
   ════════════════════════════════════════════════════════════════ */
.message {
  padding: 12px 16px;
  border-radius: var(--border-radius-small);
  font-size: 14px;
  margin-top: 12px;
  display: flex;
  align-items: center;
}
.message-success {
  background: rgba(52, 199, 89, 0.1);
  color: var(--success-green);
  border: 1px solid rgba(52, 199, 89, 0.2);
}
.message-error {
  background: rgba(255, 59, 48, 0.1);
  color: var(--error-red);
  border: 1px solid rgba(255, 59, 48, 0.2);
}
.message-info {
  background: rgba(0, 122, 255, 0.1);
  color: var(--primary-blue);
  border: 1px solid rgba(0, 122, 255, 0.2);
}
.message-warning {
  background: rgba(255, 149, 0, 0.1);
  color: var(--warning-orange);
  border: 1px solid rgba(255, 149, 0, 0.2);
}

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--separator);
  border-radius: 50%;
  border-top-color: var(--primary-blue);
  animation: spin 1s ease-in-out infinite;
  margin-right: 8px;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ════════════════════════════════════════════════════════════════
   RESULT CARDS (Check / Info)
   ════════════════════════════════════════════════════════════════ */
.info-card {
  background: var(--fill-quaternary);
  border-radius: var(--border-radius-small);
  padding: 16px;
  margin-bottom: 20px;
}
.info-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.info-card .card-timestamp {
  font-size: 11px;
  color: var(--label-tertiary);
}
.info-card .card-close {
  border: none; background: transparent;
  font-size: 16px; line-height: 1; cursor: pointer;
  color: var(--label-tertiary); padding: 0;
}
.info-card .card-close:hover { color: var(--error-red); }

.info-card .space-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--label-primary);
}
.info-card .device-count {
  font-size: 13px;
  color: var(--label-secondary);
  margin: 4px 0 8px;
}
.info-card .device-list {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--label-primary);
}
.info-card .not-found-section {
  border-left: 3px solid var(--warning-orange);
  padding: 10px 12px;
  margin-top: 10px;
  border-radius: 0 var(--border-radius-small) var(--border-radius-small) 0;
  background: rgba(255, 149, 0, 0.08);
}
.info-card .not-found-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--warning-orange);
}
.info-card .not-found-list {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  color: var(--label-secondary);
  margin-top: 4px;
}

/* Compact padding for check result blocks */
#checkResults {
  background: none;
  box-shadow: none;
  padding: 0;
  margin: 14px 0 0 0;
}
#checkResults > .info-card {
  margin: 12px 0;
  padding: 12px;
}
#checkResults > .info-card .info-card {
  margin: 8px 0 0 0;
  padding: 4px 8px 4px 12px;
}

/* ════════════════════════════════════════════════════════════════
   CONFLICT MODAL
   ════════════════════════════════════════════════════════════════ */
.conflict-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
.conflict-overlay.hidden { display: none !important; }

.conflict-modal {
  background: var(--background-tertiary);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  width: min(600px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}
.conflict-modal h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--label-primary);
  margin-bottom: 8px;
}
.conflict-modal .conflict-desc {
  font-size: 14px;
  color: var(--label-secondary);
  margin-bottom: 18px;
  line-height: 1.4;
}
.conflict-modal .conflict-list {
  margin: 16px 0;
}
.conflict-serial {
  background: var(--fill-quaternary);
  border-radius: var(--border-radius-small);
  padding: 12px 16px;
  margin-bottom: 8px;
  border-left: 4px solid var(--warning-orange);
  display: flex;
  align-items: center;
  gap: 10px;
}
.conflict-serial input[type="checkbox"] {
  flex-shrink: 0;
  width: 20px; height: 20px;
  accent-color: var(--primary-blue);
}
.conflict-serial .serial-info {
  font-size: 14px;
  line-height: 1.4;
}
.conflict-serial .serial-number {
  font-weight: 600;
  font-size: 16px;
  color: var(--label-primary);
}
.conflict-serial .serial-detail {
  font-size: 14px;
  color: var(--label-secondary);
}

.conflict-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.conflict-actions .btn {
  flex: 1;
  min-width: 140px;
}

/* ════════════════════════════════════════════════════════════════
   STATUS BAR (bottom)
   ════════════════════════════════════════════════════════════════ */
.status-bar {
  background: var(--background-tertiary);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.status-center {
  display: flex;
  align-items: center;
  gap: 12px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.status-online {
  background: var(--success-green);
  animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.7);
  }
  50% {
    opacity: 0.8;
    box-shadow: 0 0 0 6px rgba(52, 199, 89, 0);
  }
}
.status-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--label-secondary);
}

/* Compact statistics in status bar */
.statistics-compact {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.statistics-title-compact {
  font-size: 10px;
  font-weight: 600;
  color: var(--label-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.statistics-numbers {
  display: flex;
  align-items: center;
  gap: 2px;
}
.stat-number {
  font-size: 12px;
  font-weight: 700;
  color: var(--label-primary);
  min-width: 20px;
  text-align: center;
}
.stat-separator {
  color: var(--separator);
  font-size: 10px;
}
.statistics-labels {
  display: flex;
  gap: 4px;
  font-size: 8px;
  color: var(--label-tertiary);
  font-weight: 500;
}
.statistics-labels span {
  min-width: 20px;
  text-align: center;
}
.statistics-right {
  align-items: center;
}

/* Copyright */
.copyright {
  text-align: center;
  margin-top: 12px;
  font-size: 10px;
  color: var(--label-tertiary);
}

/* ════════════════════════════════════════════════════════════════
   TOGGLE SWITCH (Auto-Forward)
   ════════════════════════════════════════════════════════════════ */
.toggle-row {
  margin-top: -4px;
  margin-bottom: 12px;
}
.toggle-row label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--label-primary);
}
.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-blue);
}

/* ════════════════════════════════════════════════════════════════
   HIDDEN
   ════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }
