/* ================================================================
   Preferencias globais: tema e instalacao como app
   ================================================================ */

:root,
html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-2: #ffffff;
  --card: #ffffff;
  --card-2: #eef2f7;
  --card-hover: #f1f5f9;
  --border: rgba(15,23,42,0.12);
  --border-hover: rgba(15,23,42,0.22);
  --text: #101828;
  --muted: rgba(15,23,42,0.58);
  --muted-2: rgba(15,23,42,0.42);
  --accent-dim: rgba(37,99,235,0.12);
  --danger-dim: rgba(239,68,68,0.11);
  --success-dim: rgba(34,197,94,0.13);
  --warning-dim: rgba(245,158,11,0.16);

  --surface-1: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --surface-4: #e2e8f0;
  --border-md: rgba(15,23,42,0.18);
  --text-1: #101828;
  --text-2: #475467;
  --text-3: #667085;
  --primary-glow: rgba(37,99,235,0.16);
}

html[data-theme="light"] body {
  background: #f5f7fb !important;
  color: var(--text, var(--text-1));
}

html[data-theme="light"] .navbar {
  background: rgba(255,255,255,0.88);
}

body.app-pref-open .navbar {
  z-index: 3900;
  overflow: visible;
}

html[data-theme="light"] .glass,
html[data-theme="light"] .card,
html[data-theme="light"] .list-row,
html[data-theme="light"] .ronda-block,
html[data-theme="light"] .modal,
html[data-theme="light"] .modal-box,
html[data-theme="light"] .config-item,
html[data-theme="light"] .proj-item {
  box-shadow: 0 10px 30px rgba(15,23,42,0.06);
}

html[data-theme="light"] .sidebar,
html[data-theme="light"] .mobile-sidebar-toggle,
html[data-theme="light"] .mobile-sidebar-close {
  box-shadow: 0 18px 44px rgba(15,23,42,0.12);
}

html[data-theme="light"] .input,
html[data-theme="light"] textarea.input,
html[data-theme="light"] select.input,
html[data-theme="light"] input,
html[data-theme="light"] textarea,
html[data-theme="light"] select {
  background-color: #ffffff;
  color: var(--text, var(--text-1));
}

html[data-theme="light"] select.input option {
  background: #ffffff;
  color: #101828;
}

.app-preferences {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.app-preferences--navbar {
  position: static;
  width: auto;
  height: auto;
  transform: none;
}

.app-preferences--navbar.is-open {
  z-index: 3901;
}

.app-pref-desktop {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-preferences--sidebar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 6px;
}

.app-pref-toggle {
  position: absolute;
  left: 50%;
  top: 0;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  display: none;
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 999px;
  background: var(--card, rgba(255,255,255,0.04));
  color: var(--muted, var(--text-2, rgba(255,255,255,0.58)));
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 8px 22px rgba(0,0,0,0.26);
  transform: translate(-50%, -50%);
}

.app-pref-toggle:hover,
.app-preferences--navbar.is-open .app-pref-toggle {
  color: var(--text, var(--text-1, #e8e8e8));
  border-color: var(--border-hover, rgba(255,255,255,0.18));
  background: var(--card-hover, var(--card, rgba(255,255,255,0.07)));
}

.app-pref-chevron {
  display: block;
  font-size: 21px;
  line-height: 1;
  transform: translateY(-3px);
}

.app-pref-panel {
  position: fixed;
  top: 68px;
  left: 50%;
  z-index: 3902;
  width: min(420px, calc(100vw - 24px));
  min-width: 0;
  transform: translateX(-50%);
  display: none;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: var(--radius-sm, 8px);
  background: var(--bg-2, var(--surface-1, #111));
  box-shadow: 0 18px 44px rgba(0,0,0,0.34);
}

.app-preferences--navbar.is-open .app-pref-panel {
  display: grid;
}

.app-pref-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.theme-choice,
.install-app-card {
  min-height: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: var(--radius-sm, 8px);
  background: var(--card, rgba(255,255,255,0.04));
  color: var(--text, var(--text-1, #e8e8e8));
  font: inherit;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.theme-choice span,
.install-app-card span {
  font-size: 13px;
  font-weight: 700;
}

.theme-choice small,
.install-app-card small {
  font-size: 10.5px;
  color: var(--muted, var(--text-2, rgba(255,255,255,0.58)));
}

.theme-choice:hover,
.install-app-card:hover,
.theme-choice.active {
  border-color: var(--accent, #3b82f6);
  background: var(--accent-dim, rgba(59,130,246,0.14));
}

.theme-select,
.install-app-btn {
  min-height: 34px;
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: var(--radius-sm, 8px);
  background: var(--card, rgba(255,255,255,0.04));
  color: var(--text, var(--text-1, #e8e8e8));
  font: inherit;
  font-size: 12.5px;
}

.theme-select {
  padding: 0 34px 0 10px;
  cursor: pointer;
}

.install-app-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  cursor: pointer;
  text-decoration: none;
}

.install-app-btn.is-visible {
  display: inline-flex;
}

.install-app-card {
  padding: 0;
  display: none;
}

.install-app-card.is-visible {
  display: flex;
}

.app-preferences--sidebar .theme-select,
.app-preferences--sidebar .install-app-btn {
  width: 100%;
}

.app-preferences--navbar .theme-select,
.app-preferences--navbar .install-app-btn {
  width: auto;
}

.app-pref-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 4000;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  border-radius: var(--radius-sm, 8px);
  background: var(--bg-2, var(--surface-1, #111));
  color: var(--text, var(--text-1, #e8e8e8));
  box-shadow: 0 18px 44px rgba(0,0,0,0.32);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.app-pref-toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 820px) {
  body.app-pref-open .navbar {
    overflow: visible;
  }

  .app-preferences--navbar {
    position: absolute;
    left: 50%;
    bottom: 0;
    z-index: 70;
    width: 0;
    height: 0;
    transform: translateX(-50%);
  }

  .app-preferences--navbar.is-open {
    z-index: 3901;
  }

  .app-pref-desktop {
    display: none;
  }

  .app-pref-toggle {
    display: inline-flex;
  }

  .app-pref-panel {
    top: 68px;
    left: 50%;
    right: auto;
    width: min(360px, calc(100vw - 24px));
    min-width: 0;
    transform: translateX(-50%);
    padding: 8px;
    border-radius: 12px;
  }

  .app-pref-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(50px, auto);
    gap: 6px;
  }

  .theme-choice,
  .install-app-card {
    min-height: 50px;
    border-radius: 9px;
    gap: 1px;
  }

  .theme-choice span,
  .install-app-card span {
    font-size: 12px;
  }

  .theme-choice small,
  .install-app-card small {
    font-size: 9px;
  }
}