:root {
  --bg-color: #0b1120;
  --card-bg: #1e293b;
  --card-border: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: env(safe-area-inset-top, 16px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 16px) env(safe-area-inset-left, 16px);
}

.app-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 0;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.35);
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(30, 41, 59, 0.7);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--card-border);
}

.status-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.status-pulse.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-pulse.offline {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

/* APK Download Card */
.apk-card {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 8px 24px -4px rgba(2, 132, 199, 0.2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.apk-card-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.apk-icon-box {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35);
  flex-shrink: 0;
}

.android-svg {
  width: 28px;
  height: 28px;
  color: #ffffff;
}

.apk-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.apk-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.apk-title {
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
}

.apk-version-badge {
  font-size: 10px;
  font-weight: 800;
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.apk-desc {
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.3;
}

.btn-download-apk {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #15803d, #22c55e);
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
  transition: transform 0.15s;
}

.btn-download-apk:active {
  transform: scale(0.98);
}

/* Dashboard Area */
.dashboard-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dashboard-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 2px;
}

.dashboard-header-row h2 {
  font-size: 18px;
  font-weight: 700;
  display: inline;
  margin-right: 8px;
}

.device-count-badge {
  font-size: 11px;
  font-weight: 700;
  background: #334155;
  color: #38bdf8;
  padding: 2px 8px;
  border-radius: 9999px;
}

.btn-add-device {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
  transition: transform 0.15s, opacity 0.15s;
}

.btn-add-device:active {
  transform: scale(0.96);
}

/* Empty Dashboard */
.empty-dashboard {
  background: var(--card-bg);
  border: 1.5px dashed var(--card-border);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-icon-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #0f172a;
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.empty-dashboard h3 {
  font-size: 16px;
  font-weight: 700;
}

.empty-dashboard p {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 280px;
  line-height: 1.4;
}

.btn-primary-sm {
  background: #0284c7;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}

/* Device Cards Grid */
.device-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.device-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.3);
  transition: border-color 0.2s;
}

.device-card.online {
  border-color: rgba(56, 189, 248, 0.4);
}

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

.device-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-status {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 9999px;
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.badge-status.offline {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.device-card-details {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.device-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #334155;
  padding-top: 12px;
}

.btn-device-relay {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--card-border);
  background: #0f172a;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-device-relay.active {
  background: linear-gradient(135deg, #15803d, #22c55e);
  color: white;
  border-color: #22c55e;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.4);
}

.btn-delete-device {
  background: transparent;
  border: none;
  font-size: 16px;
  padding: 8px 12px;
  cursor: pointer;
  opacity: 0.6;
}

.btn-delete-device:hover {
  opacity: 1;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  padding: 24px;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.highlight-text {
  color: var(--accent);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

/* Scanner Animation */
.scanner-status {
  background: #0f172a;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.radar-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.2);
  border: 2px solid var(--accent);
  animation: pulseRadar 1.5s infinite;
}

@keyframes pulseRadar {
  0% { transform: scale(0.8); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0.6; }
}

.scanner-status p {
  font-size: 13px;
  color: var(--text-muted);
}

/* Sonoff Host List */
.sonoff-hosts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.sonoff-host-item {
  background: #0f172a;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s;
}

.sonoff-host-item:hover, .sonoff-host-item:active {
  border-color: var(--accent);
  background: #1e293b;
}

.host-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.host-icon {
  font-size: 20px;
}

.host-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  display: block;
}

.host-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-select-host {
  background: #0284c7;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Manual Host Toggle */
.manual-host-toggle {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-align: center;
  padding: 4px 0;
}

.manual-host-box {
  display: none;
  gap: 8px;
}

.manual-host-box.open {
  display: flex;
}

.manual-host-box input {
  flex: 1;
}

/* Form inputs */
.form-group {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.field-hint {
  display: block;
  font-size: 11px;
  color: #38bdf8;
  margin-top: 4px;
}

input[type="text"], input[type="password"] {
  width: 100%;
  background: #0f172a;
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-main);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--accent);
}

.password-wrapper {
  position: relative;
}

.password-wrapper input {
  padding-right: 44px;
}

.pwd-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.7;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary {
  background: #334155;
  color: var(--text-main);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm {
  background: #0284c7;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Loader & Steps */
.provision-loader-area {
  background: #0f172a;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.loader-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #334155;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.steps-progress {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
  text-align: left;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.step-item.active {
  color: var(--accent);
  font-weight: 600;
}

.step-item.done {
  color: var(--success);
}

.step-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #1e293b;
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.step-item.active .step-dot {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
}

.step-item.done .step-dot {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 12px 0;
  font-size: 11px;
  color: var(--text-dim);
}
