/* RESCON mobile application layer. Loaded last on purpose. */
.skadi-options[hidden] {
  display: none !important;
}

.controller-diagnostic {
  margin-top: 10px;
  color: #aab1bc;
  font-size: 10px;
}

.controller-diagnostic pre {
  max-height: 190px;
  margin: 8px 0 0;
  padding: 9px;
  overflow: auto;
  border-radius: 7px;
  background: #090b0f;
  color: #c3cad4;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  html {
    height: auto !important;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto !important;
    scroll-padding-top: 112px;
    overscroll-behavior-y: auto;
    -webkit-text-size-adjust: 100%;
  }

  body,
  body.app-body,
  .app-shell,
  .workspace,
  .view,
  .panel,
  .worker {
    max-width: 100%;
  }

  body {
    position: relative !important;
    height: auto !important;
    min-height: 100dvh;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  body.app-body,
  .app-shell,
  .workspace,
  .view.active,
  .worker-list {
    height: auto !important;
    overflow-y: visible !important;
  }

  button,
  .link-button,
  input,
  select,
  textarea,
  summary,
  .nav-item {
    touch-action: manipulation;
  }

  button,
  .link-button {
    min-height: 42px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    padding: 11px 12px;
    font-size: 16px;
  }

  textarea {
    line-height: 1.45;
  }

  /* Sticky mobile application header and readable navigation. */
  .app-shell {
    display: block;
    width: 100%;
    min-height: 100dvh;
    margin: 0;
    border: 0;
    box-shadow: none;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
    height: auto;
    padding: max(7px, env(safe-area-inset-top)) 0 7px;
    border: 0;
    border-bottom: 1px solid #24272e;
    background: #08090bfa;
    box-shadow: 0 8px 24px #0007;
    backdrop-filter: blur(14px);
  }

  .brand {
    height: 39px;
    margin: 0;
    padding: 0 12px 7px;
    border: 0;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  .brand strong {
    font-size: 13px;
    letter-spacing: .04em;
  }

  .brand small {
    display: block;
    color: #8f97a3;
    font-size: 7px;
    letter-spacing: .08em;
  }

  .main-nav {
    display: flex;
    flex-direction: row;
    gap: 6px;
    width: 100%;
    padding: 0 10px 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }

  .main-nav::-webkit-scrollbar,
  .bulk-toolbar::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    display: inline-flex;
    flex: 0 0 auto;
    justify-content: flex-start;
    gap: 7px;
    min-width: max-content;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #252830;
    border-radius: 8px;
    background: #121419;
    color: #b5bbc5;
    font-size: 10px;
    line-height: 1;
    scroll-snap-align: center;
  }

  .nav-item span {
    font-size: 14px;
  }

  .nav-item b {
    display: inline-grid;
    min-width: 18px;
    padding: 2px 5px;
    font-size: 8px;
  }

  .nav-item.active {
    border-color: #657b9d;
    background: #465d82;
  }

  .sidebar-foot {
    display: none;
  }

  /* Compact account/search row. Logout must remain reachable on mobile. */
  .workspace {
    width: 100%;
    padding: 0 10px calc(30px + env(safe-area-inset-bottom));
  }

  .workspace-head {
    position: relative;
    height: 58px;
    margin: 0 -10px;
    padding: 9px 10px;
    gap: 8px;
    background: #0b0c0f;
  }

  .global-search {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: 40px;
  }

  .global-search input {
    min-height: 38px;
    height: 38px;
    padding-left: 8px;
    font-size: 16px;
  }

  .head-actions {
    flex: 0 0 auto;
    gap: 5px;
  }

  .head-actions #updated {
    display: none;
  }

  .icon-button {
    width: 42px;
    height: 42px;
    min-height: 42px;
  }

  .user-pill {
    display: flex;
    min-height: 42px;
    height: 42px;
    padding: 4px 8px;
  }

  .user-pill > i,
  .user-pill b,
  .user-pill small {
    display: none;
  }

  .user-pill > span {
    display: block;
  }

  .user-logout {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    margin: 0;
    padding: 0 4px;
    font-size: 10px;
  }

  .page-heading {
    min-height: 0;
    padding: 16px 1px 14px;
  }

  .page-heading h1 {
    margin: 2px 0 3px;
    font-size: 20px;
  }

  .page-heading p {
    max-width: 96%;
    font-size: 10px;
    line-height: 1.4;
  }

  /* Farm summary and bulk actions. */
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 15px;
  }

  .metric {
    min-width: 0;
    min-height: 82px;
    padding: 11px;
  }

  .metric:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .metric-icon {
    width: 27px;
    height: 27px;
  }

  .metric-icon + div {
    padding-top: 7px;
  }

  .metric small {
    overflow-wrap: anywhere;
    font-size: 8px;
  }

  .metric strong {
    font-size: 20px;
  }

  .bulk-toolbar {
    position: static;
    display: flex;
    align-items: center;
    gap: 6px;
    width: calc(100% + 2px);
    margin: 0 -1px 15px;
    padding: 8px;
    overflow-x: auto;
    border-radius: 9px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }

  .bulk-toolbar > * {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .bulk-toolbar button,
  .bulk-select-all {
    min-height: 42px;
  }

  .bulk-select-all {
    align-items: center;
    padding: 0 8px;
  }

  .bulk-select-all input,
  .rig-select input {
    width: 22px;
    height: 22px;
  }

  .bulk-toolbar strong {
    min-width: max-content;
    padding: 0 5px;
    font-size: 10px;
  }

  .section-toolbar,
  .section-toolbar.compact {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 9px;
  }

  .section-toolbar > div:last-child:not(:first-child),
  .section-toolbar > button {
    max-width: 100%;
  }

  .section-toolbar button {
    min-height: 42px;
  }

  /* Rig header and commands are real touch layouts, not desktop scrollers. */
  .worker-list {
    gap: 12px;
  }

  .worker {
    border-radius: 10px;
  }

  .worker-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 13px;
  }

  .worker-name {
    padding-bottom: 11px;
  }

  .worker-name h3 {
    font-size: 15px;
  }

  .worker-cell {
    min-width: 0;
    padding: 10px 0;
    border-top: 1px solid #2b2d34;
  }

  .worker-cell b,
  .worker-cell small,
  .miner-ping-line {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .miner-ping-line {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .pool-ping {
    min-height: 34px;
    padding: 7px 9px;
  }

  .mode-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-self: stretch;
    width: 100%;
    margin-top: 4px;
  }

  .mode-control button {
    min-height: 42px;
    padding: 8px 6px;
    font-size: 9px;
  }

  .worker-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 10px;
    overflow: visible;
  }

  .worker-actions .action-spacer {
    display: none;
  }

  .worker-actions button {
    min-width: 0;
    min-height: 42px;
    padding: 7px 5px;
    overflow-wrap: anywhere;
    white-space: normal;
    line-height: 1.2;
  }

  /* Each GPU becomes a readable card. No 680px table or hidden data. */
  .gpu-area {
    display: grid;
    gap: 8px;
    padding: 9px;
    overflow: visible;
    background: #111216;
  }

  .gpu-head {
    display: none;
  }

  .gpu-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    min-width: 0;
    padding: 11px;
    border: 1px solid #2c2f37 !important;
    border-radius: 8px;
    background: #0d0e12;
  }

  .gpu-row > span {
    display: block !important;
    min-width: 0;
    padding: 7px;
    border-radius: 6px;
    background: #17191e;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
  }

  .gpu-row > span::before {
    display: block;
    margin-bottom: 3px;
    color: #858d99;
    font-size: 7px;
    font-weight: 700;
    letter-spacing: .08em;
  }

  .gpu-row > .gpu-id {
    display: flex !important;
    grid-column: 1 / -1;
    align-items: center;
    min-height: 43px;
    background: #1b1e24;
  }

  .gpu-row > .gpu-id::before,
  .gpu-row > .gpu-controls::before {
    display: none;
  }

  .gpu-row > span:nth-child(2)::before { content: "ТЕМПЕРАТУРА"; }
  .gpu-row > span:nth-child(3)::before { content: "ВЕНТИЛЯТОР"; }
  .gpu-row > span:nth-child(4)::before { content: "ПИТАНИЕ"; }
  .gpu-row > span:nth-child(5)::before { content: "CORE"; }
  .gpu-row > span:nth-child(6)::before { content: "MEMORY"; }
  .gpu-row > span:nth-child(7)::before { content: "VRAM"; }
  .gpu-row > span:nth-child(8)::before { content: "НАГРУЗКА"; }

  .gpu-id b {
    white-space: normal;
  }

  .gpu-index {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
  }

  .gpu-controls {
    display: grid !important;
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    padding: 0 !important;
    background: transparent !important;
  }

  .gpu-controls button {
    min-height: 40px;
  }

  .bar {
    width: 100%;
  }

  /* Catalogs, drivers, sheets, VLESS and updates. */
  .page-grid.miners-layout,
  .flight-catalog,
  .driver-rig-grid,
  .driver-catalog,
  .release-grid,
  .settings-layout,
  .telegram-compact-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel,
  .repo-editor,
  .miner-card,
  .flight-card,
  .release-card,
  .settings-card,
  .telegram-connect-card,
  .telegram-control-card {
    padding: 14px;
  }

  .panel-head,
  .miner-card-head,
  .flight-card-head {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .panel-head > a {
    min-height: 36px;
    padding: 8px 0;
  }

  .miner-meta,
  .settings-checks {
    grid-template-columns: minmax(0, 1fr);
  }

  .miner-actions,
  .form-actions,
  .vless-card-actions,
  .telegram-inline-actions,
  .telegram-connect-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .miner-actions > *,
  .form-actions > *,
  .vless-card-actions > *,
  .telegram-inline-actions > *,
  .telegram-connect-actions > * {
    width: 100%;
  }

  .flight-route {
    flex-wrap: wrap;
    overflow-wrap: anywhere;
  }

  .flight-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .flight-actions select {
    grid-column: 1 / -1;
    min-height: 44px;
    font-size: 16px;
  }

  .flight-actions button {
    min-width: 0;
  }

  .driver-rig-card {
    min-height: 116px;
  }

  .driver-panel {
    padding: 14px;
  }

  .driver-row {
    grid-template-columns: 31px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 9px;
  }

  .driver-row button {
    min-height: 40px;
  }

  .vless-bulk-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .vless-bulk-actions button {
    width: 100%;
  }

  .vless-card {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .vless-card > div:nth-child(2) {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .vless-card-actions {
    grid-column: 1 / -1;
  }

  .version-pair {
    gap: 7px;
    margin: 15px 0;
  }

  .version-pair div {
    min-width: 0;
    padding: 10px;
  }

  .version-pair strong {
    overflow-wrap: anywhere;
    font-size: 18px;
  }

  .version-pair > span {
    padding-bottom: 13px;
  }

  .agent-release-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px;
    padding: 12px;
  }

  .agent-release-row .version-inline {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .agent-release-row .status-badge {
    grid-column: 2;
    grid-row: 1;
  }

  .agent-release-row button {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
  }

  /* Activity becomes cards and retains error output on phones. */
  .activity-list {
    display: grid;
    gap: 8px;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .activity-row,
  .activity-row.batch-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px 10px;
    padding: 12px;
    border: 1px solid #2b2e35;
    border-radius: 8px;
    background: #15171c;
  }

  .activity-row > * {
    display: block !important;
    min-width: 0;
  }

  .activity-row > b {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
  }

  .activity-row > .status-badge {
    grid-column: 2;
    grid-row: 1;
  }

  .activity-row > span:nth-child(3) {
    grid-column: 1 / -1;
    color: #aab1bc;
    font-size: 10px;
    overflow-wrap: anywhere;
  }

  .activity-row > .command-output {
    grid-column: 1 / -1;
    padding: 8px;
    border-radius: 6px;
    background: #0e1014;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .activity-row > small {
    grid-column: 1 / -1;
  }

  /* Forms and owner settings. */
  .form-grid.two,
  .form-grid.five,
  .telegram-switch-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .span-two,
  .form-grid .span-two {
    grid-column: auto;
  }

  label {
    font-size: 12px;
    line-height: 1.35;
  }

  .check-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .check-list label,
  .check {
    min-height: 44px;
    align-items: center;
  }

  .check-list input,
  .check input,
  .telegram-notify-grid input,
  .telegram-switch-grid input {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  .owner-setting-row {
    align-items: flex-start;
    gap: 12px;
  }

  .switch {
    flex-basis: 48px;
    width: 48px;
    height: 28px;
  }

  .switch span::after {
    width: 20px;
    height: 20px;
  }

  .switch input:checked + span::after {
    transform: translateX(20px);
  }

  .telegram-token-field .token-tools,
  .telegram-time-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .telegram-token-field .token-tools > *,
  .telegram-time-row > * {
    grid-column: 1;
  }

  .telegram-notify-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Mobile dialogs: viewport-safe, scrollable, with persistent actions. */
  .modal,
  .small-modal,
  .editor-modal,
  .console-modal,
  .flight-modal,
  #terminal-dialog {
    width: calc(100vw - 10px) !important;
    max-width: none !important;
    max-height: calc(100dvh - 10px) !important;
    margin: auto 5px 5px !important;
    overflow: auto;
    border-radius: 13px 13px 8px 8px;
  }

  .modal > header,
  .modal form > header {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 13px 14px;
    background: #17171bf5;
    backdrop-filter: blur(12px);
  }

  .modal header h2 {
    font-size: 16px;
  }

  .modal header button {
    width: 44px;
    min-height: 44px;
    margin: -8px -8px 0 0;
  }

  .modal form > div:not(.form-grid),
  .small-modal .form-grid,
  .flight-modal .form-grid,
  .flight-modal h3 {
    margin-inline: 14px;
  }

  .notice,
  .json-import {
    margin-inline: 14px;
  }

  .modal form > footer,
  .modal > footer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 15px;
    padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
    border-top: 1px solid #2e3138;
    background: #17171bf5;
    backdrop-filter: blur(12px);
  }

  .modal form > footer button,
  .modal > footer button {
    width: 100%;
    min-height: 44px;
  }

  .editor-modal > textarea,
  #rig-conf-content {
    width: calc(100% - 28px);
    height: 52dvh;
    margin: 12px 14px;
    font-size: 14px;
  }

  .console-modal,
  #terminal-dialog {
    height: calc(100dvh - 10px) !important;
  }

  .console-modal pre {
    height: calc(100% - 70px);
    padding: 12px;
    font-size: 11px;
  }

  #terminal-container {
    height: calc(100% - 70px);
    padding: 4px;
  }

  .driver-confirm-body {
    padding: 13px 14px;
  }

  .coolbox-status-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

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

  /* iOS does not reliably scroll a long form when dialog itself is the scroller. */
  .coolbox-modal {
    height: calc(100dvh - 10px) !important;
    overflow: hidden !important;
  }

  .coolbox-modal #coolbox-form {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
  }

  .coolbox-modal .modal-scroll-body {
    min-height: 0;
    margin: 0 !important;
    padding: 0 0 16px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  .coolbox-modal .modal-scroll-body > .form-grid {
    margin-inline: 14px;
  }

  .coolbox-modal .modal-scroll-body > .check {
    margin-inline: 14px;
  }

  .coolbox-modal .modal-scroll-body > .form-actions {
    margin-inline: 14px;
    grid-template-columns: minmax(0, 1fr);
  }

  .skadi-options[hidden] {
    display: none !important;
  }

  .coolbox-modal form > footer {
    position: relative;
    margin: 0;
  }

  /* Login remains comfortable on 320px devices. */
  .login-shell {
    min-height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    padding: 22px 17px;
    border-radius: 15px;
  }

  .login-card h1 {
    margin-top: 13px;
  }

  .login-card button,
  .telegram-channel-link {
    min-height: 48px;
  }

  #toast-stack {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
  }

  .toast {
    width: 100%;
  }
}

@media (max-width: 390px) {
  .workspace {
    padding-inline: 8px;
  }

  .workspace-head {
    margin-inline: -8px;
    padding-inline: 8px;
  }

  .global-search input::placeholder {
    color: transparent;
  }

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

  .telegram-notify-grid,
  .miner-actions,
  .form-actions,
  .vless-card-actions,
  .telegram-inline-actions,
  .telegram-connect-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .version-pair {
    grid-template-columns: minmax(0, 1fr);
  }

  .version-pair > span {
    display: none;
  }

  .driver-row {
    grid-template-columns: 31px minmax(0, 1fr);
  }

  .driver-row button {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (hover: none) and (pointer: coarse) {
  button:hover,
  .nav-item:hover,
  .telegram-channel-link:hover {
    filter: none;
  }

  button:active,
  .nav-item:active,
  .link-button:active {
    transform: scale(.98);
  }
}
