:root {
  --bg: #0b1220;
  --panel: #121b2e;
  --panel-2: #0f1728;
  --line: #26314b;
  --text: #e8eefc;
  --muted: #9fb0d3;
  --accent: #63b3ff;
  --accent-strong: #63b3ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 10px 30px rgba(0,0,0,.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

img {
  display: block;
  max-width: 100%;
}

input, select, button {
  font: inherit;
}

.site-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 18px 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.session-badge-wrap {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.session-badge-label {
  color: var(--muted);
  font-size: 14px;
}

.session-badge {
  display: inline-block;
  min-width: 90px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: #0d1524;
  border-radius: 999px;
  font-family: Consolas, Monaco, monospace;
  letter-spacing: 1px;
}

.lang-select,
input[type="text"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #0d1524;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}


input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,179,255,.14);
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.card--centered {
  text-align: center;
}

.card-title {
  margin: 0 0 10px;
  font-size: 24px;
}

.card-subtitle {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 17px;
}

.card-hint {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.index-main {
  display: grid;
  gap: 20px;
}

.connect-card {
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.card-title--spaced {
  margin-bottom: 22px;
}

.card-subtitle--spaced {
  margin-bottom: 10px;
}

.connect-form--spaced {
  margin-top: 26px;
}

.input-label--center {
  text-align: center;
}

.connect-form {
  display: grid;
  gap: 14px;
  justify-items: center;
}

.input-label {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.session-input {
  width: 170px !important;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin: 0 auto;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 700;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease, transform .15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-outline-primary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-outline-primary:hover {
  background: var(--accent);
  color: #08111f;
}

.btn-outline-danger {
  background: transparent;
  color: #ff8d8d;
  border: 1px solid #ff8d8d;
}

.btn-outline-danger:hover {
  background: #ff8d8d;
  color: #260000;
}

.btn-sm {
  padding: 7px 11px;
  font-size: 13px;
}

.status-text {
  color: var(--muted);
  font-size: 14px;
  margin-top: 10px;
}

.log-card {
  min-height: 240px;
}

.log-card__header {
  margin-bottom: 12px;
}

.log-box {
  min-height: 180px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #08111f;
  color: #c7d2fe;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
}

.connect-main {
  display: grid;
  gap: 18px;
}

.provider-menu-section {
  padding: 16px;
}

.provider-menu-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
}

.provider-tile {
  appearance: none;
  border: 1px solid var(--line);
  background: #0d1524;
  color: var(--text);
  border-radius: 16px;
  padding: 14px 12px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform .15s ease, border-color .2s ease, background-color .2s ease;
}

.provider-tile:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.provider-tile.is-active {
  border-color: var(--accent);
  background: rgba(99,179,255,.08);
}

.provider-tile--danger.is-active,
.provider-tile--danger:hover {
  border-color: #ff8d8d;
}

.provider-tile__label {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
}

.provider-panel {
  min-height: 260px;
}

.provider-section {
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .24s ease, transform .24s ease;
}

.provider-section.is-active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
}

.form-field--full {
  grid-column: 1 / -1;
}

.form-field label,
.checkbox-row {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
}

.form-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.action-row {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.backup-actions {
  display: flex;
  margin-top: 6px;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.provider-section-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.hidden-config-row {
  margin-top: 10px;
}

.backup-progress {
  margin-bottom: 16px;
}

.progress-bar {
  margin-top: 6px;
  height: 16px;
  background: #0d1524;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .25s ease;
}

.masked-value {
  letter-spacing: 1px;
}

input[type="password"],
input.password-mask,
input.masked-readonly {
  background: #0d1524 !important;
  color: var(--text) !important;
  border: 1px solid var(--line) !important;
  border-radius: 12px !important;
  padding: 12px 14px !important;
  box-shadow: none !important;
  -webkit-text-fill-color: var(--text) !important;
  opacity: 1 !important;
}

input.masked-readonly {
  pointer-events: none;
}

input[readonly].masked-readonly {
  opacity: 1;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.device-providers__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.providers-list {
  display: grid;
  gap: 12px;
}

.provider-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #0d1524;
}

.provider-item__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.provider-item__name {
  font-weight: 700;
}

.provider-item__type {
  color: var(--muted);
  font-size: 13px;
}

.provider-item__meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.footer {
  margin-top: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.topbar--stacked {
  display: block;
}

.topbar-actions--right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.flag-picker {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.flag-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #0d1524;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color .2s ease, background-color .2s ease, transform .15s ease;
  font-size: 18px;
  line-height: 1;
}

.flag-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.flag-btn.is-active {
  border-color: var(--accent);
  background: rgba(99,179,255,.12);
}

.input-label--centered {
  display: block;
  width: 100%;
  text-align: center;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.device-providers-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1.15fr);
  gap: 18px;
  align-items: start;
}

.device-info__grid {
  display: grid;
  gap: 12px;
}

.device-info__item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d1524;
}

.device-info__label {
  color: var(--muted);
  font-size: 12px;
}

.device-info__value {
  word-break: break-word;
  font-size: 14px;
}

.advanced-box {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(13,21,36,.75);
}

.desktop-info-tile {
  display: flex;
}

.provider-section {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(8px);
  transition: max-height .28s ease, opacity .24s ease, transform .24s ease, margin-top .24s ease, padding-top .24s ease;
  margin-top: 0;
  padding-top: 0;
}

.provider-section.is-active {
  max-height: 2400px;
  opacity: 1;
  transform: translateY(0);
  margin-top: 12px;
  padding-top: 4px;
}

.provider-tile__icon {
  width: 100px;
  height: 100px;
  object-fit: contain;
}

.topbar.topbar--index {
  display: block !important;
  width: 100%;
  margin-bottom: 24px;
}

.topbar.topbar--index .topbar-actions {
  display: flex;
  justify-content: flex-end !important;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 10px;
}

.topbar.topbar--index .topbar-title-row {
  display: flex;
  justify-content: center !important;
  align-items: center;
  width: 100%;
}

.topbar.topbar--index .page-title {
  margin: 0;
  width: 100%;
  text-align: center !important;
}

.topbar.topbar--brand {
  display: grid !important;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
  width: 100%;
  margin-bottom: 24px;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-side--left {
  justify-content: flex-start;
}

.topbar-side--right {
  justify-content: flex-end;
}

.topbar-brand-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: auto;
  max-width: 360px;
  max-height: 164px;
  object-fit: contain;
}

.topbar-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #0d1524;
  color: var(--muted);
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  transition: border-color .2s ease, background-color .2s ease, transform .15s ease;
}

.topbar-home-link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.topbar-home-link:visited,
.topbar-home-link:active,
.topbar-home-link:focus {
  color: var(--muted);
  text-decoration: none;
}

input:disabled,
select:disabled,
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.app-modal.hidden {
  display: none !important;
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.app-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
}

.app-modal__dialog {
  position: relative;
  z-index: 2;
  width: min(92vw, 420px);
  margin: 12vh auto 0;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.app-modal__title {
  margin: 0 0 12px;
}

.app-modal__message {
  color: var(--text);
  line-height: 1.45;
}

.app-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 1080px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  .provider-menu-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  .device-providers-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .brand-logo {
    max-width: 260px;
    max-height: 104px;
  }
  .topbar-side--left {
    display: none;
  }

  .topbar.topbar--brand {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  
  .desktop-info-tile {
    display: none !important;
  }
  
  .mobile-inline-panel.hidden {
    display: none !important;
  }

  .mobile-inline-panel {
    display: block;
  }

  #mobileProvidersListCard,
  #mobileDeviceInfoCard {
    margin-top: 0;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }

  .provider-menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .device-providers__head {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-center {
    order: 1;
  }

  .topbar-actions {
    order: 2;
    justify-content: center;
    flex-wrap: wrap;
  }

  .topbar-spacer {
    display: none;
  }
}

@media (max-width: 520px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  .site-shell {
    padding: 18px 12px 28px;
  }

  .page-title {
    font-size: 26px;
  }

  .provider-menu-grid {
    grid-template-columns: 1fr;
  }

  .session-input {
    width: 150px !important;
    font-size: 22px;
    letter-spacing: 3px;
  }

  .action-row,
  .backup-actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .topbar--centered {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
  }

  .topbar-spacer {
    min-width: 1px;
  }

  .topbar-center {
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: none;
  }

  .topbar-title-row {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 6px;
  }
  
  .page-title--center {
    text-align: center;
    width: 100%;
    margin: 0;
  }

  .topbar--index {
    display: block;
    margin-bottom: 24px;
  }
  
  .lang-label {
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
  }

  .lang-flag {
    font-size: 18px;
    line-height: 1;
  }
}

@media (max-width: 820px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  .provider-menu-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .provider-panel {
    display: block;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    min-height: auto;
  }

  .topbar-actions--right {
    justify-content: center;
  }

  .provider-section {
    display: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .24s ease, transform .24s ease;
    margin-top: 10px;
    background: linear-gradient(180deg, var(--panel), var(--panel-2));
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow);
  }

  .provider-section.is-active {
    display: block;
    opacity: 1;
    transform: translateY(0);
  }

  .provider-tile {
    min-height: 74px;
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
    padding: 14px 16px;
  }

  .provider-tile__icon {
    width: 70px;
    height: 70px;
    flex: 0 0 40px;
  }

  .provider-tile__label {
    text-align: left;
    font-size: 15px;
  }

  .provider-panel .provider-section + .provider-section {
    margin-top: 14px;
  }
}

.mobile-only {
  display: none !important;
}

@media (max-width: 820px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  .mobile-only {
    display: flex !important;
  }

  #devicePanels {
    display: block;
  }

  #deviceProvidersCard,
  #deviceInfoCard {
    display: none;
    margin-top: 14px;
  }

  #deviceProvidersCard.is-mobile-visible,
  #deviceInfoCard.is-mobile-visible {
    display: block;
  }
}

@media (min-width: 821px) {
  input:disabled,
  select:disabled,
  button:disabled {
    opacity: 0.5;
  }
    
  [data-provider-section="backup"] {
    padding-top: 0;
  }

  .provider-menu-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 10px;
  }
  
  .provider-tile {
    min-height: 88px;
    padding: 10px 8px;
    gap: 8px;
  }

  .provider-tile__icon {
    width: 100px;
    height: 100px;
    object-fit: contain;
  }

  .provider-tile__label {
    display: none;
  }
  
  [data-provider-section="backup"] .card-title {
    margin-bottom: 8px;
  }

  [data-provider-section="backup"] .provider-section-hint {
    margin-bottom: 10px;
  }

  [data-provider-section="backup"] .backup-actions {
    gap: 10px;
  }
}

.mobile-inline-panel {
  margin-top: 10px;
}
