:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #e5e7eb;
    --text: #111827;
    --text-soft: #6b7280;
    --text-muted: #9ca3af;

    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;

    --green: #16a34a;
    --green-soft: #f0fdf4;

    --red: #dc2626;
    --red-soft: #fef2f2;

    --purple: #7c3aed;
    --orange: #ea580c;

    --sidebar: #111827;

    --radius: 16px;
    --radius-small: 10px;

    --shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}


/* Reset */

* {
    box-sizing: border-box;
}

html {
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
}


/* App */

.app-shell {
    min-height: 100vh;
}


/* Topbar */

.topbar {
    height: 72px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 28px;

    position: sticky;
    top: 0;
    z-index: 100;
}

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

.brand-mark {
    width: 38px;
    height: 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 11px;

    background: var(--primary);
    color: white;

    font-size: 18px;
    font-weight: 800;
}

.brand-name {
    font-weight: 750;
    font-size: 16px;
}

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

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

.server-indicator {
    display: flex;
    align-items: center;
    gap: 8px;

    color: var(--text-soft);
    font-size: 13px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;

    display: inline-block;

    border-radius: 50%;
}

.status-online {
    background: var(--green);
    box-shadow: 0 0 0 4px var(--green-soft);
}

.status-offline {
    background: #9ca3af;
}

.logout-link {
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 600;
}

.logout-link:hover {
    color: var(--text);
}


/* Layout */

.app-layout {
    display: flex;
    min-height: calc(100vh - 72px);
}

.sidebar {
    width: 230px;

    background: var(--sidebar);
    color: white;

    padding: 24px 14px;

    display: flex;
    flex-direction: column;

    flex-shrink: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;

    padding: 12px 14px;

    margin-bottom: 5px;

    border-radius: 10px;

    color: #9ca3af;

    font-size: 14px;
    font-weight: 600;

    transition: 0.2s ease;
}

.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.07);
}

.nav-item.active {
    color: white;
    background: rgba(37, 99, 235, 0.85);
}

.nav-icon {
    width: 20px;
    text-align: center;
    font-size: 18px;
}

.sidebar-footer {
    margin-top: auto;

    padding: 18px 14px;

    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-label {
    font-size: 10px;
    letter-spacing: 0.12em;
    color: #6b7280;
    margin-bottom: 10px;
}

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 9px;

    color: #d1d5db;

    font-size: 13px;
}

.main-content {
    width: 100%;
    max-width: 1500px;

    padding: 36px 42px;
    margin: 0 auto;
}


/* Page header */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;

    gap: 24px;

    margin-bottom: 30px;
}

.eyebrow {
    color: var(--primary);

    font-size: 11px;
    font-weight: 800;

    letter-spacing: 0.12em;

    margin-bottom: 7px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 7px;

    font-size: 30px;
    line-height: 1.15;

    letter-spacing: -0.025em;
}

.page-description {
    margin-bottom: 0;

    color: var(--text-soft);

    font-size: 14px;
}


/* Buttons */

.primary-button,
.secondary-button,
.action-button,
.btn {
    border: 0;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;

    min-height: 40px;

    padding: 0 15px;

    border-radius: 10px;

    font-size: 13px;
    font-weight: 700;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        background 0.15s ease,
        box-shadow 0.15s ease;
}

.primary-button {
    background: var(--primary);
    color: white;

    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.primary-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.secondary-button {
    background: var(--surface);
    color: var(--text);

    border: 1px solid var(--border);
}

.secondary-button:hover {
    background: var(--surface-soft);
}


/* Stats */

.stats-grid {
    display: grid;

    grid-template-columns: repeat(4, 1fr);

    gap: 16px;

    margin-bottom: 38px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 15px;

    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    padding: 20px;

    box-shadow: var(--shadow);
}

.stat-icon {
    width: 44px;
    height: 44px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 12px;

    font-weight: 800;
    font-size: 18px;
}

.stat-icon-blue {
    color: var(--primary);
    background: var(--primary-soft);
}

.stat-icon-green {
    color: var(--green);
    background: var(--green-soft);
}

.stat-icon-purple {
    color: var(--purple);
    background: #f5f3ff;
}

.stat-icon-orange {
    color: var(--orange);
    background: #fff7ed;
}

.stat-label {
    color: var(--text-soft);

    font-size: 12px;
    font-weight: 600;

    margin-bottom: 3px;
}

.stat-value {
    font-size: 25px;
    line-height: 1.1;

    font-weight: 800;

    letter-spacing: -0.02em;
}

.stat-value-small {
    font-size: 18px;
}

.stat-description {
    color: var(--text-muted);

    font-size: 11px;

    margin-top: 3px;
}


/* Sections */

.section {
    margin-bottom: 42px;
}

.section-title-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    gap: 20px;

    margin-bottom: 18px;
}

.section-title-row h2 {
    margin-bottom: 4px;

    font-size: 19px;

    letter-spacing: -0.015em;
}

.section-description {
    margin: 0;

    color: var(--text-soft);

    font-size: 13px;
}


/* Resources */

.resource-grid {
    display: grid;

    grid-template-columns: repeat(3, 1fr);

    gap: 16px;
}

.resource-card {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    padding: 20px;
}

.resource-header {
    display: flex;
    justify-content: space-between;

    font-size: 13px;
    font-weight: 650;

    margin-bottom: 14px;
}

.resource-header span {
    color: var(--text-soft);
}

.progress-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    border-radius: inherit;
    transition: width 0.4s ease;
}

.resource-footer {
    color: var(--text-muted);

    font-size: 11px;

    margin-top: 10px;
}


/* Devices */

.device-grid {
    display: grid;

    grid-template-columns: repeat(2, minmax(0, 1fr));

    gap: 18px;
}

.device-card {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    padding: 20px;

    box-shadow: var(--shadow);

    overflow: hidden;
}

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

    gap: 16px;

    margin-bottom: 20px;
}

.device-identity {
    display: flex;
    align-items: center;
    gap: 12px;

    min-width: 0;
}

.device-icon {
    width: 46px;
    height: 46px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--surface-soft);

    border: 1px solid var(--border);

    border-radius: 13px;

    font-size: 21px;

    flex-shrink: 0;
}

.device-identity h3 {
    margin-bottom: 4px;

    font-size: 15px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-ip {
    color: var(--text-muted);

    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.device-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;

    flex-shrink: 0;

    font-size: 11px;
    font-weight: 750;
}

.device-online {
    color: var(--green);
}

.device-offline {
    color: var(--text-muted);
}

.device-details {
    display: grid;

    grid-template-columns: repeat(3, 1fr);

    gap: 1px;

    background: var(--border);

    border: 1px solid var(--border);

    border-radius: 10px;

    overflow: hidden;

    margin-bottom: 18px;
}

.device-detail {
    background: var(--surface-soft);

    padding: 11px;
}

.device-detail span {
    display: block;

    color: var(--text-muted);

    font-size: 10px;
    font-weight: 600;

    margin-bottom: 3px;
}

.device-detail strong {
    display: block;

    font-size: 11px;

    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;

    overflow: hidden;
    text-overflow: ellipsis;
}


/* QR */

.qr-container {
    display: none;

    padding: 20px;

    margin-bottom: 16px;

    background: #f8fafc;

    border: 1px solid var(--border);

    border-radius: 14px;

    text-align: center;
}

.qr-container.visible {
    display: block;
}

.qr-image {
    width: min(220px, 75vw);
    height: auto;

    display: block;

    margin: 0 auto 12px;

    background: white;

    border-radius: 10px;

    padding: 10px;

    border: 1px solid var(--border);
}

.qr-caption {
    color: var(--text-soft);

    font-size: 12px;
}

.qr-loading {
    color: var(--text-muted);

    font-size: 12px;

    padding: 30px;
}

.qr-image.loaded + .qr-caption {
    display: block;
}

.qr-show-label,
.qr-hide-label {
    pointer-events: none;
}

.qr-hide-label {
    display: none;
}

.qr-toggle.active .qr-show-label {
    display: none;
}

.qr-toggle.active .qr-hide-label {
    display: inline;
}


/* Device actions */

.device-actions {
    display: grid;

    grid-template-columns: 1.2fr 1fr 0.8fr 0.8fr;

    gap: 8px;
}

.action-button {
    min-width: 0;

    padding: 0 10px;

    background: var(--surface-soft);

    border: 1px solid var(--border);

    color: var(--text);

    white-space: nowrap;
}

.action-button:hover {
    background: #eef2f7;
}

.action-primary {
    background: var(--primary-soft);

    color: var(--primary);

    border-color: #dbeafe;
}

.action-primary:hover {
    background: #dbeafe;
}

.action-secondary {
    color: var(--text-soft);
}

.action-danger {
    color: var(--red);

    background: var(--red-soft);

    border-color: #fee2e2;
}

.action-danger:hover {
    background: #fee2e2;
}


/* Empty */

.empty-state {
    text-align: center;

    padding: 70px 20px;

    background: var(--surface);

    border: 1px dashed #d1d5db;

    border-radius: var(--radius);
}

.empty-icon {
    width: 54px;
    height: 54px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin: 0 auto 16px;

    border-radius: 15px;

    background: var(--primary-soft);

    color: var(--primary);

    font-size: 26px;
}

.empty-state h3 {
    margin-bottom: 7px;
}

.empty-state p {
    max-width: 420px;

    margin: 0 auto 22px;

    color: var(--text-soft);

    font-size: 13px;
}


/* Flash */

.flash-container {
    margin-bottom: 22px;
}

.flash {
    display: flex;
    align-items: center;
    gap: 9px;

    padding: 12px 15px;

    background: var(--green-soft);

    border: 1px solid #bbf7d0;

    color: #166534;

    border-radius: 10px;

    font-size: 13px;
}


/* Forms */

.form-page {
    max-width: 620px;

    margin: 20px auto;
}

.form-page-header {
    margin-bottom: 24px;
}

.back-link {
    display: inline-block;

    margin-bottom: 28px;

    color: var(--text-soft);

    font-size: 13px;
    font-weight: 600;
}

.back-link:hover {
    color: var(--text);
}

.form-page-header h1 {
    margin-bottom: 8px;
}

.form-page-header p {
    color: var(--text-soft);

    font-size: 14px;
}

.form-card {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    padding: 28px;

    box-shadow: var(--shadow);
}

.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;

    margin-bottom: 8px;

    font-size: 13px;
    font-weight: 700;
}

.form-group input {
    width: 100%;

    height: 48px;

    padding: 0 14px;

    background: var(--surface);

    border: 1px solid #d1d5db;

    border-radius: 10px;

    color: var(--text);

    outline: none;

    transition: border 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus {
    border-color: var(--primary);

    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.input-help {
    margin-top: 7px;

    color: var(--text-muted);

    font-size: 11px;
}

.example-devices {
    padding: 16px;

    background: var(--surface-soft);

    border: 1px solid var(--border);

    border-radius: 12px;

    margin-bottom: 24px;
}

.example-title {
    color: var(--text-soft);

    font-size: 11px;
    font-weight: 700;

    margin-bottom: 10px;
}

.example-chip {
    border: 1px solid var(--border);

    background: white;

    border-radius: 8px;

    padding: 8px 10px;

    margin: 0 5px 5px 0;

    cursor: pointer;

    font-size: 12px;
}

.example-chip:hover {
    border-color: #bfdbfe;

    background: var(--primary-soft);
}

.form-actions {
    display: flex;

    gap: 10px;

    padding-top: 6px;
}

.form-submit {
    flex: 1;
}


/* Mobile floating button */

.mobile-floating-button {
    display: none;
}


/* Mobile menu */

.mobile-menu-button {
    display: none;

    width: 42px;
    height: 42px;

    background: transparent;

    border: 1px solid var(--border);

    border-radius: 10px;

    cursor: pointer;

    padding: 9px;
}

.mobile-menu-button span {
    display: block;

    height: 2px;

    margin: 4px 0;

    background: var(--text);
}


/* Responsive */

@media (max-width: 1100px) {

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .device-grid {
        grid-template-columns: 1fr;
    }

}


@media (max-width: 800px) {

    .topbar {
        height: 64px;

        padding: 0 16px;
    }

    .topbar-actions {
        display: none;
    }

    .mobile-menu-button {
        display: block;
    }

    .app-layout {
        min-height: calc(100vh - 64px);
    }

    .sidebar {
        position: fixed;

        top: 64px;
        left: 0;
        bottom: 0;

        width: 250px;

        z-index: 90;

        transform: translateX(-100%);

        transition: transform 0.2s ease;

        box-shadow: 15px 0 40px rgba(0,0,0,0.12);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        padding: 24px 18px 80px;
    }

    .page-header {
        align-items: flex-start;

        flex-direction: column;

        margin-bottom: 24px;
    }

    .page-header .primary-button {
        width: 100%;
    }

    h1 {
        font-size: 27px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);

        gap: 10px;

        margin-bottom: 30px;
    }

    .stat-card {
        padding: 15px;

        gap: 10px;
    }

    .stat-icon {
        width: 38px;
        height: 38px;

        font-size: 15px;
    }

    .stat-value {
        font-size: 21px;
    }

    .resource-grid {
        grid-template-columns: 1fr;
    }

    .desktop-add-button {
        display: none;
    }

    .section-title-row {
        align-items: flex-start;
    }

    .device-grid {
        gap: 12px;
    }

    .device-card {
        padding: 16px;
    }

    .device-actions {
        grid-template-columns: 1fr 1fr;
    }

    .action-button {
        min-height: 43px;
    }

    .mobile-floating-button {
        display: flex;

        position: fixed;

        right: 18px;
        bottom: 18px;

        width: 54px;
        height: 54px;

        align-items: center;
        justify-content: center;

        border-radius: 50%;

        background: var(--primary);
        color: white;

        font-size: 26px;

        box-shadow: 0 8px 25px rgba(37, 99, 235, 0.35);

        z-index: 80;
    }

    .form-page {
        margin: 0 auto;
    }

    .form-card {
        padding: 20px;
    }

}


@media (max-width: 480px) {

    .brand-subtitle {
        display: none;
    }

    .stats-grid {
        gap: 8px;
    }

    .stat-card {
        padding: 13px;

        min-width: 0;
    }

    .stat-icon {
        display: none;
    }

    .stat-label {
        font-size: 11px;
    }

    .stat-value {
        font-size: 20px;
    }

    .device-card-header {
        gap: 8px;
    }

    .device-status {
        font-size: 10px;
    }

    .device-details {
        grid-template-columns: repeat(2, 1fr);
    }

    .device-detail:last-child {
        grid-column: span 2;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions > * {
        width: 100%;
    }

}

/* =========================================================
   LOGIN PAGE
   ========================================================= */

.login-page {
    min-height: 100vh;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(
            circle at 15% 20%,
            rgba(59, 130, 246, 0.12),
            transparent 35%
        ),
        radial-gradient(
            circle at 85% 80%,
            rgba(16, 185, 129, 0.10),
            transparent 35%
        ),
        #0b0f14;
    color: #f8fafc;
}

.login-shell {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
}

.login-card {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 430px;
    padding: 34px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    background: rgba(17, 24, 39, 0.88);
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(20px);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 42px;
}

.login-logo {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #14b8a6);
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.25);
}

.login-logo span {
    font-size: 21px;
    font-weight: 800;
    color: white;
}

.login-brand h1 {
    margin: 0;
    font-size: 17px;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.login-brand p {
    margin: 4px 0 0;
    color: #94a3b8;
    font-size: 13px;
}

.login-heading {
    margin-bottom: 28px;
}

.login-heading h2 {
    margin: 0;
    font-size: 30px;
    line-height: 1.15;
    letter-spacing: -0.04em;
}

.login-heading p {
    margin: 9px 0 0;
    color: #94a3b8;
    font-size: 14px;
    line-height: 1.6;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

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

.form-field label {
    color: #cbd5e1;
    font-size: 13px;
    font-weight: 600;
}

.password-wrapper {
    position: relative;
}

.password-wrapper input {
    width: 100%;
    box-sizing: border-box;
    height: 52px;
    padding: 0 72px 0 15px;
    border: 1px solid #334155;
    border-radius: 12px;
    outline: none;
    background: #0f172a;
    color: #f8fafc;
    font-size: 15px;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}

.password-wrapper input::placeholder {
    color: #64748b;
}

.password-wrapper input:focus {
    border-color: #3b82f6;
    background: #111c31;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: #60a5fa;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.password-toggle:hover {
    color: #93c5fd;
}

.login-button {
    width: 100%;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 17px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: white;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.25);
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.login-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 34px rgba(37, 99, 235, 0.35);
}

.login-button:active {
    transform: translateY(0);
}

.login-arrow {
    font-size: 20px;
    line-height: 1;
}

.login-alert {
    margin-bottom: 22px;
    padding: 12px 14px;
    border: 1px solid rgba(248, 113, 113, 0.25);
    border-radius: 10px;
    background: rgba(127, 29, 29, 0.22);
    color: #fca5a5;
    font-size: 13px;
}

.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-top: 28px;
    color: #64748b;
    font-size: 12px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.65);
}

.login-background-decoration {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
}

.decoration-one {
    width: 280px;
    height: 280px;
    top: -100px;
    left: -80px;
    background: rgba(37, 99, 235, 0.12);
}

.decoration-two {
    width: 320px;
    height: 320px;
    right: -120px;
    bottom: -120px;
    background: rgba(20, 184, 166, 0.10);
}

@media (max-width: 520px) {
    .login-shell {
        padding: 16px;
    }

    .login-card {
        padding: 26px 22px;
        border-radius: 20px;
    }

    .login-brand {
        margin-bottom: 34px;
    }

    .login-heading h2 {
        font-size: 27px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .login-button,
    .password-wrapper input {
        transition: none;
    }
}