:root {
  --bg-primary: #111b21;
  --bg-secondary: #1f2c34;
  --bg-tertiary: #2a3942;
  --bg-hover: #182229;
  --green: #00a884;
  --green-light: #25d366;
  --green-bubble: #005c4b;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #546268;
  --border: #2a3942;
  --accent: #00a884;
  --red: #f15c6d;
  --yellow: #f0b429;
  --blue: #53bdeb;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 58px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
}

.brand-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
  flex-shrink: 0;
}
.brand-dot.connected { background: var(--green-light); }
.brand-dot.qr { background: var(--yellow); animation: pulse 1.4s ease-in-out infinite; }
.brand-dot.disconnected { background: var(--red); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.header-info {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
}

.header-name { font-weight: 600; color: var(--text-primary); }
.header-phone { font-family: monospace; }

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

.btn-logout {
  background: rgba(241, 92, 109, 0.12);
  border: 1px solid rgba(241, 92, 109, 0.4);
  color: var(--red);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-logout:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px; height: 32px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* Main layout */
.app-main {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  height: calc(100vh - 58px);
  margin-top: 58px;
  overflow: hidden;
}

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

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}
.badge-yellow { background: var(--yellow); color: #111; }

/* Buttons */
.btn-primary {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--green-light); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 9px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-sm {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s;
}
.btn-sm:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.empty-state {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 16px 8px;
}

/* Field */
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
}

input[type="text"], input[type="url"], input[type="datetime-local"], textarea, select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input[type="text"]:focus,
input[type="url"]:focus,
input[type="datetime-local"]:focus,
textarea:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 80px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 40px;
  text-align: center;
  max-width: 380px;
  width: 90%;
}
.modal-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; margin-bottom: 16px;
}
.logo-icon { font-size: 28px; }
.logo-text { font-size: 20px; font-weight: 700; color: var(--green-light); }
.modal-box h2 { font-size: 18px; margin-bottom: 8px; }
.modal-hint {
  font-size: 12px; color: var(--text-secondary);
  margin-bottom: 20px; line-height: 1.5;
}
#qr-container {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  display: flex; align-items: center; justify-content: center;
  min-height: 200px;
  margin-bottom: 14px;
}
#qr-image { max-width: 100%; border-radius: 4px; }
.qr-spinner {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: #333; font-size: 13px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #ddd;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.modal-status { font-size: 12px; color: var(--text-secondary); }
