/* ==========================================================================
   Miner dashboard — redesigned stylesheet
   Все имена классов сохранены, HTML менять не нужно.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ---------- Tokens ---------- */
:root {
    /* Surfaces: глубокий сине-графитовый */
    --bg: #0a0d14;
    --bg-sunken: #070a10;
    --surface: #111622;
    --surface-2: #171d2c;
    --surface-3: #1f2638;

    /* Lines */
    --line: #232b3d;
    --line-strong: #323c55;

    /* Text */
    --text: #e6ebf5;
    --text-2: #9aa6bf;
    --text-3: #62708c;

    /* Accent: синий */
    --accent: #2f6bff;
    --accent-hover: #4d83ff;
    --accent-ink: #8db1ff;
    --accent-wash: rgba(47, 107, 255, 0.15);
    --accent-ring: rgba(77, 131, 255, 0.4);

    /* Semantic */
    --ok: #3fb97a;
    --ok-wash: rgba(63, 185, 122, 0.13);
    --warn: #e0a83a;
    --warn-wash: rgba(224, 168, 58, 0.13);
    --bad: #e5584f;
    --bad-wash: rgba(229, 88, 79, 0.13);

    /* Shape */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;

    /* Type */
    --font-ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

    --sidebar-w: 240px;
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

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

html {
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

body {
    min-width: 320px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

code,
textarea,
.hashrate,
.hashrate-total,
.stat-value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

a {
    color: var(--accent-ink);
}

:focus-visible {
    outline: 2px solid var(--accent-hover);
    outline-offset: 2px;
}

::selection {
    background: var(--accent-ring);
}

/* ---------- Layout ---------- */
.container {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

.app-shell {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.main-content {
    flex: 1;
    width: 100%;
    max-width: 1480px;
    margin: 0 auto;
    padding: clamp(1.25rem, 3vw, 2.75rem);
    /* Единственная анимация загрузки — плавное появление контента */
    animation: page-in 320ms var(--ease) both;
}

@keyframes page-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.footer {
    padding: 1.25rem 2rem;
    color: var(--text-3);
    font-size: 0.8rem;
    text-align: center;
}

/* ---------- Sidebar ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex: 0 0 var(--sidebar-w);
    flex-direction: column;
    gap: 1.5rem;
    width: var(--sidebar-w);
    height: 100vh;
    padding: 1.25rem 0.75rem;
    overflow: hidden auto;
    background: var(--bg-sunken);
    border-right: 1px solid var(--line);
}

.navbar-header {
    padding: 0.25rem 0.5rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0;
    color: var(--text);
    text-decoration: none;
}

.navbar-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    object-fit: cover;
    box-shadow: 0 0 0 1px var(--line-strong);
}

.navbar-brand span {
    display: grid;
    line-height: 1.15;
}

.navbar-brand strong {
    font-size: 1.02rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.navbar-brand small {
    margin-top: 0.2rem;
    color: var(--text-3);
    font-size: 0.74rem;
    font-weight: 500;
}

.navbar-menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    list-style: none;
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 40px;
    padding: 0.55rem 0.75rem;
    color: var(--text-2);
    font-size: 0.92rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--r-sm);
    transition: color 140ms ease, background-color 140ms ease;
}

.nav-link svg,
.logout-btn svg {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    opacity: 0.85;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-2);
}

.nav-link.active {
    color: #fff;
    background: var(--accent-wash);
}

.nav-link.active svg {
    color: var(--accent-ink);
    opacity: 1;
}

.nav-link.active::before {
    position: absolute;
    top: 50%;
    left: -0.75rem;
    width: 3px;
    height: 20px;
    content: '';
    background: var(--accent-hover);
    border-radius: 0 3px 3px 0;
    transform: translateY(-50%);
}

.sidebar-spacer {
    flex: 1;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 40px;
    padding: 0.55rem 0.75rem;
    color: var(--text-2);
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    transition: color 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.logout-btn:hover {
    color: #fff;
    background: var(--accent-wash);
    border-color: var(--accent);
}

.nav-toggle {
    display: none;
}

/* ---------- Page headings ---------- */
.dashboard h2,
.miners-page h2,
.config-page h2,
.updates-page h2,
.donations-container h2 {
    color: var(--text) !important;
    font-family: var(--font-ui);
    font-size: clamp(1.4rem, 2.4vw, 1.9rem) !important;
    font-weight: 650;
    letter-spacing: -0.02em !important;
    line-height: 1.2;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 1.5rem !important;
}

.page-title svg {
    width: 22px;
    height: 22px;
    color: var(--accent-hover);
}

/* ---------- Cards ---------- */
.stat-card,
.config-section,
.empty-message,
.pagination-controls,
.form-modal-content {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
}

.config-section {
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.empty-message {
    padding: 2.5rem 1.5rem;
    color: var(--text-2);
    text-align: center;
    border-style: dashed;
    border-color: var(--line-strong);
}

.empty-message a {
    color: var(--accent-ink);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ---------- Dashboard stats ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.9rem;
    margin-bottom: 2rem;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.9rem;
    width: 100%;
    margin-bottom: 2rem;
}

.stat-card {
    position: relative;
    min-width: 0;
    padding: 1.25rem 1.35rem;
    transition: border-color 160ms ease;
}

.stat-card:hover {
    border-color: var(--line-strong);
}

.dashboard-stats .stat-card {
    min-height: 132px;
    font-family: var(--font-ui) !important;
}

.stat-card h3,
.dashboard-stats .stat-card h3 {
    margin-top: 0.6rem !important;
    color: var(--text-3) !important;
    font-family: var(--font-ui) !important;
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0 !important;
    text-transform: none;
}

.stat-value,
.dashboard-stats .stat-card p {
    margin-top: 0.15rem;
    color: var(--text) !important;
    font-family: var(--font-mono);
    font-size: clamp(1.6rem, 2.6vw, 2.2rem);
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.dashboard-stats .stat-card:first-child p { color: var(--ok) !important; }
.dashboard-stats .stat-card:nth-child(2) p { color: var(--bad) !important; }

.stat-icon {
    width: 20px;
    height: 20px;
    color: var(--text-3);
}

.stat-icon-online  { color: var(--ok); }
.stat-icon-offline { color: var(--bad); }

/* ---------- Controls above tables ---------- */
.miners-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.search-field {
    position: relative;
    flex: 1;
    width: 100%;
}

.search-field > svg {
    position: absolute;
    top: 50%;
    left: 0.85rem;
    z-index: 1;
    width: 17px;
    height: 17px;
    color: var(--text-3);
    pointer-events: none;
    transform: translateY(-50%);
}

.search-field .search-input {
    width: 100%;
    padding-left: 2.5rem !important;
}

/* ---------- Tables ---------- */
.miners-list,
.miners-preview,
.config-section {
    overflow: hidden;
}

.miners-preview {
    margin-top: 2rem;
}

.miners-preview h3 {
    margin-bottom: 0.9rem;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 600;
}

.miners-table {
    width: 100%;
    margin-top: 0;
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
}

.miners-table thead {
    background: var(--surface-2);
}

.miners-table th {
    padding: 0.85rem 1rem;
    color: var(--text-3) !important;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--line);
}

.miners-table td {
    padding: 0.9rem 1rem;
    color: var(--text-2);
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.miners-table tbody tr:last-child td {
    border-bottom: 0;
}

.miners-table tbody tr {
    transition: background-color 120ms ease;
}

.miners-table tbody tr:hover {
    background: var(--surface-2);
}

.hashrate,
.hashrate-total {
    color: var(--text);
    font-size: 0.9rem;
}

/* ---------- Status pills ---------- */
.status {
    position: relative;
    display: inline-block;
    padding: 0.25rem 0.65rem 0.25rem 1.3rem !important;
    font-size: 0.78rem !important;
    font-weight: 600;
    text-transform: capitalize;
    white-space: nowrap;
    border: 0 !important;
    border-radius: 999px;
}

.status::before {
    position: absolute;
    top: 50%;
    left: 0.58rem;
    width: 6px;
    height: 6px;
    content: '';
    border-radius: 50%;
    transform: translateY(-50%);
}

.status.online,
.status.active {
    color: var(--ok);
    background: var(--ok-wash);
}
.status.online::before,
.status.active::before {
    background: var(--ok);
    box-shadow: 0 0 0 3px rgba(63, 185, 122, 0.2);
}

.status.offline,
.status.error {
    color: var(--bad);
    background: var(--bad-wash);
}
.status.offline::before,
.status.error::before {
    background: var(--bad);
}

.status.paused {
    color: var(--warn);
    background: var(--warn-wash);
}
.status.paused::before {
    background: var(--warn);
}

.status.disabled,
.status.unknown {
    color: var(--text-3);
    background: rgba(98, 112, 140, 0.16);
}
.status.disabled::before,
.status.unknown::before {
    background: var(--text-3);
}

/* ---------- Buttons ---------- */
.btn,
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0.55rem 1rem;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.btn:active,
.copy-btn:active {
    transform: translateY(1px);
}

.btn svg,
.copy-btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary,
.btn-success {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover,
.btn-success:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary,
.copy-btn {
    color: var(--text);
    background: var(--surface-2);
    border-color: var(--line-strong);
}

.btn-secondary:hover,
.copy-btn:hover {
    background: var(--surface-3);
    border-color: #44506e;
}

.btn-danger {
    color: var(--bad);
    background: var(--bad-wash);
    border-color: rgba(229, 88, 79, 0.35);
}

.btn-danger:hover {
    color: #fff;
    background: var(--bad);
    border-color: var(--bad);
}

.btn-sm {
    min-height: 32px;
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    color: var(--text-2);
    cursor: pointer;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    transition: color 140ms ease, background-color 140ms ease;
}

.icon-btn:hover {
    color: var(--text);
    background: var(--surface-2);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* ---------- Forms ---------- */
.config-form,
#minerForm {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 620px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
}

.form-group small {
    color: var(--text-3);
    font-size: 0.82rem;
}

.form-group.checkbox {
    flex-direction: row;
    align-items: center;
}

.form-group.checkbox label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.form-group.checkbox input {
    width: auto;
    margin: 0;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

input:not([type='checkbox']):not([type='radio']),
select,
textarea,
.search-input,
.address-input {
    min-height: 42px;
    padding: 0.6rem 0.8rem !important;
    color: var(--text) !important;
    background: var(--bg-sunken) !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: var(--r-sm) !important;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-3);
}

input:not([type='checkbox']):not([type='radio']):hover,
select:hover,
textarea:hover {
    border-color: #44506e !important;
}

input:not([type='checkbox']):not([type='radio']):focus,
select:focus,
textarea:focus,
.search-input:focus {
    border-color: var(--accent-hover) !important;
    box-shadow: 0 0 0 3px var(--accent-wash) !important;
    outline: none;
}

input[type='checkbox'],
input[type='radio'] {
    accent-color: var(--accent);
}

/* ---------- Modal ---------- */
.form-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(3, 5, 10, 0.74);
    backdrop-filter: blur(4px);
}

.form-modal.hidden {
    display: none;
}

.form-modal-content {
    position: relative;
    width: 100%;
    max-width: 520px;
    padding: 1.75rem;
    background: var(--surface);
    border-color: var(--line-strong);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
    /* Анимация — ответ на действие пользователя (открытие окна) */
    animation: modal-in 200ms var(--ease) both;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.close-btn {
    position: absolute;
    top: 0.9rem;
    right: 0.9rem;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    color: var(--text-3);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--r-sm);
    transition: color 140ms ease, background-color 140ms ease;
}

.close-btn:hover {
    color: var(--text);
    background: var(--surface-2);
}

/* ---------- Pagination ---------- */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.8rem;
}

.page-info {
    min-width: 140px;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: center;
}

.pagination-controls .btn {
    min-width: 110px;
}

/* ---------- Updates page ---------- */
.update-current,
.update-available {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-3);
    font-size: 0.82rem;
    font-weight: 600;
}

.update-current {
    color: var(--ok);
}

.update-current svg {
    width: 15px;
    height: 15px;
}

.update-available {
    color: var(--warn);
}

#versionTableBody td:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .container {
        flex-direction: column;
    }

    .navbar {
        flex: 0 0 auto;
        width: 100%;
        height: auto;
        gap: 0;
        padding: 0.75rem 1rem;
        overflow: visible;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .navbar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0;
        border: 0;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .navbar-menu,
    .navbar .sidebar-spacer,
    .navbar .logout-btn {
        display: none;
    }

    .navbar.nav-open .navbar-menu {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.35rem;
        padding: 0.9rem 0 0;
    }

    .navbar.nav-open .logout-btn {
        display: flex;
        margin-top: 0.5rem;
    }

    .nav-link.active::before {
        display: none;
    }

    .miners-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 1rem;
    }

    .navbar.nav-open .navbar-menu,
    .dashboard-stats,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .miners-controls,
    .pagination-controls,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .form-actions .btn,
    .pagination-controls .btn {
        width: 100%;
    }

    .miners-table th,
    .miners-table td {
        padding: 0.7rem 0.8rem;
        font-size: 0.85rem;
    }

    .footer {
        padding-inline: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
